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(-)
@@ -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 */
/**
@@ -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);
@@ -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