将所有元数据(文件和视频)和非视频流从一个视频复制到另一个视频

将所有元数据(文件和视频)和非视频流从一个视频复制到另一个视频

这与这个问题有些类似,但稍微复杂一些。使用 ffmpeg 将元数据从一个文件复制到另一个文件

我有两个视频。

  • 视频 1 - 来自摄像机的原始视频,包含我们需要的流和元数据
  • 视频 2 - 经过 After Effects 修饰,现在缺少元数据和流。

我希望将视频 1 中的所有非视频流复制到新视频(视频流 0 以外的所有内容)。我只想将视频 2(流 0)的视频流复制到新文件。我希望这有意义。

我正在 After Effects 中修饰原始素材,并希望将其与所有原始元数据一起导出,以便我可以将其导入 GoPro Fusion Studio 进行稳定和拼接。

这是实际源文件的完整细节...或输入 0...原始素材。

  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2019-08-18T12:27:46.000000Z
    firmware        : FS1.04.01.80.00
  Duration: 00:07:00.42, start: 0.000000, bitrate: 45287 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 2704x2624 [SAR 1:1 DAR 169:164], 44954 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AVC
      encoder         : GoPro AVC encoder
      timecode        : 12:52:47:11
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AAC
      timecode        : 12:52:47:11
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro TCD
      timecode        : 12:52:47:11
    Stream #0:3(eng): Data: none (gpmd / 0x646D7067), 184 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro MET
    Stream #0:4(eng): Data: none (fdsc / 0x63736466), 9 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro SOS

编辑:根据评论更新,经过几天的调整。我们目前正在使用此脚本将两个输入文件合并为一个新文件。我们的目标和期望是,在映射元数据和流之后,我们最终会得到一个与源视频几乎相同的文件。

这是我们正在使用的 sh 文件。

ffmpeg -i GF120010.source.MP4 -i GF120010.fixed.MP4 -copy_unknown -map_metadata 0 -c copy -tag:d:1 'gpmd' -tag:d:2 'gpmd' -map 1:v -metadata:s:v: handler=' GoPro AVC' -map 0:a -metadata:s:a: handler=' GoPro AAC' -map 0:m:handler_name:' GoPro TCD' -metadata:s:d:0 handler=' GoPro TCD' -map 0:m:handler_name:' GoPro MET' -metadata:s:d:1 handler=' GoPro MET' -map 0:m:handler_name:' GoPro SOS' -metadata:s:d:2 handler=' GoPro SOS' GF120010.mp4

这是运行该脚本后的输出:

  built with gcc 7.3.1 (GCC) 20180722
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  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
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002577f72b740] Using non-standard frame rate 29/1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GF120010.source.MP4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2019-08-18T12:27:46.000000Z
    firmware        : FS1.04.01.80.00
  Duration: 00:07:00.42, start: 0.000000, bitrate: 45287 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 2704x2624 [SAR 1:1 DAR 169:164], 44954 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AVC
      encoder         : GoPro AVC encoder
      timecode        : 12:52:47:11
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AAC
      timecode        : 12:52:47:11
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro TCD
      timecode        : 12:52:47:11
    Stream #0:3(eng): Data: none (gpmd / 0x646D7067), 184 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro MET
    Stream #0:4(eng): Data: none (fdsc / 0x63736466), 9 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro SOS
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'GF120010.fixed.MP4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2019-08-25T01:14:49.000000Z
  Duration: 00:07:00.46, start: 0.000000, bitrate: 50357 kb/s
    Stream #1:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 2704x2624, 50040 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2019-08-25T01:14:50.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2019-08-25T01:14:54.000000Z
      handler_name    : Alias Data Handler
File 'GF120010.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'GF120010.mp4':
  Metadata:
    major_brand     : mp41
    minor_version   : 538120216
    compatible_brands: mp41
    creation_time   : 2019-08-18T12:27:46.000000Z
    firmware        : FS1.04.01.80.00
    encoder         : Lavf58.12.100
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 2704x2624, q=2-31, 50040 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
    Metadata:
      creation_time   : 2019-08-25T01:14:50.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
      handler         :         GoPro AVC
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AAC
      timecode        : 12:52:47:11
      handler         :         GoPro AAC
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro TCD
      timecode        : 12:52:47:11
      handler         :         GoPro TCD
    Stream #0:3(eng): Data: none (gpmd / 0x646D7067), 184 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro MET
      handler         :         GoPro MET
    Stream #0:4(eng): Data: none (gpmd / 0x646D7067), 9 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro SOS
      handler         :         GoPro SOS
Stream mapping:
  Stream #1:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
  Stream #0:3 -> #0:3 (copy)
  Stream #0:4 -> #0:4 (copy)
Press [q] to stop, [?] for help
frame=12600 fps=696 q=-1.0 Lsize= 2585057kB time=00:07:00.39 bitrate=50373.6kbits/s speed=23.2x
video:2568126kB audio:6569kB subtitle:0kB other streams:10000kB global headers:0kB muxing overhead: 0.014028% 

