Crop, Scale and Merge
I had record webcam to local files. Their resolution are 1280x720. I would like to merge them to be one 1920x1080 video. And position them to left and right.First, I have to crop their left and right areas. Only taking the middle of frame. Then I can scale and merge them.
Crop
The crop command looks like below:
ffmpeg -i input.mpg -filter_complex crop=in_w/2 -c:v libx264 output.ts
[Video filter - crop](http://www.ffmpeg.org/ffmpeg-all.html\#crop\)
Scale and Merge
The document <<Create a mosaic out of several input videos>> of FFmpeg teach me how to merge input videos.
[Create a mosaic out of several input videos](https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos\)
Combine above to make MPEG-TS
My final command is:
ffmpeg -i webcam.mpg -i webcam2.mpg -filter_complex "nullsrc=size=1920x1080 [base]; [0:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [left]; [1:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [right]; [base][left] overlay=shortest=1 [tmp1]; [tmp1][right] overlay=shortest=1:x=960" -c:v libx264 output.ts
First step is to create empty background.
nullsrc=size=1920x1080 [base];
Then crop and scale the input videos.
[0:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [left];
[1:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [right];
Put first input to left of background.
[base][left] overlay=shortest=1 [tmp1];
Put second input to right of background.
[tmp1][right] overlay=shortest=1:x=960
Finally, output it to the local file.
-c:v libx264 output.ts
Make playlist
I would like to output them to be HLS playlist.
ffmpeg -i webcam.mpg -i webcam2.mpg -filter_complex "nullsrc=size=1920x1080 [base]; [0:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [left]; [1:v] setpts=PTS-STARTPTS, crop=iw/2, scale=960x1080 [right]; [base][left] overlay=shortest=1 [tmp1]; [tmp1][right] overlay=shortest=1:x=960" -c:v libx264 -hls_flags append_list -hls_flags omit_endlist -start_number 0 -hls_allow_cache 0 -hls_segment_filename segment_%03d.ts live.m3u8
I only change the originaloutput.ts
to be:
-hls_flags append_list -hls_flags omit_endlist -start_number 0 -hls_allow_cache 0 -hls_segment_filename segment_%03d.ts live.m3u8