[FFmpeg-devel] [PATCH 1/1] avformat/movenc: use modern iTunes copyright atom

Timo Teräs timo.teras at iki.fi
Wed Mar 28 19:02:48 EEST 2018


iTunes currently uses the 'cprt' atom to store the copyright notice
and this patch fixes compatibility with majority of software that
supports the 'ilst' atom. Other software and documentation using this:
 - AtomicParseley encodes and parses only 'cprt'
 - Most players recognize only 'cprt'
 - https://sno.phy.queensu.ca/~phil/exiftool/TagNames/QuickTime.html
   documents both tag types
 - http://mutagen.readthedocs.io/en/latest/api/mp4.html documents
   only 'cprt'

ffmpeg mov reader properly parses the 'cprt' tag inside 'ilst' tag
and functions correctly with streams produced with this commit.

Since 'cprt' seems to be the current correct atom, it is used by
default. "-movflags legacy_copyright" option is added to revert
back to the old atom type in case that is needed.

Signed-off-by: Timo Teräs <timo.teras at iki.fi>
---
If the legacy option is not needed, I'm happy to resend patch just
changing the atom types.

 libavformat/movenc.c | 6 +++++-
 libavformat/movenc.h | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ef668eccd5..230aeb6a6d 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -79,6 +79,7 @@ static const AVOption options[] = {
     { "use_metadata_tags", "Use mdta atom for metadata.", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_USE_MDTA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "skip_trailer", "Skip writing the mfra/tfra/mfro trailer for fragmented files", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_TRAILER}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "negative_cts_offsets", "Use negative CTS offsets (reducing the need for edit lists)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+    { "legacy_copyright", "Use legacy iTunes (c)cpy copyright atom inside ilst", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_LEGACY_ILTS_CPRT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
     { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
     { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
@@ -3432,7 +3433,10 @@ static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov,
     }
     mov_write_string_metadata(s, pb, "\251cmt", "comment"  , 1);
     mov_write_string_metadata(s, pb, "\251gen", "genre"    , 1);
-    mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1);
+    if (mov->flags & FF_MOV_FLAG_LEGACY_ILTS_CPRT)
+      mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1);
+    else
+      mov_write_string_metadata(s, pb, "cprt", "copyright", 1);
     mov_write_string_metadata(s, pb, "\251grp", "grouping" , 1);
     mov_write_string_metadata(s, pb, "\251lyr", "lyrics"   , 1);
     mov_write_string_metadata(s, pb, "desc",    "description",1);
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index ca2a9c9722..e83a29aea2 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -246,6 +246,7 @@ typedef struct MOVMuxContext {
 #define FF_MOV_FLAG_SKIP_TRAILER          (1 << 18)
 #define FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS  (1 << 19)
 #define FF_MOV_FLAG_FRAG_EVERY_FRAME      (1 << 20)
+#define FF_MOV_FLAG_LEGACY_ILTS_CPRT      (1 << 21)
 
 int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
 
-- 
2.16.2



More information about the ffmpeg-devel mailing list