Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lynne <dev@lynne.ee>
To: Ffmpeg Devel <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avformat: add AVFMT_INIT_ZERO_SKIP flag and use it in MOV
Date: Mon, 30 Oct 2023 19:56:59 +0100 (CET)
Message-ID: <Ni0wZ0L--3-9@lynne.ee> (raw)

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

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.


[-- Attachment #2: 0001-avformat-add-AVFMT_INIT_ZERO_SKIP-flag-and-use-it-in.patch --]
[-- Type: text/x-diff, Size: 2938 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2023-10-30 18:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ni0wZ0L--3-9@lynne.ee \
    --to=dev@lynne.ee \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git