如何分割视频,然后用ffmpeg连接成原来的 [英] How to segment a video and then concatenate back into original one with ffmpeg
问题描述
脚本主要使用段
和 concatenate
过滤器的FFmpeg。我想先做一个简单的测试。但是,我无法将视频分割成段,然后连接到原始视频(使用相同的编解码器)。我已尝试使用以下命令:
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。构建分块列表:
#!/ bin / bash -e
set -e
echo ffconcat版本1.0> `ls chunk - *。seg |中的f的concat.txt
sort`; do
echofile $ f>> concat.txt
done
c。连接块
ffmpeg -y -v error -i concat.txt -f concat -map 0 -c copy -f avi output.avi
然后当我运行 ffprobe
我得到以下消息说它是一个非交错的AVI:
ffprobe版本N-82301-g1bbb18f版权所有(c) 2007-2016 FFmpeg开发人员
用gcc 5.4.0(GCC)
配置:--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-libsnap py --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]交织AVI
输入#0,avi,来自'output.avi':
元数据:
编码器:Lavf57.57.100
持续时间:74:43:47.82,开始:0.000000,比特率:17 kb / s
流#0:0:视频:mpeg4(高级简单配置文件)(XVID / 0x44495658),yuv420p,64 0x368 [SAR 1:1 DAR 40:23],23.98 fps,23.98 tbr,23.98 tbn,23.98 tbc
流#0:1:音频:mp3(U [0] [0] [0] / 0x0055) ,48000 Hz,stereo,s16p,112 kb / s
我没有成功尝试过其他一些事情。任何帮助将不胜感激。提前致谢!!
默认情况下,段Muxer保留输入时间戳。并且concat demuxer的工作方式是将传入文件的相对时间戳添加到目前为止处理的净持续时间。例如如果第一个文件是10秒,第二个文件是5秒,但开始时间是10秒。然后,输出中第二个文件的第一帧将具有20秒的时间戳。这个我相信导致AVI警告。
还要记住,段MUXER可以为您创建连接列表,使用
ffmpeg -fflags + genpts -i Test.avi -map 0 -c copy -f segment -segment_format avi -segment_list Test.ffcat -reset_timestamps 1 -v错误chunk-%03d.seg
然后
ffmpeg -y -v error -i Test.ffcat -map 0 -c copy output.avi
I am surveying on distributed video transcoding with FFmpeg. I have found that there is a good script on https://github.com/nergdron/dve/blob/master/dve.
The script mainly uses the segment
and concatenate
filters of FFmpeg. 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. 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 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. e.g. If first file is 10 seconds, and second file is 5 seconds but with a start time of 10 seconds. Then the first frame of the 2nd file in the output will have a timestamp of 20 seconds. This, I believe, is leading to the AVI warning.
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
这篇关于如何分割视频,然后用ffmpeg连接成原来的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!