简体   繁体   English

如何分割视频,然后使用ffmpeg连接回原始视频

[英]How to segment a video and then concatenate back into original one with ffmpeg

I am surveying on distributed video transcoding with FFmpeg. 我正在调查使用FFmpeg进行分布式视频转码。 I have found that there is a good script on https://github.com/nergdron/dve/blob/master/dve . 我发现https://github.com/nergdron/dve/blob/master/dve上有一个很好的脚本。

The script mainly uses the segment and concatenate filters of FFmpeg. 该脚本主要使用FFmpeg的segmentconcatenate过滤器。 I want to do a simple test first. 我想先做一个简单的测试。 However, I can not split the video into segments and then concatenate back to original video (with the same codec). 但是,我无法将视频拆分成段,然后连接回原始视频(使用相同的编解码器)。 I have tried with the following command: 我尝试过以下命令:

a. 一个。 Chunk the video 视频大块

ffmpeg -fflags +genpts -i Test.avi -map 0 -codec copy -f segment -segment_format avi -v error chunk-%03d.seg

b. Building the chunking list: 构建分块列表:

#!/bin/bash -e
set -e
echo "ffconcat version 1.0" > concat.txt
for f in `ls chunk-*.seg | sort`; do
echo "file $f" >> concat.txt
done

c. C。 Concatenate the chunks 连接块

ffmpeg  -y -v error -i concat.txt -f concat -map 0 -c copy -f avi output.avi

Then when I run ffprobe I get the following message which says it is a non-interleaved AVI: 然后,当我运行ffprobe我得到以下消息,表明它是一个非交错的AVI:

    ffprobe version N-82301-g1bbb18f Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --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-libschroedinger --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-decklink --enable-zlib
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
[avi @ 00000000028e3700] non-interleaved AVI
Input #0, avi, from 'output.avi':
  Metadata:
    encoder         : Lavf57.57.100
  Duration: 74:43:47.82, start: 0.000000, bitrate: 17 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x368 [SAR 1:1 DAR 40:23], 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 112 kb/s

I have tried a few other things without success. 我尝试过其他一些没有成功的事情。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance!! 提前致谢!!

The segment muxer, by default, preserves input timestamps. 默认情况下,段复用器会保留输入时间戳。 And the way that the concat demuxer works is that it adds the relative timestamp of incoming files to the net duration processed so far. concat demuxer工作的方式是它将传入文件的相对时间戳添加到目前为止处理的净持续时间。 eg If first file is 10 seconds, and second file is 5 seconds but with a start time of 10 seconds. 例如,如果第一个文件是10秒,第二个文件是5秒,但开始时间是10秒。 Then the first frame of the 2nd file in the output will have a timestamp of 20 seconds. 然后输出中第二个文件的第一帧将具有20秒的时间戳。 This, I believe, is leading to the AVI warning. 我相信这是导致AVI警告的原因。

Also keeping in mind that the segment muxer can create the concat list for you, use 另请注意,段复用器可以为您创建连续列表,请使用

ffmpeg -fflags +genpts -i Test.avi -map 0 -c copy -f segment -segment_format avi -segment_list Test.ffcat -reset_timestamps 1 -v error chunk-%03d.seg

and then 然后

ffmpeg -y -v error -i Test.ffcat -map 0 -c copy output.avi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM