diff mbox series

[FFmpeg-devel,20/25] avformat/matroskaenc: Redo applying ProRes offset

Message ID AM7PR03MB666097A3FF6D6F36F65045828F569@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit abbc111067bfa7beafc51aa60f153bba3f4caca6
Headers show
Series [FFmpeg-devel,01/25] avformat/matroskaenc: Fix potential overflow | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 16, 2022, 11:04 p.m. UTC
Add a field to mkv_track that is set to the offset instead
of checking for whether the track is ProRes when writing
the Block. This makes writing the Block independent
of the AVCodecParameters.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/matroskaenc.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index be1b3711e4..fdce3fad49 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -167,6 +167,7 @@  typedef struct mkv_track {
     unsigned        track_num;
     int             track_num_size;
     int             sample_rate;
+    unsigned        offset;
     int64_t         sample_rate_offset;
     int64_t         last_timestamp;
     int64_t         duration;
@@ -2451,12 +2452,9 @@  static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
         return err;
     }
 
-    if (CONFIG_MATROSKA_MUXER &&
-        par->codec_id == AV_CODEC_ID_PRORES && size >= 8) {
-        /* Matroska specification requires to remove the first QuickTime atom
-         */
-        size  -= 8;
-        offset = 8;
+    if (track->offset <= size) {
+        size  -= track->offset;
+        offset = track->offset;
     }
 
     side_data = av_packet_get_side_data(pkt,
@@ -3117,6 +3115,11 @@  static int mkv_init(struct AVFormatContext *s)
                 (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1))
                 track->reformat = mkv_reformat_h2645;
             break;
+        case AV_CODEC_ID_PRORES:
+            /* Matroska specification requires to remove
+             * the first QuickTime atom. */
+            track->offset = 8;
+            break;
 #endif
         case AV_CODEC_ID_AV1:
             track->reformat = mkv_reformat_av1;