How to make my video in landscape mode using ffmpeg

为君一笑 提交于 2019-12-24 18:14:12

问题


I have four video chats. Somehow I have managed to cut videos into pieces, stored in array then stacked and finally concat the video which is in the youtube link down below. I have used the size in the portrait view is 640*480. But I need to show them in the landscape. Suggest me any ideas.

Landscape view: https://youtu.be/u8tmL2-CdK0 Portrait view: https://youtu.be/lO-Q3I9X8OA

These are my inputs

Input #0, matroska,webm, from 'PA473fbf06ed1f952f95c88b9cf22ed0ba_pre.mkv': Metadata: encoder : GStreamer matroskamux version 1.8.1.1 creation_time : 2019-11-05T06:08:19.000000Z Duration: 00:01:05.50, start: 63.041000, bitrate: 30 kb/s Stream #0:0(eng): Video: h264 (Baseline), yuvj420p(pc, progressive), 360x480, SAR 1:1 DAR 3:4, 15 tbr, 1k tbn, 2k tbc (default) Metadata: title : Video Input #1, matroska,webm, from 'PA183db0ed986039de3197092103a411eb_pre.mkv': Metadata: encoder : GStreamer matroskamux version 1.8.1.1 creation_time : 2019-11-05T06:07:20.000000Z Duration: 00:03:15.14, start: 4.062000, bitrate: 172 kb/s Stream #1:0(eng): Video: h264 (Baseline), yuvj420p(pc, progressive), 360x480, SAR 1:1 DAR 3:4, 15 fps, 15 tbr, 1k tbn, 2k tbc (default) Metadata: title : Video Input #2, matroska,webm, from 'PA62a810038cbcc00be21fac43e98f5ee1_pre.mkv': Metadata: encoder : GStreamer matroskamux version 1.8.1.1 creation_time : 2019-11-05T06:07:45.000000Z Duration: 00:02:21.71, start: 28.803000, bitrate: 92 kb/s Stream #2:0(eng): Video: h264 (Baseline), yuvj420p(pc, progressive), 360x480, SAR 1:1 DAR 3:4, 15 tbr, 1k tbn, 2k tbc (default) Metadata: title : Video Input #3, matroska,webm, from 'PA8fa44ff1ba37ee510a045198bca6f04a_pre.mkv': Metadata: encoder : GStreamer matroskamux version 1.8.1.1 creation_time : 2019-11-05T06:07:48.000000Z Duration: 00:01:50.69, start: 32.318000, bitrate: 28 kb/s Stream #3:0(eng): Video: h264 (Baseline), yuvj420p(pc, progressive), 360x480, SAR 1:1 DAR 3:4, 15 fps, 15 tbr, 1k tbn, 2k tbc (default) Metadata: title : Video

At first, I change all the video resolution to 640:480 because each video may have different resolution (probability). So I am setting a fixed resolution.

ffmpeg -i PA8fa44ff1ba37ee510a045198bca6f04a_pre.mkv -vf scale=640:480 PA8fa44ff1ba37ee510a045198bca6f04a.mkv -hide_banner Input #0, matroska,webm, from PA8fa44ff1ba37ee510a045198bca6f04a_pre.mkv': Metadata: encoder : GStreamer matroskamux version 1.8.1.1 creation_time : 2019-11-05T06:07:48.000000Z Duration: 00:01:50.69, start: 32.318000, bitrate: 28 kb/s Stream #0:0(eng): Video: h264 (Baseline), yuvj420p(pc, progressive), 360x480, SAR 1:1 DAR 3:4, 15 fps, 15 tbr, 1k tbn, 2k tbc (default) Metadata: title : Video Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Press [q] to stop, [?] for help [swscaler @ 0000021d72eb3f80] deprecated pixel format used, make sure you did set range correctly [libx264 @ 0000021d72b33b40] using SAR=9/16 [libx264 @ 0000021d72b33b40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX [libx264 @ 0000021d72b33b40] profile High, level 2.2, 4:2:0, 8-bit [libx264 @ 0000021d72b33b40] 264 - core 158 r2984 3759fcb - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, matroska, to 'PA8fa44ff1ba37ee510a045198bca6f04a.mkv': Metadata: encoder : Lavf58.32.104 Stream #0:0(eng): Video: h264 (libx264) (H264 / 0x34363248), yuvj420p(pc), 640x480 [SAR 9:16 DAR 3:4], q=-1--1, 15 fps, 1k tbn, 15 tbc (default) Metadata: title : Video encoder : Lavc58.56.101 libx264

Two videos merging command

ffmpeg -i ddb97d85-fc21-4fb4-8062-ca2084a48aeb.mkv -i a8665a5f-fb5e-44cb-a072-070fbe07a14f.mkv -filter_complex "[0:v][1:v]hstack" 1572934056.mkv

Three videos merging command

ffmpeg -i 16f90447-c8b6-4077-b3b6-4fb2c07e19b5.mkv -i ef501109-0ee9-4924-8de1-65eb796a4a78.mkv -i 0b284aa6-4175-472c-aaf6-837412f97f32.mkv -filter_complex "[1:v]scale=320:-1[left]; [2:v]scale=320:-1[right]; [left][right]hstack[bottom]; [0:v][bottom]vstack" 1572934058.mkv

Concat Command

ffmpeg -i 1572934031.mkv -i 1572934056.mkv -i 1572934058.mkv -i 1572934089.mkv -i 1572934155.mkv -i 1572934169.mkv -i 1572934198.mkv -filter_complex "[0]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[0v];[1]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[1v];[2]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[2v];[3]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[3v];[4]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[4v];[5]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[5v];[6]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,fps=fps=30,setsar=1[6v];[0v][1v][2v][3v][4v][5v][6v]concat=n=7:v=1:a=0[v]" -map "[v]" 4c21f002fa76b148c00cc6fbceaa57ee.mp4


回答1:


No need to pre-process. Do it all in one command. Assuming desired output size is 1280x960:

ffmpeg \
-i left-1.mkv -i right-1.mkv \
-i topleft-2.mkv -i topright-2.mkv -i bottom-2.mkv \
-filter_complex \
"[0]scale=640:480:force_original_aspect_ratio=decrease,pad=640:960:(ow-iw)/2:(oh-ih)/2,setsar=1[left1];
 [1]scale=640:480:force_original_aspect_ratio=decrease,pad=640:960:(ow-iw)/2:(oh-ih)/2,setsar=1[right1];
 [left1][right1]hstack=inputs=2[set1];
 [2]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[topleft2];
 [3]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1[topright2];
 [4]scale=640:480:force_original_aspect_ratio=decrease,pad=1280:480:(ow-iw)/2:(oh-ih)/2,setsar=1[bottom2];
 [topleft2][topright2][bottom2]xstack=inputs=3:layout=0_0|w0_0|0_h0[set2];
 [set1][set2]concat=n=2:v=1:a=0[v]" \
-map "[v]" output.mp4


来源:https://stackoverflow.com/questions/58727172/how-to-make-my-video-in-landscape-mode-using-ffmpeg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!