输出后,这是 ffmpeg 对新生成的 mp4 显示的内容

  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2019-08-18T12:27:46.000000Z
    encoder         : Lavf58.12.100
  Duration: 00:07:00.42, start: 0.000000, bitrate: 50370 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 2704x2624, 50040 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AVC
      timecode        : 12:52:47:11
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro AAC
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro TCD
      timecode        : 12:52:47:11
    Stream #0:3(eng): Data: none (gpmd / 0x646D7067), 184 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro MET
    Stream #0:4(eng): Data: none (gpmd / 0x646D7067), 9 kb/s (default)
    Metadata:
      creation_time   : 2019-08-18T12:27:46.000000Z
      handler_name    :         GoPro SOS

使用 ExifTool,这些是 ffmpeg 导出的 MP4 的详细信息

[System]        FileName                        : GF120010.mp4
[System]        Directory                       : .
[System]        FileSize                        : 2.5 GB
[System]        FileModifyDate                  : 2019:08:27 20:54:28-05:00
[System]        FileAccessDate                  : 2019:08:27 20:54:28-05:00
[System]        FileCreateDate                  : 2019:08:19 12:12:48-05:00
[System]        FilePermissions                 : rw-rw-rw-
[File]          FileType                        : MP4
[File]          FileTypeExtension               : mp4
[File]          MIMEType                        : video/mp4
[QuickTime]     MajorBrand                      : MP4  Base Media v1 [IS0 14496-12:2003]
[QuickTime]     MinorVersion                    : 0.2.0
[QuickTime]     CompatibleBrands                : isom, iso2, avc1, mp41
[QuickTime]     MovieDataSize                   : 2646726722
[QuickTime]     MovieDataOffset                 : 48
[QuickTime]     MovieHeaderVersion              : 0
[QuickTime]     CreateDate                      : 2019:08:18 12:27:46
[QuickTime]     ModifyDate                      : 2019:08:18 12:27:46
[QuickTime]     TimeScale                       : 1000
[QuickTime]     Duration                        : 0:07:00
[QuickTime]     PreferredRate                   : 1
[QuickTime]     PreferredVolume                 : 100.00%
[QuickTime]     MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[QuickTime]     PreviewTime                     : 0 s
[QuickTime]     PreviewDuration                 : 0 s
[QuickTime]     PosterTime                      : 0 s
[QuickTime]     SelectionTime                   : 0 s
[QuickTime]     SelectionDuration               : 0 s
[QuickTime]     CurrentTime                     : 0 s
[QuickTime]     NextTrackID                     : 6
[QuickTime]     HandlerType                     : Metadata
[QuickTime]     HandlerVendorID                 : Apple
[Track1]        TrackHeaderVersion              : 0
[Track1]        TrackCreateDate                 : 2019:08:18 12:27:46
[Track1]        TrackModifyDate                 : 2019:08:18 12:27:46
[Track1]        TrackID                         : 1
[Track1]        TrackDuration                   : 0:07:00
[Track1]        TrackLayer                      : 0
[Track1]        TrackVolume                     : 0.00%
[Track1]        MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[Track1]        ImageWidth                      : 2704
[Track1]        ImageHeight                     : 2624
[Track1]        TimeCode                        : 3
[Track1]        MediaHeaderVersion              : 0
[Track1]        MediaCreateDate                 : 2019:08:18 12:27:46
[Track1]        MediaModifyDate                 : 2019:08:18 12:27:46
[Track1]        MediaTimeScale                  : 30000
[Track1]        MediaDuration                   : 0:07:00
[Track1]        MediaLanguageCode               : eng
[Track1]        HandlerType                     : Video Track
[Track1]        HandlerDescription              : GoPro AVC
[Track1]        GraphicsMode                    : srcCopy
[Track1]        OpColor                         : 0 0 0
[Track1]        CompressorID                    : avc1
[Track1]        SourceImageWidth                : 2704
[Track1]        SourceImageHeight               : 2624
[Track1]        XResolution                     : 72
[Track1]        YResolution                     : 72
[Track1]        BitDepth                        : 24
[Track1]        VideoFrameRate                  : 29.97
[Track2]        TrackHeaderVersion              : 0
[Track2]        TrackCreateDate                 : 2019:08:18 12:27:46
[Track2]        TrackModifyDate                 : 2019:08:18 12:27:46
[Track2]        TrackID                         : 2
[Track2]        TrackDuration                   : 0:07:00
[Track2]        TrackLayer                      : 0
[Track2]        TrackVolume                     : 100.00%
[Track2]        MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[Track2]        MediaHeaderVersion              : 0
[Track2]        MediaCreateDate                 : 2019:08:18 12:27:46
[Track2]        MediaModifyDate                 : 2019:08:18 12:27:46
[Track2]        MediaTimeScale                  : 48000
[Track2]        MediaDuration                   : 0:07:00
[Track2]        MediaLanguageCode               : eng
[Track2]        HandlerType                     : Audio Track
[Track2]        HandlerDescription              : GoPro AAC
[Track2]        Balance                         : 0
[Track2]        AudioFormat                     : mp4a
[Track2]        AudioChannels                   : 2
[Track2]        AudioBitsPerSample              : 16
[Track2]        AudioSampleRate                 : 48000
[Track3]        TrackHeaderVersion              : 0
[Track3]        TrackCreateDate                 : 2019:08:18 12:27:46
[Track3]        TrackModifyDate                 : 2019:08:18 12:27:46
[Track3]        TrackID                         : 3
[Track3]        TrackDuration                   : 0:07:00
[Track3]        TrackLayer                      : 0
[Track3]        TrackVolume                     : 0.00%
[Track3]        MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[Track3]        MediaHeaderVersion              : 0
[Track3]        MediaCreateDate                 : 2019:08:18 12:27:46
[Track3]        MediaModifyDate                 : 2019:08:18 12:27:46
[Track3]        MediaTimeScale                  : 29
[Track3]        MediaDuration                   : 0:07:00
[Track3]        MediaLanguageCode               : eng
[Track3]        HandlerType                     : Time Code
[Track3]        HandlerDescription              : GoPro TCD
[Track3]        OtherFormat                     : tmcd
[Track4]        TrackHeaderVersion              : 0
[Track4]        TrackCreateDate                 : 2019:08:18 12:27:46
[Track4]        TrackModifyDate                 : 2019:08:18 12:27:46
[Track4]        TrackID                         : 4
[Track4]        TrackDuration                   : 0:07:00
[Track4]        TrackLayer                      : 0
[Track4]        TrackVolume                     : 0.00%
[Track4]        MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[Track4]        MediaHeaderVersion              : 0
[Track4]        MediaCreateDate                 : 2019:08:18 12:27:46
[Track4]        MediaModifyDate                 : 2019:08:18 12:27:46
[Track4]        MediaTimeScale                  : 1000
[Track4]        MediaDuration                   : 0:07:00
[Track4]        MediaLanguageCode               : eng
[Track4]        HandlerType                     : NRT Metadata
[Track4]        HandlerDescription              : GoPro MET
[Track4]        GenMediaVersion                 : 0
[Track4]        GenFlags                        : 0 0 0
[Track4]        GenGraphicsMode                 : ditherCopy
[Track4]        GenOpColor                      : 32768 32768 32768
[Track4]        GenBalance                      : 0
[Track4]        MetaFormat                      : gpmd
[Track4]        Warning                         : [minor] The ExtractEmbedded option may find more tags in the movie data
[Track5]        TrackHeaderVersion              : 0
[Track5]        TrackCreateDate                 : 2019:08:18 12:27:46
[Track5]        TrackModifyDate                 : 2019:08:18 12:27:46
[Track5]        TrackID                         : 5
[Track5]        TrackDuration                   : 0:07:00
[Track5]        TrackLayer                      : 0
[Track5]        TrackVolume                     : 0.00%
[Track5]        MatrixStructure                 : 1 0 0 0 1 0 0 0 1
[Track5]        MediaHeaderVersion              : 0
[Track5]        MediaCreateDate                 : 2019:08:18 12:27:46
[Track5]        MediaModifyDate                 : 2019:08:18 12:27:46
[Track5]        MediaTimeScale                  : 90000
[Track5]        MediaDuration                   : 0:07:00
[Track5]        MediaLanguageCode               : eng
[Track5]        HandlerType                     : NRT Metadata
[Track5]        HandlerDescription              : GoPro SOS
[Track5]        GenMediaVersion                 : 0
[Track5]        GenFlags                        : 0 0 0
[Track5]        GenGraphicsMode                 : ditherCopy
[Track5]        GenOpColor                      : 32768 32768 32768
[Track5]        GenBalance                      : 0
[Track5]        MetaFormat                      : gpmd
[ItemList]      Encoder                         : Lavf58.12.100
[Composite]     ImageSize                       : 2704x2624
[Composite]     Megapixels                      : 7.1
[Composite]     AvgBitrate                      : 50.4 Mbps
[Composite]     Rotation                        : 0

答案1

请后续读者注意 - ffmpeg 的新版本可能比旧版本更差,至少在 Windows 上是这样。

最新的 ffmpeg(4.2.1 及以上版本),在运行 Fusion 视频的命令时,例如:

ffmpeg -i GOPR5687.MP4 -map 0 -copy_unknown -map_metadata 0 \
-c copy -c:v h264 -crf 22 output.mp4

(或主题发起者提到的命令)给我这个:

Could not find tag for codec none in stream #2, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

我花了两天时间尝试破解它 :-/ 最后终于成功了。当我使用 4.0.2 版本时,一切开始正常(Windows 上的 32 和 64 版本均可用)。呼!!

此外,特别是对于 GoPRo 视频,处理程序名称存在启动 TAB 问题,如下所述: http://coderunner.io/how-to-compress-gopro-movies-and-keep-metadata/

答案2

我没有成功使用已经介绍的方法,但是如果有人只对在修改视频时复制元数据信息感兴趣(类似于图像),外置工具可用于:

exiftool -TagsFromFile from.mp4 to.mp4

相关内容