preface

I recently had a requirement to test a video service interface with a very large video to see if the resulting response times out. However, there is only a 2GB movie file on the local PC. How to quickly generate a 10GB video file?

Video stitching

FFmpeg is a set of open source programs for recording, converting, and streaming digital audio and video. This article introduces FFmpeg official recommendation of three video splicing methods.

  1. Concat Demuxer: Concatenation based on Demuxer requires the same properties of video and audio streams. This method does not decode and encode video and audio streams, so it is fast and recommended to use this method.
ffmpeg -f concat -safe 0 -i filelist.txt -c copy yeqiongzhou.mp4
filelist.txt: file 'test1.mp4'
              file 'test1.mp4'
	      file 'test2.mp4'
	      file 'test2.mp4'Using this command, you can create a large video file from the local test1.mp4 and test2.mp4 files. Tips: For relative paths, the -safe 0 above is not required.Copy the code
  1. Concat Protocol: This approach operates based on files, some files (such as MPEG-2 Transport Streams), which is similar to using cat on Linux systems or copying on Windows.

ffmpeg -i “concat:test1.mp4|test2.mp4|test3.mp4” -c copy yeqiongzhou.mp4

  1. Concat filter: This method is actually all the video and audio decoding, unified into the original audio and video stream, and then inserted into the encoder for recoding. This method requires the resolution and frame rate between videos must be consistent, the advantage is good compatibility, can cope with most of the scene.
ffmpeg -i test1.mp4 -i test2.webm -i test3.mov \
-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]"Yeqiongzhou.mkv Through the above command we merged three files with video streams and audio streams.Copy the code