如何分割视频,然后使用 ffmpeg 连接回原始视频 [英] How to segment a video and then concatenate back into original one with ffmpeg

查看:27
本文介绍了如何分割视频,然后使用 ffmpeg 连接回原始视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调查使用 FFmpeg 的分布式视频转码.我发现 https://github.com/nergdron/dve 上有一个很好的脚本/blob/master/dve.

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.

脚本主要使用FFmpeg的segmentconcatenate过滤器.我想先做一个简单的测试.但是,我无法将视频拆分为多个片段,然后再连接回原始视频(使用相同的编解码器).我已尝试使用以下命令:

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:

一个.分块视频

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 version 1.0" > concat.txt
for f in `ls chunk-*.seg | sort`; do
echo "file $f" >> concat.txt
done

c.连接块

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

然后,当我运行 ffprobe 时,我收到以下消息,指出它是非交错 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!!

推荐答案

默认情况下,段复用器会保留输入时间戳.concat demuxer 的工作方式是将传入文件的相对时间戳添加到目前处理的净持续时间.例如如果第一个文件是 10 秒,第二个文件是 5 秒,但开始时间为 10 秒.然后输出中第二个文件的第一帧将具有 20 秒的时间戳.我相信,这会导致 AVI 警告.

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

然后

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

这篇关于如何分割视频,然后使用 ffmpeg 连接回原始视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