如何使用ffmpeg将WebM音频(Opus)和MP4视频(H.264)合并为一个MP4文件

时间:2020-05-13 14:31:11

标签: video ffmpeg

我正在尝试将带有Opus音频的WebM文件+带有H.264视频的MP4文件合并为一个MP4文件:

ffmpeg -i audio.webm -i video.mp4 -c copy output.mp4

但是,我得到一个错误:

[mp4 @ 0x56105a6d0a40] opus in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature

完整日志:

ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.3.0 (Arch Linux 9.3.0-1)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --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-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, matroska,webm, from 'audio.webm':
  Metadata:
    ENCODER         : Lavf58.29.100
  Duration: 00:00:10.01, start: -0.007000, bitrate: 106 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      ENCODER         : Lavc58.54.100 libopus
      DURATION        : 00:00:10.008000000
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:00:10.00, start: 0.000000, bitrate: 2796 kb/s
    Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2793 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
[mp4 @ 0x56105a6d0a40] track 1: codec frame size is not set
[mp4 @ 0x56105a6d0a40] opus in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature
Stream mapping:
  Stream #1:0 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
    Last message repeated 1 times

更新1

我尝试了以下命令:

ffmpeg -i audio.webm -i video.mp4 -c复制-strict实验output.mp4

但出现新错误:

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000225b1eb07c0]格式 仅以低分1检测到mov,mp4,m4a,3gp,3g2,mj2 可能会误检测! [mov,mp4,m4a,3gp,3g2,mj2 @ 00000225b1eb07c0] 找不到moov原子inputVideo.mp4:何时发现无效数据 处理输入


更新2

我发现我的输入视频已损坏,这导致Update 1中的错误。

因此,一旦我在Update 1中运行了命令,它确实为我提供了一个更大的mp4文件,但该文件仍然没有音频。

2 个答案:

答案 0 :(得分:3)

问题1:MP4中的作品

添加-strict -2(或别名-strict experimental),如日志中所述:

[mp4 @ 0x5630ee4eb000] opus in MP4 support is experimental, add '-strict -2' if you want to use it.

示例命令:

ffmpeg -i audio.webm -i video.mp4 -c copy -strict experimental output.mp4

但是,ffmpeg的较新版本不再认为MP4中的Opus具有实验性,因此,如果升级,则无需添加-strict

截至该答案的最新发布版本是4.2.2。使用git master分支中的版本,或等待4.3使用-strict跳过。


问题2:处理输入时发现无效数据

输入文件已损坏。不幸的是,ffmpeg对此无能为力。


问题3:没有音频

这表示您的播放器,浏览器或设备不支持MP4容器中的Opus音频。您需要将音频重新编码为AAC:

ffmpeg -i audio.webm -i video.mp4 -c copy -c:a aac output.mp4

答案 1 :(得分:0)

我找到了answer

ffmpeg -i video.mp4 -i audio.webm -c:v copy video480p.mp4

此外,如果您想重新编码音频

ffmpeg -i video.mp4 -i audio.webm -c:v copy -c:a aac video480p.mp4

作为一个初学者,我不知道-c:v是什么意思,所以我找到了说明所有内容的文档。 http://ffmpeg.org/ffmpeg-all.html#Stream-specifiers