diff mbox series

[FFmpeg-devel] avformat/mov: add option to use tfdt for fragment timestamps.

Message ID 20210529090452.10239-1-ffmpeg@gyani.pro
State Accepted
Commit 071930de724166bfb90fc6d368c748771188fd94
Headers show
Series [FFmpeg-devel] avformat/mov: add option to use tfdt for fragment timestamps. | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Gyan Doshi May 29, 2021, 9:04 a.m. UTC
---

I faced the same issue as the poster in

https://lists.ffmpeg.org/pipermail/ffmpeg-user/2018-March/039038.html

After patch, start_time is correct as well as monotonicity of ts.

 doc/demuxers.texi  | 6 ++++++
 libavformat/isom.h | 1 +
 libavformat/mov.c  | 4 +++-
 3 files changed, 10 insertions(+), 1 deletion(-)

Comments

Gyan Doshi May 31, 2021, 6:22 p.m. UTC | #1
Plan to push tomorrow.

On 2021-05-29 14:34, Gyan Doshi wrote:
> ---
>
> I faced the same issue as the poster in
>
> https://lists.ffmpeg.org/pipermail/ffmpeg-user/2018-March/039038.html
>
> After patch, start_time is correct as well as monotonicity of ts.
>
>   doc/demuxers.texi  | 6 ++++++
>   libavformat/isom.h | 1 +
>   libavformat/mov.c  | 4 +++-
>   3 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 13fe17ff4f..38734b577f 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -662,6 +662,12 @@ Set mfra timestamps as PTS
>   Don't use mfra box to set timestamps
>   @end table
>   
> +@item use_tfdt
> +For fragmented input, set fragment's starting timestamp to @code{baseMediaDecodeTime} from the @code{tfdt} box.
> +Default is disabled, which will preferentially use the @code{earliest_presentation_time} from the @code{sidx} box.
> +In either case, the timestamp from the @code{mfra} box will be used if it's available and @code{use_mfra_for} is
> +set to pts or dts.
> +
>   @item export_all
>   Export unrecognized boxes within the @var{udta} box as metadata entries. The first four
>   characters of the box type are set as the key. Default is false.
> diff --git a/libavformat/isom.h b/libavformat/isom.h
> index 5a6d504090..ac1b3f3d56 100644
> --- a/libavformat/isom.h
> +++ b/libavformat/isom.h
> @@ -277,6 +277,7 @@ typedef struct MOVContext {
>       int moov_retry;
>       int use_mfra_for;
>       int has_looked_for_mfra;
> +    int use_tfdt;
>       MOVFragmentIndex frag_index;
>       int atom_depth;
>       unsigned int aax_mode;  ///< 'aax' file has been detected
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index c088c9f515..6c99a67ff5 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -4803,7 +4803,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
>               dts = frag_stream_info->first_tfra_pts;
>               av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64
>                       ", using it for dts\n", pts);
> -        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) {
> +        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE && !c->use_tfdt) {
>               // FIXME: sidx earliest_presentation_time is *PTS*, s.b.
>               // pts = frag_stream_info->sidx_pts;
>               dts = frag_stream_info->sidx_pts - sc->time_offset;
> @@ -8169,6 +8169,8 @@ static const AVOption mov_options[] = {
>           FLAGS, "use_mfra_for" },
>       {"pts", "pts", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_MFRA_PTS}, 0, 0,
>           FLAGS, "use_mfra_for" },
> +    {"use_tfdt", "use tfdt for fragment timestamps", OFFSET(use_tfdt), AV_OPT_TYPE_BOOL, {.i64 = 0},
> +        0, 1, FLAGS},
>       { "export_all", "Export unrecognized metadata entries", OFFSET(export_all),
>           AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS },
>       { "export_xmp", "Export full XMP metadata", OFFSET(export_xmp),
Gyan Doshi June 2, 2021, 5:17 a.m. UTC | #2
On 2021-05-31 23:52, Gyan Doshi wrote:
> Plan to push tomorrow.

Pushed as 071930de724166bfb90fc6d368c748771188fd94


>
> On 2021-05-29 14:34, Gyan Doshi wrote:
>> ---
>>
>> I faced the same issue as the poster in
>>
>> https://lists.ffmpeg.org/pipermail/ffmpeg-user/2018-March/039038.html
>>
>> After patch, start_time is correct as well as monotonicity of ts.
>>
>>   doc/demuxers.texi  | 6 ++++++
>>   libavformat/isom.h | 1 +
>>   libavformat/mov.c  | 4 +++-
>>   3 files changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
>> index 13fe17ff4f..38734b577f 100644
>> --- a/doc/demuxers.texi
>> +++ b/doc/demuxers.texi
>> @@ -662,6 +662,12 @@ Set mfra timestamps as PTS
>>   Don't use mfra box to set timestamps
>>   @end table
>>   +@item use_tfdt
>> +For fragmented input, set fragment's starting timestamp to 
>> @code{baseMediaDecodeTime} from the @code{tfdt} box.
>> +Default is disabled, which will preferentially use the 
>> @code{earliest_presentation_time} from the @code{sidx} box.
>> +In either case, the timestamp from the @code{mfra} box will be used 
>> if it's available and @code{use_mfra_for} is
>> +set to pts or dts.
>> +
>>   @item export_all
>>   Export unrecognized boxes within the @var{udta} box as metadata 
>> entries. The first four
>>   characters of the box type are set as the key. Default is false.
>> diff --git a/libavformat/isom.h b/libavformat/isom.h
>> index 5a6d504090..ac1b3f3d56 100644
>> --- a/libavformat/isom.h
>> +++ b/libavformat/isom.h
>> @@ -277,6 +277,7 @@ typedef struct MOVContext {
>>       int moov_retry;
>>       int use_mfra_for;
>>       int has_looked_for_mfra;
>> +    int use_tfdt;
>>       MOVFragmentIndex frag_index;
>>       int atom_depth;
>>       unsigned int aax_mode;  ///< 'aax' file has been detected
>> diff --git a/libavformat/mov.c b/libavformat/mov.c
>> index c088c9f515..6c99a67ff5 100644
>> --- a/libavformat/mov.c
>> +++ b/libavformat/mov.c
>> @@ -4803,7 +4803,7 @@ static int mov_read_trun(MOVContext *c, 
>> AVIOContext *pb, MOVAtom atom)
>>               dts = frag_stream_info->first_tfra_pts;
>>               av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64
>>                       ", using it for dts\n", pts);
>> -        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) {
>> +        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE && 
>> !c->use_tfdt) {
>>               // FIXME: sidx earliest_presentation_time is *PTS*, s.b.
>>               // pts = frag_stream_info->sidx_pts;
>>               dts = frag_stream_info->sidx_pts - sc->time_offset;
>> @@ -8169,6 +8169,8 @@ static const AVOption mov_options[] = {
>>           FLAGS, "use_mfra_for" },
>>       {"pts", "pts", 0, AV_OPT_TYPE_CONST, {.i64 = 
>> FF_MOV_FLAG_MFRA_PTS}, 0, 0,
>>           FLAGS, "use_mfra_for" },
>> +    {"use_tfdt", "use tfdt for fragment timestamps", 
>> OFFSET(use_tfdt), AV_OPT_TYPE_BOOL, {.i64 = 0},
>> +        0, 1, FLAGS},
>>       { "export_all", "Export unrecognized metadata entries", 
>> OFFSET(export_all),
>>           AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS },
>>       { "export_xmp", "Export full XMP metadata", OFFSET(export_xmp),
>
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 13fe17ff4f..38734b577f 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -662,6 +662,12 @@  Set mfra timestamps as PTS
 Don't use mfra box to set timestamps
 @end table
 
+@item use_tfdt
+For fragmented input, set fragment's starting timestamp to @code{baseMediaDecodeTime} from the @code{tfdt} box.
+Default is disabled, which will preferentially use the @code{earliest_presentation_time} from the @code{sidx} box.
+In either case, the timestamp from the @code{mfra} box will be used if it's available and @code{use_mfra_for} is
+set to pts or dts.
+
 @item export_all
 Export unrecognized boxes within the @var{udta} box as metadata entries. The first four
 characters of the box type are set as the key. Default is false.
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 5a6d504090..ac1b3f3d56 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -277,6 +277,7 @@  typedef struct MOVContext {
     int moov_retry;
     int use_mfra_for;
     int has_looked_for_mfra;
+    int use_tfdt;
     MOVFragmentIndex frag_index;
     int atom_depth;
     unsigned int aax_mode;  ///< 'aax' file has been detected
diff --git a/libavformat/mov.c b/libavformat/mov.c
index c088c9f515..6c99a67ff5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4803,7 +4803,7 @@  static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
             dts = frag_stream_info->first_tfra_pts;
             av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64
                     ", using it for dts\n", pts);
-        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE) {
+        } else if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE && !c->use_tfdt) {
             // FIXME: sidx earliest_presentation_time is *PTS*, s.b.
             // pts = frag_stream_info->sidx_pts;
             dts = frag_stream_info->sidx_pts - sc->time_offset;
@@ -8169,6 +8169,8 @@  static const AVOption mov_options[] = {
         FLAGS, "use_mfra_for" },
     {"pts", "pts", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_MFRA_PTS}, 0, 0,
         FLAGS, "use_mfra_for" },
+    {"use_tfdt", "use tfdt for fragment timestamps", OFFSET(use_tfdt), AV_OPT_TYPE_BOOL, {.i64 = 0},
+        0, 1, FLAGS},
     { "export_all", "Export unrecognized metadata entries", OFFSET(export_all),
         AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS },
     { "export_xmp", "Export full XMP metadata", OFFSET(export_xmp),