使用 ffmpeg 在网格中合并四个不同分辨率的视频

使用 ffmpeg 在网格中合并四个不同分辨率的视频

我想将四个视频合并成一个,如下所示。鉴于所有视频的分辨率相同,我已获得正确的输出。但是,分辨率不同时,我得到了不理想的结果。有关更多详细信息,请参阅下文。

我需要 ffmpeg 代码来将 4 个不同分辨率的视频合并成网格格式

ffmpeg.exe -i "1.avi" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=2.avi, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=4.avi, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"

上面的代码给出以下输出。

ffmpeg -i 1.avi

Input #0, avi, from '1.avi':
  Metadata:
    encoder         : Lavf55.44.100
  Duration: 00:00:03.10, start: 0.000000, bitrate: 773 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 640
x480 [SAR 1:1 DAR 4:3], 782 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified

ffmpeg-i 2.avi

Input #0, avi, from '2.avi':
  Metadata:
    encoder         : Lavf55.44.100
  Duration: 00:00:03.10, start: 0.000000, bitrate: 773 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 640
x480 [SAR 1:1 DAR 4:3], 782 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified

ffmpeg-i 3.avi

Input #0, avi, from '3.avi':
  Metadata:
    encoder         : Lavf55.44.100
  Duration: 00:00:03.10, start: 0.000000, bitrate: 699 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 640
x480 [SAR 1:1 DAR 4:3], 705 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified

ffmpeg-i 4.avi

Input #0, avi, from '4.avi':
  Metadata:
    encoder         : Lavf55.44.100
  Duration: 00:00:03.10, start: 0.000000, bitrate: 724 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p,          
640x480 [SAR 1:1 DAR 4:3], 731 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified

例如

但是当我旋转其中一个视频并合并它们时出现了问题。

ffmpeg -i 1.avi (480x640) 仅更改

Input #0, avi, from '1.avi':
Metadata:
encoder         : Lavf55.44.100
Duration: 00:00:03.10, start: 0.000000, bitrate: 961 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 
480x640 [SAR 1:1 DAR 3:4], 976 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
At least one output file must be specified

在此处输入图片描述

请告诉我需要改变什么才能获得期望的结果(如下所示)。 谢谢 在此处输入图片描述

答案1

考虑到视频是 640X480,旋转后的视频是 480X640,我搞清楚了。以下是四种情况。希望以后能帮到大家。:)

{文件编号}={角度}

1=90 2=0 3=0 4=0

ffmpeg.exe -i "1.avi" -vf "[in] scale=0:480 , pad=width=640+640:height=480:x=(640-480)/2:y=0:color=red [left];movie=2.avi, scale=640:480, pad=width=640:height=480:x=0:y=0:color=red [right]; [left][right] overlay=640:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=0:0 , pad=width=640+640:height=480:x=0:y=0:color=red [left];movie=4.avi, scale=0:0, pad=width=640:height=480:x=0:y=0:color=red [right]; [left][right] overlay=640:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"
Pause

2=0 1=90 3=0 4=0

ffmpeg.exe -i "2.avi" -vf "[in] scale=0:0 , pad=width=640+640:height=480:x=0:y=0:color=red [left];movie=1.avi, scale=0:480 , pad=width=640:height=480:x=(640-480)/2:y=0:color=red [right]; [left][right] overlay=640:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=4.avi, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"
Pause

90 90 0 0

ffmpeg.exe -i "2.avi" -vf "[in] scale=0:480 , pad=width=640+640:height=480:x=(640-480)/2:y=0:color=red [left];movie=1.avi, scale=0:480 , pad=width=640:height=480:x=(640-480)/2:y=0:color=red [right]; [left][right] overlay=640:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=iw:ih, pad=2*iw:ih [left];movie=4.avi, scale=iw:ih [right]; [left][right] overlay=main_w/2:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"
Pause

90 90 90 90

ffmpeg.exe -i "1.avi" -vf "[in] scale=0:0 , pad=width=480+480:height=640:x=0:y=0:color=red [left];movie=2.avi, scale=0:0 , pad=width=480:height=640:x=0:y=0:color=red [right]; [left][right] overlay=480:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=0:0 , pad=width=480+480:height=640:x=0:y=0:color=red [left];movie=4.avi, scale=0:0 , pad=width=480:height=640:x=0:y=0:color=red [right]; [left][right] overlay=480:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"
Pause

90 90 0 90

ffmpeg.exe -i "1.avi" -vf "[in] scale=0:0 , pad=width=480+480:height=640:x=0:y=0:color=red [left];movie=2.avi, scale=0:0 , pad=width=480:height=640:x=0:y=0:color=red [right]; [left][right] overlay=480:0 [out]" -b:v 768k "Output1.mp4"
ffmpeg.exe -i "3.avi" -vf "[in] scale=480:0 , pad=width=480+480:height=640:x=0:y=(640-480)/2:color=red [left];movie=4.avi, scale=0:0 , pad=width=480:height=640:x=0:y=0:color=red [right]; [left][right] overlay=480:0 [out]" -b:v 768k "Output2.mp4"
ffmpeg.exe -i "Output1.mp4" -vf "pad=iw:2*ih [top]; movie=Output2.mp4 [bottom]; [top][bottom] overlay=0:main_h/2" "Output_Stacked.mp4"
Pause

相关内容