[FFmpeg-devel] [PATCH 1/2] avformat/movenc: don't negate roll_distance when writing it

James Almer jamrial at gmail.com
Fri Jul 30 00:06:50 EEST 2021


Ensure instead that it's the correct value.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/movenc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 57062f45c5..fedc9c0e18 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2545,7 +2545,7 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
             int distance = 0;
             for (j = i - 1; j >= 0; j--) {
                 roll_samples_remaining -= get_cluster_duration(track, j);
-                distance++;
+                distance--;
                 if (roll_samples_remaining <= 0)
                     break;
             }
@@ -2555,7 +2555,7 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
             if (roll_samples_remaining > 0)
                 distance = 0;
             /* Verify distance is a maximum of 32 (2.5ms) packets. */
-            if (distance > 32)
+            if (distance < 32)
                 return AVERROR_INVALIDDATA;
             if (i && distance == sgpd_entries[entries].roll_distance) {
                 sgpd_entries[entries].count++;
@@ -2569,7 +2569,7 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
     } else {
         entries++;
         sgpd_entries[entries].count = track->sample_count;
-        sgpd_entries[entries].roll_distance = 1;
+        sgpd_entries[entries].roll_distance = -1;
         sgpd_entries[entries].group_description_index = ++group;
     }
     entries++;
@@ -2588,7 +2588,7 @@ static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
     avio_wb32(pb, group); /* entry_count */
     for (i = 0; i < entries; i++) {
         if (sgpd_entries[i].group_description_index) {
-            avio_wb16(pb, -sgpd_entries[i].roll_distance); /* roll_distance */
+            avio_wb16(pb, sgpd_entries[i].roll_distance); /* roll_distance */
         }
     }
 
-- 
2.32.0



More information about the ffmpeg-devel mailing list