如何使用ffmpeg复制流并保留格式和元数据?

5
我有两个文件,每个文件都有多个流。
Output.mp4 文件有 2 条流:视频和音频(流0,1)。
Input.mp4 文件有 3 条流:视频、音频和数据(流0,1,2)。
我需要将 Input.mp4 文件的第 2 条流添加到 Output.mp4 文件中,生成 Final.mov 文件。
我尝试了以下命令,但好像无法保留添加的流的格式和元数据:
ffmpeg -y -i Output.mp4 -i Input.mp4 -c copy -map 0:0 -map 0:1 -map 1:2 Final.mov

从ffmpeg的输出结果看,它似乎正在工作,但是Final.mov中流的格式和元数据不正确。

我需要帮助修改命令使其正常工作。

谢谢!

以下是命令输出:

ffmpeg -y -i Output.mp4 -i Input.mp4 -c copy -map 0:0 -map 0:1 -map 1:2 Final.mov

ffmpeg version N-84679-gd65b595 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 51.100 / 55. 51.100
  libavcodec     57. 86.103 / 57. 86.103
  libavformat    57. 67.100 / 57. 67.100
  libavdevice    57.  3.101 / 57.  3.101
  libavfilter     6. 78.100 /  6. 78.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2018-04-15T21:57:13.000000Z
  Duration: 00:24:25.05, start: 0.000000, bitrate: 3571 kb/s
    Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 7680x3840 [SAR 1:1 DAR 2:1], 3252 kb/s, 1 fps, 1 tbr, 100k tbn, 2.15 tbc (default)
    Metadata:
      creation_time   : 2018-04-15T21:57:13.000000Z
      handler_name    : Alias Data Handler
      encoder         : HEVC Coding
    Side data:
      stereo3d: 2D
      spherical: equirectangular (0.000000/0.000000/0.000000)
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2018-04-15T21:57:13.000000Z
      handler_name    : Alias Data Handler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'Input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    creation_time   : 2018-04-12T12:02:32.000000Z
    make            : Insta360
    model           : Insta360 Pro
    encoder         : Lavf57.71.100
    description     : {"info":{"gyro_stabilized":false,"initial_view_changed":false}}
  Duration: 00:24:25.00, start: -0.004233, bitrate: 6394 kb/s
    Stream #1:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv), 7680x3840, 6196 kb/s, 1 fps, 1 tbr, 360k tbn, 5 tbc (default)
    Metadata:
      creation_time   : 2018-04-12T12:02:32.000000Z
      handler_name    : VideoHandler
    Side data:
      stereo3d: 2D
      spherical: equirectangular (0.000000/0.000000/0.000000)
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 4.0, fltp, 129 kb/s (default)
    Metadata:
      creation_time   : 2018-04-12T12:02:32.000000Z
      handler_name    : SoundHandler
    Stream #1:2(und): Data: none (camm / 0x6D6D6163), 36 kb/s
    Metadata:
      creation_time   : 2018-04-12T12:02:32.000000Z
      handler_name    : CameraMetadataMotionHandler
Output #0, mov, to 'Final.mov':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf57.67.100
    Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 7680x3840 [SAR 1:1 DAR 2:1], q=2-31, 3252 kb/s, 1 fps, 1 tbr, 100k tbn, 100k tbc (default)
    Metadata:
      creation_time   : 2018-04-15T21:57:13.000000Z
      handler_name    : Alias Data Handler
      encoder         : HEVC Coding
    Side data:
      stereo3d: 2D
      spherical: equirectangular (0.000000/0.000000/0.000000)
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2018-04-15T21:57:13.000000Z
      handler_name    : Alias Data Handler
    Stream #0:2(und): Data: none (camm / 0x6D6D6163), 36 kb/s
    Metadata:
      creation_time   : 2018-04-12T12:02:32.000000Z
      handler_name    : CameraMetadataMotionHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #1:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[mov @ 0000000004894f00] Unknown hldr_type for camm / 0x6D6D6163, writing dummy valuesd= 629x
frame= 1465 fps=625 q=-1.0 Lsize=  650825kB time=00:24:24.98 bitrate=3639.3kbits/s speed= 625x
video:581593kB audio:56757kB subtitle:0kB other streams:6602kB global headers:0kB muxing overhead: 0.910633%

以下是Final.mp4文件中的流:

ffmpeg -i Final.mov

ffmpeg version N-84679-gd65b595 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 51.100 / 55. 51.100
  libavcodec     57. 86.103 / 57. 86.103
  libavformat    57. 67.100 / 57. 67.100
  libavdevice    57.  3.101 / 57.  3.101
  libavfilter     6. 78.100 /  6. 78.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000000002726860] overread end of atom 'stsd' by 2974416 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Final.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.67.100
  Duration: 00:24:25.00, start: 0.000000, bitrate: 3639 kb/s
    Stream #0:0(eng): Video: hevc (Main) (hvc1 / 0x31637668), yuvj420p(pc, bt709), 7680x3840 [SAR 1:1 DAR 2:1], 3252 kb/s, 1 fps, 1 tbr, 100k tbn, 2.15 tbc (default)
    Metadata:
      handler_name    : DataHandler
      encoder         : HEVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      handler_name    : DataHandler
    Stream #0:2(eng): Data: none (stts / 0x73747473), 36 kb/s
    Metadata:
      handler_name    : DataHandler

看起来它不喜欢你的流1:2 对于camm / 0x6D6D6163,写入虚拟值,尽管你已经指定了复制。 - undefined
是的。该流是Google街景所需的视频中的GPS数据。有没有办法解决这个问题? - undefined
1个回答

0
还有一个问题是索尼视频(h264和h265编码文件,源自ILCE-7M4)也遇到了同样的问题:MP4文件包含实时元数据(rtmd),ffmpeg不允许直接复制(非常严格)。MP4Box可以为您完成此操作,因此您不一定需要将容器“移动”到MOV或M4V。在下面的示例中,我使用苹果的AAC编码器和特定比特率(!= CRF)进行了两次转换:
ffmpeg -y -i "${INPUTFILE}" -c:v libx265 -b:v 35000k -x265-params pass=1 -an -f null /dev/null && \
ffmpeg -i "${INPUTFILE}" -c:v libx265 -b:v 35000k -x265-params pass=2 -c:a aac_at -b:a 192k -movflags use_metadata_tags+faststart -map_metadata 0 -tag:v hvc1 "${OUTPUTFILE}"
MP4Box -add ${INPUTFILE}#3 ${OUTPUTFILE}
MP4Box -dump-xml ${INPUTFILE}.xml ${INPUTFILE}
MP4Box -set-meta META -set-xml ${INPUTFILE}.xml ${OUTPUTFILE} 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接