`ffmpeg` 无法识别通过 concat 解复用器合并 mp4 的管道输入

`ffmpeg` 无法识别通过 concat 解复用器合并 mp4 的管道输入

我想通过 concat 解复用器合并 mp4 文件,但无法使用脚本来工作。

我正在使用另一个 AskUbuntu 答案中的脚本,名为concatmp4

#!/usr/bin/env bash

if [ $# -lt 1 ]; then
    echo "Usage: `basename $0` input_1.mp4 input_2.mp4 ... output.mp4"
    exit 0
fi

ARGS=("$@") # determine all arguments
output=${ARGS[${#ARGS[@]}-1]} # get the last argument (output file)
unset ARGS[${#ARGS[@]}-1] # drop it from the array
(for f in "${ARGS[@]}"; do echo "file '$f'"; done) | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -vcodec copy -acodec copy $output

然而,当我在 mp4 文件上运行它时,我总是得到

$ concatmp4 Itazuraguma_no_Gloomy_01.mp4 Itazuraguma_no_Gloomy_02.mp4 test.mp4
ffmpeg version 4.4-6ubuntu5 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-7ubuntu1)
  configuration: --prefix=/usr --extra-version=6ubuntu5 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55f2ed650200] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x55f2ed650200] moov atom not found
[concat @ 0x55f2ed63e440] Impossible to open 'pipe:Itazuraguma_no_Gloomy_01.mp4'
pipe:: Invalid data found when processing input

当我将脚本的最后一行修改为(for f in "${ARGS[@]}"; do echo "file '$f'"; done) > input.text,然后ffmpeg -f concat -i input.text -c copy output.mp4从命令行运行时,它起作用了 (!)。需要澄清的是,当我-c copy在脚本中使用时,错误是一样的。

当脚本通过临时文件运行时它也有效:

... # lines after the 'unset' line in the original:
tmpfile="${output%.mp4}.tmp"
(for f in "${ARGS[@]}"; do echo "file '$f'"; done) > "$tmpfile"
ffmpeg -f concat -safe 0 -i "$tmpfile" -c copy "$output"
rm "$tmpfile"

要使脚本运行需要什么?

答案1

根据 的 bug tracker ffmpeg,新版本中有一些变化。自 4.2.2 和 4.3.2 之间的发布以来,相对 URL 的处理已得到修复,以使其与官方建议兼容。

如果 concat 脚本中有裸文件名,则文件应该与脚本位于同一目录(当然还有协议)中。当然,这对于 pipe: 来说是不可能的,但仍然适用。如果脚本保存在临时文件中,则其协议将更改为“文件”,并且由于该更改,旧方法将起作用。

管道输入需要在 concat 代码中同时指定 concatfile和协议file:

现在的例子通过协议需要输入pipefile file:'input_01.mp4'而不是旧的file 'input_01.mp4'

新版本的脚本需要改为

#!/usr/bin/env bash

if [ $# -lt 1 ]; then
    echo "Usage: `basename $0` input_1.mp4 input_2.mp4 ... output.mp4"
    exit 0
fi

ARGS=("$@") # determine all arguments
output=${ARGS[${#ARGS[@]}-1]} # get the last argument (output file)
unset ARGS[${#ARGS[@]}-1] # drop it from the array
(for f in "${ARGS[@]}"; do echo "file file:'$f'"; done) | ffmpeg -protocol_whitelist file,pipe -f concat -safe 0 -i pipe: -c:v copy -c:a copy $output

上班。

相关内容