diff mbox

[FFmpeg-devel] lavf/movenc: Allow to disable writing the timecode track

Message ID 201609242240.35695.cehoyos@ag.or.at
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos Sept. 24, 2016, 8:40 p.m. UTC
Hi!

Not everybody is happy about a timecode track in mp4, 
see ticket #5492.

Please comment, Carl Eugen
From 47a813709643106b0d0a2eceff822107c395d15c Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Sat, 24 Sep 2016 22:38:14 +0200
Subject: [PATCH] lavf/movenc: Allow to disable writing the timecode track.

Fixes ticket #5492.
---
 doc/muxers.texi      |    3 +++
 libavformat/movenc.c |    6 ++++--
 libavformat/movenc.h |    1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Sept. 25, 2016, 5:49 p.m. UTC | #1
On Sat, Sep 24, 2016 at 10:40:35PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Not everybody is happy about a timecode track in mp4, 
> see ticket #5492.
> 
> Please comment, Carl Eugen

>  doc/muxers.texi      |    3 +++
>  libavformat/movenc.c |    6 ++++--
>  libavformat/movenc.h |    1 +
>  3 files changed, 8 insertions(+), 2 deletions(-)
> 1ff491854d9a8c694b38153561d873b55688bb13  0001-lavf-movenc-Allow-to-disable-writing-the-timecode-tr.patch
> From 47a813709643106b0d0a2eceff822107c395d15c Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Sat, 24 Sep 2016 22:38:14 +0200
> Subject: [PATCH] lavf/movenc: Allow to disable writing the timecode track.
> 
> Fixes ticket #5492.
> ---
>  doc/muxers.texi      |    3 +++
>  libavformat/movenc.c |    6 ++++--
>  libavformat/movenc.h |    1 +
>  3 files changed, 8 insertions(+), 2 deletions(-)

should be ok, but please wait a day with applying so others can
comment too

[...]
Clément Bœsch Sept. 25, 2016, 7:47 p.m. UTC | #2
On Sat, Sep 24, 2016 at 10:40:35PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Not everybody is happy about a timecode track in mp4, 
> see ticket #5492.
> 
> Please comment, Carl Eugen

