0

This is somewhat similar to this question, but a bit more complex. Using ffmpeg to copy metadata from one file to another

I have two videos.

  • Video 1 - original from camera with streams and metadata we need
  • Video 2 - retouched from After Effects which is now missing metadata and streams.

I want all non-video streams from Video 1 to be copied to a new video (everything other than the video stream 0). I want only the video stream of Video 2 (stream 0) be copied to a new file. I hope this makes sense.

I'm retouching the raw footage in After Effects and want to export this with all of the original metadata intact, so that I can import it into GoPro Fusion Studio to stabilize and stitch.

This is the full detail on the actual source file...or input 0...the raw footage.

  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

Edit: Updated per comments, and after days of tweaking. We are currently using this script to merge the two input files into a new file. Our goal and expectation was that after mapping the metadata and streams we would end up with a file that was nearly identical to the source video.

Here's the sh file we are using.

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

Here's the output after running this script:

  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% 

After the output, this is what ffmpeg shows for the newly generated 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

Using ExifTool, these are the details from the ffmpeg exported 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
  • The answer in question you linked should, with trivial modification, achieve what you want. Have you tried reading the documentation? What have you tried? Where did you fail? What commands do you think might work? – Mokubai Aug 25 '19 at 17:44
  • Indeed. I've been going through it like crazy today, otherwise I wouldn't be asking here. I'm not wrapping my head around the stream selection/mapping options unfortunately. I'm updating my original question with more detail. Good point. thanks. – ESB Aug 26 '19 at 0:17
  • Please show the full, uncut command line output of your ffmpeg command, and tell us what it does (i.e., what did you expect, what did you get). – slhck Aug 27 '19 at 7:58
  • Updated my original post above. – ESB Aug 28 '19 at 2:21
2

A note for the subsequent readers - newer versions of ffmpeg might be worse than olders, at least on Windows.

The latest ffmpeg (4.2.1 and nighly builds), when running commands for the Fusion videos, e.g. this:

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

(or a command mentioned by the topic starter) gives me this:

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

I've spent two days trying to crack it :-/ And finally I did. It all started to work when I used the version 4.0.2 (both 32 and 64 versions on Windows work). Phew!!

Also, specifically for GoPRo videos, there is a starter TAB problem for handler names, described here: http://coderunner.io/how-to-compress-gopro-movies-and-keep-metadata/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.