[英]FFMPEG - Concating multiple clips produce corrupted output (freeze video, audio loss, lengthy duration)
I am trying to concat multiple clips using FFMPEG我正在尝试使用 FFMPEG 连接多个剪辑
My input videos have the following details:我的输入视频具有以下详细信息:
ffprobe version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2007-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:05:11.75, start: 0.000000, bitrate: 1338 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1204 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 11/09/2018.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
handler_name : ISO Media file produced by Google Inc. Created on: 11/09/2018.
ffprobe version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2007-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:05.62, start: 0.000000, bitrate: 2479 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1260x720 [SAR 1:1 DAR 7:4], 2376 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
I have tried 2 approaches but none seemed to work properly.我尝试了 2 种方法,但似乎没有一种方法可以正常工作。
Steps:脚步:
ffmpeg -i input1.mp4 -qscale:v 1 intermediate1.mpg
ffmpeg -i input2.mp4 -qscale:v 1 intermediate2.mpg
cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg
ffmpeg -i intermediate_all.mpg -qscale:v 2 output.mp4
Steps:脚步:
ffmpeg -i input1.mp4 -s hd720 -r 30000/1001 -video_track_timescale 30k -c:a copy input1-converted.mp4
ffmpeg -i input2.mp4 -s hd720 -r 30000/1001 -video_track_timescale 30k -c:a copy input2-converted.mp4
ffmpeg -f concat -safe 0 -i vidlist.txt -c copy output.mp4
One resultant clip with both inputs merged one after another with proper length(sum of inputs) and no video freeze/audio loss.具有两个输入的一个合成剪辑一个接一个地合并,具有适当的长度(输入总和)并且没有视频冻结/音频丢失。
One resultant clip with both inputs merged one after another with lengthy duration(more than the sum of inputs) and video freeze and sometimes audio loss as well.一个带有两个输入的合成剪辑一个接一个地合并,持续时间很长(超过输入的总和)和视频冻结,有时还会丢失音频。
Your inputs must have the same parameters, but yours vary in width, frame rate, timescale, audio sample rate, and audio channel layout.您的输入必须具有相同的参数,但您的输入在宽度、帧速率、时间刻度、音频采样率和音频通道布局方面有所不同。 Since
input1.mp4
is the main feature you can re-encode input2.mp4
to match the properties of input1.mp4
:由于
input1.mp4
是其主要特征,你可以重新编码input2.mp4
匹配的属性input1.mp4
:
ffmpeg -i input2.mp4 -filter_complex "[0:v]pad=1280:720:-1:-1,fps=30000/1001[v];[0:a]aformat=sample_rates=44100:channel_layouts=stereo[a]" -map "[v]" -map "[a]" input2b.mp4
Then use the concat demuxer to concatenate them.然后使用concat demuxer将它们连接起来。 Create
input.txt
:创建
input.txt
:
file 'input1.mp4'
file 'input2b.mp4'
Concatenate:连接:
ffmpeg -f concat -i input.txt -c copy output.mp4
This leaves input1.mp4
untouched: the process is faster, and preserves the quality of input1.mp4
.这使
input1.mp4
保持不变:该过程更快,并保留了input1.mp4
的质量。
Even better is to re-create a new input2.mp4
from the original source while setting the proper parameters.更好的是从原始源重新创建一个新的
input2.mp4
,同时设置适当的参数。 This will avoid generation loss from re-encoding a new file from it.这将避免从它重新编码一个新文件的代损失。
try this尝试这个
ffmpeg -i input1-converted.mp4 -i input2-converted.mp4 -filter_complex "concat=n=2:v=1:a=1" output.mp4
n=2 (inputs). n=2(输入)。
v=1: 1 video stream from each video. v=1:来自每个视频的 1 个视频流。
a=1 1 audio stream from each video. a=1 来自每个视频的 1 个音频流。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.