如何使用ffmpeg写入mp4元数据而不影响视频数据

时间:2018-07-13 10:49:36

标签: video ffmpeg metadata mp4

我试图在一个步骤中将元数据写入视频文件,并在另一步骤中捕获视频文件的“原始数据”(无元数据)部分。问题在于,对于MP4文件,向文件中添加元数据似乎也会改变原始视频数据,而MKV文件会按预期运行。这是一个包含两个文件的示例:test.mkvtest.mp4

MKV

ffmpeg -i test.mkv -loglevel error -metadata 'arbitrary=string' -codec copy test-new-metadata.mkv

ffmpeg -i test.mkv              -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
631becf821dca89b150120d25393491a  -

ffmpeg -i test-new-metadata.mkv -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
631becf821dca89b150120d25393491a  -

MP4

ffmpeg -i test.mp4 -loglevel error -metadata 'arbitrary=string' -codec copy test-new-metadata.mp4

ffmpeg -i test.mp4              -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
b9b28e4ac500be961bd07290a34cf93f  -

ffmpeg -i test-new-metadata.mp4 -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
d13e7177fae9b341994bc1ee8f3812bc  -

...现在是webm,只是看我是否迷失了方向:

Webm

ffmpeg -i test.webm -loglevel error -metadata 'arbitrary=string' -codec copy test-new-metadata.webm

ffmpeg -i test.webm              -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
a62e053d3dbf627db4d77c5165152a81  -

ffmpeg -i test-new-metadata.webm -loglevel error -map 0:v:0 -c copy -f data - -map 0:a:0 -c copy -f data - | md5sum
a62e053d3dbf627db4d77c5165152a81  -

因此,我想知道我对如何捕获原始视频的理解是错误的,还是MP4在某种程度上是“特殊的”。请注意,我对使用ffmpeg自己的哈希函数不感兴趣,因为我想通过外部进程运行原始数据。在这里使用md5sum只是为了测试输出是否相同。

更新:根据要求,我将包括MP4文件元数据写入步骤的输出:

$ ffmpeg -i test.mp4 -metadata 'arbitrary=string' -codec copy test-new-metadata.mp4
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.1.1 (GCC) 20180531
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avresample --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20T21:29:11.000000Z
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
Output #0, mp4, to 'test-new-metadata.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    arbitrary       : string
    encoder         : Lavf58.12.100
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, q=2-31, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  166 fps=0.0 q=-1.0 Lsize=     377kB time=00:00:05.54 bitrate= 556.7kbits/s speed=4.07e+03x    
video:315kB audio:56kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.609490%

更新2 :这是link to the misbehaving mp4 file(375k)。

0 个答案:

没有答案