diff mbox series

[FFmpeg-devel] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV

Message ID Ni0wZ0L--3-9@lynne.ee
State New
Headers show
Series [FFmpeg-devel] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Lynne Oct. 30, 2023, 6:56 p.m. UTC
Meant to be applied on top my AAC patchset.

MOV trims both the decoder/codec's algorithmic delay,
and additionally, any samples the encoder needs removed, via edit lists,
which we export as skip_samples side data.

The issue is that if there are no edit lists, with the recent AAC
decoding algorithmic delay removal patch, the default, algorithmic
delay will be removed of 1024 samples.

However, MOV specifies that this delay should be left as-is, even if
edit lists are not used.

demux.c, however, only signals a SKIP_SAMPLES side data if it is non-zero.
Hence, this patch just changes this such that side data will always be
put for MOV, even if it is zero, for only the first frame.

This way, the decoder will not skip the algorithmic delay by itself.

Patch attached.
diff mbox series

Patch

From 27e7e32e862b7dcd0f3c89a138f9ff64ed5042ed Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Mon, 30 Oct 2023 19:42:14 +0100
Subject: [PATCH] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV

MOV trims both the decoder/codec's algorithmic delay,
and additionally, any samples the encoder needs removed, via edit lists,
which we export as skip_samples side data.

The issue is that if there are no edit lists, with the recent AAC
decoding algorithmic delay removal patch, the default, algorithmic
delay will be removed of 1024 samples.

However, MOV specifies that this delay should be left as-is, even if
edit lists are not used.

demux.c, however, only signals a SKIP_SAMPLES side data if it is non-zero.
Hence, this patch just changes this such that side data will always be
put for MOV, even if it is zero, for only the first frame.
---
 libavformat/avformat.h | 4 ++++
 libavformat/demux.c    | 3 ++-
 libavformat/mov.c      | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 9e7eca007e..8a1ae91042 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -501,6 +501,10 @@  typedef struct AVProbeData {
                                         AVFormatContext.avoid_negative_ts
                                         */
 
+#define AVFMT_INIT_ZERO_SKIP 0x80000  /**< Format requires that skip_samples should
+                                           always be signalled, even if it is zero,
+                                           for the first frame. */
+
 #define AVFMT_SEEK_TO_PTS   0x4000000 /**< Seeking is based on PTS */
 
 /**
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 6f640b92b1..a4953d36f1 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -1398,7 +1398,8 @@  FF_ENABLE_DEPRECATION_WARNINGS
         if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE))
             sti->skip_samples = sti->start_skip_samples;
         sti->skip_samples = FFMAX(0, sti->skip_samples);
-        if (sti->skip_samples || discard_padding) {
+        if (sti->skip_samples || discard_padding ||
+            ((s->iformat->flags & AVFMT_INIT_ZERO_SKIP) && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE))) {
             uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
             if (p) {
                 AV_WL32(p, sti->skip_samples);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2f29487beb..e012bd0291 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -9327,5 +9327,5 @@  const AVInputFormat ff_mov_demuxer = {
     .read_packet    = mov_read_packet,
     .read_close     = mov_read_close,
     .read_seek      = mov_read_seek,
-    .flags          = AVFMT_NO_BYTE_SEEK | AVFMT_SEEK_TO_PTS | AVFMT_SHOW_IDS,
+    .flags          = AVFMT_NO_BYTE_SEEK | AVFMT_SEEK_TO_PTS | AVFMT_SHOW_IDS | AVFMT_INIT_ZERO_SKIP,
 };
-- 
2.42.0