Search code examples
videoffmpeg

FFMPEG Merge two videos into one with side-by-side same quality output


I'm already working on project with 3d video and I have a problem, I got left and right channel of video and I need to merge them into side by side. I already read some blogs about this problem and I got this code:

ffmpeg -i avatar35l.avi -vf "movie=avatar35r.avi [in1]; [in]pad=1920*2:1080[in0]; [in0][in1] overlay=1920:0 [out]" avatar35sbs.avi

It works, but there is significant quality loss and I need the quality of the output video to be the same as the input video: 30fps, 1080p, same length. I'm new to ffmpeg and i need a concrete example of that.

Can anybody help me?


Solution

  • Lossless

    You'll have to use a truly lossless format if you require "a quality of output video same as input video". Example for ffv1 using the hstack filter instead of movie+pad+overlay:

    ffmpeg -i left.avi -i right.avi -filter_complex hstack -c:v ffv1 output.avi
    

    FFmpeg supports several additional lossless compressed formats such as:

    • lossless H.264: -c:v libx264 -crf 0
    • huffyuv: -c:v huffyuv
    • ffvhuff: -c:v ffvhuff
    • UT Video: -c:v utvideo
    • And of course lossless uncompressed formats including rawvideo.

    Since it is lossless the output file will be huge, and your player or device will probably not like it.

    Visually lossless

    Of course what you may actually want is "lossy, yet 'visually lossless', but not a gigantic, huge file like true lossless provides". In that case use:

    ffmpeg -i left.avi -i right.avi -filter_complex "hstack,format=yuv420p" -c:v libx264 -crf 18 output.mp4
    

    You didn't mention audio. If you want to merge the audio from each input as well use the amerge filter:

    ffmpeg -i left.avi -i right.avi -filter_complex "[0:v][1:v]hstack,format=yuv420p[v];[0:a][1:a]amerge[a]" -map "[v]" -map "[a]" -c:v libx264 -crf 18 -ac 2 output.mp4
    

    See FFmpeg Wiki: H.264 Video Encoding.