I am working on a hobby project using Pi 3. I have bunch of videos (approx 4-5 min long) recorded from Pi camera. Now, I want to cut each video (6-7 seconds) and then want to stitch them back to back. How to do this ?
You can use the concat demuxer to do this without needing to re-encode.
First make a text file:
file '/path/to/video_01.mp4' inpoint 30 outpoint 35 file '/path/to/video_02.mp4' inpoint 2 outpoint 6 file '/path/to/video_03.mp4' inpoint 128 outpoint 142 file '/path/to/video_04.mp4' inpoint 48 outpoint 51 file '/path/to/video_05.mp4' inpoint 180 outpoint 200 file '/path/to/video_06.mp4' inpoint 0 outpoint 8
ffmpeg -f concat -i input.txt -c copy output.mp4
Note that all segments must be the same format, width x height, frame rate, etc. If they differ see the next method below.
The in and out points may not be accurate unless your inputs are intra-frame codecs (if you are unsure they probably are not). See the
outputdocumentation for details. If frame accuracy is required see the method below.
ffmpeg -i input0 -i input1 -i input2 -i input3 -i input4 -i input5 \ -filter_complex \ "[0:v]trim=3:9,scale=1280:720,setpts=PTS-STARTPTS[v0]; \ [1:v]trim=30:36,setpts=PTS-STARTPTS[v1]; \ [2:v]trim=5:12,setpts=PTS-STARTPTS[v2]; \ [3:v]trim=46:56,scale=1280:720,setpts=PTS-STARTPTS[v3]; \ [4:v]trim=2:19,setpts=PTS-STARTPTS[v4]; \ [5:v]trim=128:166,setpts=PTS-STARTPTS[v5]; \ [v0][v1][v2][v3][v4][v5]concat=n=6:v=1:a=0[v]" -map "[v]" -c:v h264_omx output.mp4
Filtering will require re-encoding. This example uses the encoder
h264_omxwhich utilizes OpenMAX IL hardware to encode. If your
ffmpegdoes not support this, and you want to use it, then see FFmpeg hardware acceleration on Raspberry PI.
You didn't mention audio, so I assumed there was none. If you need it add the atrim filter, adjust the concat
avalue, and add the proper