[FFmpeg-devel] [PATCH 3/5] avformat/movenc: fix traf_number field inside tfra box
Zhao Zhili
quinkblack at foxmail.com
Fri Dec 3 07:06:55 EET 2021
traf_number indicates the ‘traf’ number that contains the sync sample.
The number ranges from 1 (the first ‘traf’ is numbered 1) in each ‘moof’.
For A-V interleaved fmp4 with two traf boxes inside a moof, tfra box
was broken.
---
libavformat/movenc.c | 4 +++-
libavformat/movenc.h | 2 ++
tests/ref/fate/movenc | 28 ++++++++++++++--------------
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 06d3819591..f8731d33c5 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4628,6 +4628,7 @@ static int mov_add_tfra_entries(AVIOContext *pb, MOVMuxContext *mov, int tracks,
int size)
{
int i;
+ uint32_t index = 0;
for (i = 0; i < mov->nb_streams; i++) {
MOVTrack *track = &mov->tracks[i];
MOVFragmentInfo *info;
@@ -4659,6 +4660,7 @@ static int mov_add_tfra_entries(AVIOContext *pb, MOVMuxContext *mov, int tracks,
info->time = 0;
}
info->tfrf_offset = 0;
+ info->traf_index = ++index;
mov_write_tfrf_tags(pb, mov, track);
}
return 0;
@@ -4960,7 +4962,7 @@ static int mov_write_tfra_tag(AVIOContext *pb, MOVTrack *track)
continue;
avio_wb64(pb, track->frag_info[i].time);
avio_wb64(pb, track->frag_info[i].offset + track->data_offset);
- avio_w8(pb, 1); /* traf number */
+ avio_w8(pb, track->frag_info[i].traf_index); /* traf number */
avio_w8(pb, 1); /* trun number */
avio_w8(pb, 1); /* sample number */
}
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index f73604d6f3..e3a5e2864a 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -81,6 +81,8 @@ typedef struct MOVFragmentInfo {
int64_t tfrf_offset;
int size;
uint32_t first_sample_flags;
+ /* ranges from 1 (the first ‘traf’ is numbered 1) in each ‘moof’ */
+ uint32_t traf_index;
} MOVFragmentInfo;
typedef struct MOVTrack {
diff --git a/tests/ref/fate/movenc b/tests/ref/fate/movenc
index 70c66b7fd7..529a1c6da5 100644
--- a/tests/ref/fate/movenc
+++ b/tests/ref/fate/movenc
@@ -2,17 +2,17 @@ write_data len 36, time nopts, type header atom ftyp
write_data len 2429, time nopts, type header atom -
write_data len 788, time 1000000, type sync atom moof
write_data len 110, time nopts, type trailer atom -
-6f06e338c71468d56580df40ff265066 3363 non-empty-moov
+e38b4db4d6542159a18a231df1f8a17a 3363 non-empty-moov
write_data len 36, time nopts, type header atom ftyp
write_data len 2761, time nopts, type header atom -
write_data len 908, time 966667, type sync atom moof
write_data len 110, time nopts, type trailer atom -
-caf0876986b5f033efc0958c338289cc 3815 non-empty-moov-elst
+aced0fb08e209f7b892fc69319de4c6c 3815 non-empty-moov-elst
write_data len 36, time nopts, type header atom ftyp
write_data len 2669, time nopts, type header atom -
write_data len 908, time 1000000, type sync atom moof
write_data len 110, time nopts, type trailer atom -
-e106084014ed245ed7c4a30f1d11a3ac 3723 non-empty-moov-no-elst
+d2879ae4007bec11714c47ed9c4606c9 3723 non-empty-moov-no-elst
write_data len 24, time nopts, type header atom ftyp
write_data len 1171, time nopts, type header atom -
write_data len 728, time 0, type sync atom moof
@@ -26,29 +26,29 @@ write_data len 1123, time nopts, type header atom -
write_data len 796, time 0, type sync atom moof
write_data len 788, time 1000000, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-08f4b3ad3a3ea224b2ee731476b9056b 2891 empty-moov
+7c8bbc289e14ae747ad3f9c73107912b 2891 empty-moov
write_data len 36, time nopts, type header atom ftyp
write_data len 1123, time nopts, type header atom -
write_data len 1068, time 0, type sync atom moof
write_data len 908, time 1000000, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-d7a2dcb43eb0f95f92669f55fc7adeba 3283 empty-moov-no-elst
+0c6a543b723d16f5bb2bbb1204625a41 3283 empty-moov-no-elst
write_data len 36, time nopts, type header atom ftyp
write_data len 1123, time nopts, type header atom -
write_data len 900, time -33333, type sync atom moof
write_data len 908, time 966667, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-ea70ca697306976879be408431c27aee 3115 empty-moov-no-elst-no-adjust
+f99a6f2437e513d6dcf521f8d167f342 3115 empty-moov-no-elst-no-adjust
write_data len 1159, time nopts, type header atom ftyp
write_data len 796, time 0, type sync atom moof
write_data len 788, time 1000000, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-08f4b3ad3a3ea224b2ee731476b9056b 2891 delay-moov
+7c8bbc289e14ae747ad3f9c73107912b 2891 delay-moov
write_data len 1231, time nopts, type header atom ftyp
write_data len 916, time -33333, type sync atom moof
write_data len 908, time 966667, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-314cc3b6296f4ee583b328a34be50b2f 3203 delay-moov-elst
+a7ddf0bfd32683de9dd22afe3b1135a4 3203 delay-moov-elst
write_data len 1195, time nopts, type header atom ftyp
write_data len 836, time 0, type sync atom moof
write_data len 67, time nopts, type trailer atom -
@@ -117,12 +117,12 @@ write_data len 1223, time nopts, type header atom ftyp
write_data len 2572, time -333333, type sync atom sidx
write_data len 996, time 5166667, type sync atom sidx
write_data len 148, time nopts, type trailer atom -
-d37a7eda807912b9ed05ccfe003a9e4f 4939 vfr
+0009ab3c8ebc80a286e5b10dfacc8ef3 4939 vfr
write_data len 1223, time nopts, type header atom ftyp
write_data len 2572, time -333333, type sync atom sidx
write_data len 996, time 5166667, type sync atom sidx
write_data len 148, time nopts, type trailer atom -
-d37a7eda807912b9ed05ccfe003a9e4f 4939 vfr-noduration
+0009ab3c8ebc80a286e5b10dfacc8ef3 4939 vfr-noduration
write_data len 1231, time nopts, type header atom ftyp
write_data len 1500, time -333333, type sync atom moof
write_data len 1500, time nopts, type unknown atom -
@@ -131,7 +131,7 @@ write_data len 1500, time 9666667, type sync atom moof
write_data len 1500, time nopts, type unknown atom -
write_data len 1004, time nopts, type unknown atom -
write_data len 148, time nopts, type trailer atom -
-08b6401dc81912e5264245b7233c4ab3 9299 large_frag
+9549eeeac8731d820dc395bc73aa605f 9299 large_frag
write_data len 1231, time nopts, type header atom ftyp
write_data len 684, time -33333, type sync atom moof
write_data len 504, time 800000, type boundary atom moof
@@ -139,15 +139,15 @@ write_data len 420, time 1266667, type boundary atom moof
write_data len 668, time 1566667, type sync atom moof
write_data len 440, time 2233333, type boundary atom moof
write_data len 205, time nopts, type trailer atom -
-2dd052ab30624c1a415184c5bf973670 4152 vfr-noduration-interleave
+9ec014d07518b90a5321d792d737bfc0 4152 vfr-noduration-interleave
write_data len 1231, time nopts, type header atom ftyp
write_data len 916, time 0, type sync atom moof
write_data len 908, time 1000000, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-d81c3a0ce5940a2db74c99ad435e0560 3203 delay-moov-elst-neg-cts
+b8076064cedf2fefc242d9af67cdaeba 3203 delay-moov-elst-neg-cts
write_data len 36, time nopts, type header atom ftyp
write_data len 1123, time nopts, type header atom -
write_data len 900, time 0, type sync atom moof
write_data len 908, time 1000000, type sync atom moof
write_data len 148, time nopts, type trailer atom -
-3be575022e446855bca1e45b7942cc0c 3115 empty-moov-neg-cts
+c1307485f65c4a00a06ca82f5e0b1361 3115 empty-moov-neg-cts
--
2.31.1
More information about the ffmpeg-devel
mailing list