> From 47a813709643106b0d0a2eceff822107c395d15c Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Sat, 24 Sep 2016 22:38:14 +0200
> Subject: [PATCH] lavf/movenc: Allow to disable writing the timecode track.
> 
> Fixes ticket #5492.
> ---
>  doc/muxers.texi      |    3 +++
>  libavformat/movenc.c |    6 ++++--
>  libavformat/movenc.h |    1 +
>  3 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 27eb9a0..61476ca 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -884,6 +884,9 @@ the new default-base-is-moof flag instead. This flag is new from
>  14496-12:2012. This may make the fragments easier to parse in certain
>  circumstances (avoiding basing track fragment location calculations
>  on the implicit end of the previous track fragment).
> +@item -write_tmcd
> +Specify 1 to force writing a timecode track, 0 to disable it and -1 to
> +write a timecode track only for mov and mp4 output (default).
>  @end table
>  
>  @subsection Example
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 0382309..a5e4ad1 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -90,6 +90,7 @@ static const AVOption options[] = {
>      { "encryption_key", "The media encryption key (hex)", offsetof(MOVMuxContext, encryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
>      { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
>      { "use_stream_ids_as_track_ids", "use stream ids as track ids", offsetof(MOVMuxContext, use_stream_ids_as_track_ids), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
> +    { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},

AV_OPT_TYPE_BOOL

>      { NULL },
>  };
>  
> @@ -2312,7 +2313,7 @@ static int mov_write_minf_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext
>      } else if (track->tag == MKTAG('r','t','p',' ')) {
>          mov_write_hmhd_tag(pb);
>      } else if (track->tag == MKTAG('t','m','c','d')) {
> -        if (track->mode == MODE_MP4)
> +        if (track->mode != MODE_MOV)
>              mov_write_nmhd_tag(pb);
>          else
>              mov_write_gmhd_tag(pb, track);
> @@ -5539,7 +5540,8 @@ static int mov_write_header(AVFormatContext *s)
>          }
>      }
>  
> -    if (mov->mode == MODE_MOV || mov->mode == MODE_MP4) {
> +    if (   mov->write_tmcd == -1 && (mov->mode == MODE_MOV || mov->mode == MODE_MP4)
> +        || mov->write_tmcd == 1) {
>          tmcd_track = mov->nb_streams;
>  
>          /* +1 tmcd track for each video stream with a timecode */
> diff --git a/libavformat/movenc.h b/libavformat/movenc.h
> index ea76e39..1f7a9d7 100644
> --- a/libavformat/movenc.h
> +++ b/libavformat/movenc.h
> @@ -219,6 +219,7 @@ typedef struct MOVMuxContext {
>  
>      int use_stream_ids_as_track_ids;
>      int track_ids_ok;
> +    int write_tmcd;
>  } MOVMuxContext;
>  

Didn't test nor looked in depth, but OK if it disable timecode in MP4 by
default. Timecode is only (badly) "standardized" in MOV, so we shouldn't
write such track in MP4.
Dave Rice Sept. 25, 2016, 8:51 p.m. UTC | #3
> On Sep 25, 2016, at 1:49 PM, Michael Niedermayer <michael@niedermayer.cc> wrote:
> 
> On Sat, Sep 24, 2016 at 10:40:35PM +0200, Carl Eugen Hoyos wrote:
>> Hi!
>> 
>> Not everybody is happy about a timecode track in mp4, 
>> see ticket #5492.
>> 
>> Please comment, Carl Eugen
> 
>> doc/muxers.texi      |    3 +++
>> libavformat/movenc.c |    6 ++++--
>> libavformat/movenc.h |    1 +
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>> 1ff491854d9a8c694b38153561d873b55688bb13  0001-lavf-movenc-Allow-to-disable-writing-the-timecode-tr.patch
>> From 47a813709643106b0d0a2eceff822107c395d15c Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
>> Date: Sat, 24 Sep 2016 22:38:14 +0200
>> Subject: [PATCH] lavf/movenc: Allow to disable writing the timecode track.
>> 
>> Fixes ticket #5492.
>> ---
>> doc/muxers.texi      |    3 +++
>> libavformat/movenc.c |    6 ++++--
>> libavformat/movenc.h |    1 +
>> 3 files changed, 8 insertions(+), 2 deletions(-)
> 
> should be ok, but please wait a day with applying so others can
> comment too

+1 Tested this and it works well and solves an issue that I occasionally find. Thanks Carl.

[...]

Dave Rice
Carl Eugen Hoyos Sept. 26, 2016, 6:56 a.m. UTC | #4
2016-09-25 21:47 GMT+02:00 Clément Bœsch <u@pkh.me>:

>> +    { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
>
> AV_OPT_TYPE_BOOL

Applied with that change.

[...]

> Didn't test nor looked in depth, but OK if it disable timecode in
> MP4 by default. Timecode is only (badly) "standardized" in MOV,
> so we shouldn't write such track in MP4.

Independent patch sent, this changes (requested) behaviour.

Thank you, Carl Eugen
diff mbox

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 27eb9a0..61476ca 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -884,6 +884,9 @@  the new default-base-is-moof flag instead. This flag is new from
 14496-12:2012. This may make the fragments easier to parse in certain
 circumstances (avoiding basing track fragment location calculations
 on the implicit end of the previous track fragment).
+@item -write_tmcd
+Specify 1 to force writing a timecode track, 0 to disable it and -1 to
+write a timecode track only for mov and mp4 output (default).
 @end table
 
 @subsection Example
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 0382309..a5e4ad1 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -90,6 +90,7 @@  static const AVOption options[] = {
     { "encryption_key", "The media encryption key (hex)", offsetof(MOVMuxContext, encryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
     { "use_stream_ids_as_track_ids", "use stream ids as track ids", offsetof(MOVMuxContext, use_stream_ids_as_track_ids), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+    { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { NULL },
 };
 
@@ -2312,7 +2313,7 @@  static int mov_write_minf_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext
     } else if (track->tag == MKTAG('r','t','p',' ')) {
         mov_write_hmhd_tag(pb);
     } else if (track->tag == MKTAG('t','m','c','d')) {
-        if (track->mode == MODE_MP4)
+        if (track->mode != MODE_MOV)
             mov_write_nmhd_tag(pb);
         else
             mov_write_gmhd_tag(pb, track);
@@ -5539,7 +5540,8 @@  static int mov_write_header(AVFormatContext *s)
         }
     }
 
-    if (mov->mode == MODE_MOV || mov->mode == MODE_MP4) {
+    if (   mov->write_tmcd == -1 && (mov->mode == MODE_MOV || mov->mode == MODE_MP4)
+        || mov->write_tmcd == 1) {
         tmcd_track = mov->nb_streams;
 
         /* +1 tmcd track for each video stream with a timecode */
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index ea76e39..1f7a9d7 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -219,6 +219,7 @@  typedef struct MOVMuxContext {
 
     int use_stream_ids_as_track_ids;
     int track_ids_ok;
+    int write_tmcd;
 } MOVMuxContext;
 
 #define FF_MOV_FLAG_RTP_HINT              (1 <<  0)