Python Forum
How to crop a video to 9:16?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to crop a video to 9:16?
#1
Hello everyone,

I am looking to crop my video that has a standard aspect ratio (1920x 1080) to a 9:16 aspect ratio (1080 x 1920).

I saw that there were several modules available but after spending two days trying to find a solution, nothing works for me. I must be making a mistake somewhere.

Would you have a module to recommend? I tried with FFmpeg but the documentation is unclear, I can't find my way around (I am a beginner).

Thanks a lot for your help!
Reply
#2
(May-13-2022, 07:34 PM)yschrs Wrote: Would you have a module to recommend? I tried with FFmpeg but the documentation is unclear, I can't find my way around (I am a beginner).
Would defiantly advice to use FFmpeg for this.
If i do a quick test.
ffmpeg -i david.mkv -vf scale=1080:920 -preset slow -crf 18 output2.mp4
Work fine this change aspect ratio from 1920x1080 to 1080x920 and this setting keep the quality high same as original.

If have problem with setup,post what the problem is.
Here is how the run look, using newest FFmpeg and i am using Windows here,work the same on all Platforms.
G:\1_youtube\youtube_env
λ ffmpeg -i david.mkv -vf scale=1080:920 -preset slow -crf 18 output2.mp4
ffmpeg version 2022-05-12-git-30e2bb0f64-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 11.3.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls -
-enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --
enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --
enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --
enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enab
le-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --
enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt
 --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-lib
gsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --e
nable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 28.100 / 59. 28.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 38.100 /  8. 38.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, matroska,webm, from 'david.mkv':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    ENCODER         : Lavf58.17.101
  Duration: 00:03:01.74, start: -0.007000, bitrate: 2600 kb/s
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:03:01.715000000
  Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
    Metadata:
      DURATION        : 00:03:01.741000000
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (opus (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000001c9e4707900] using SAR=368/243
[libx264 @ 000001c9e4707900] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 000001c9e4707900] profile High, level 3.2, 4:2:0, 8-bit
[libx264 @ 000001c9e4707900] 264 - core 164 r3094 bfc87b7 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1
 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_
pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyram
id=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=18.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output2.mp4':
  Metadata:
    COMPATIBLE_BRANDS: iso6avc1mp41
    MAJOR_BRAND     : dash
    MINOR_VERSION   : 0
    encoder         : Lavf59.23.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 1080x920 [SAR 368:243 DAR 16:9], q=2-31, 29.97 fps, 30k tbn (default)
    Metadata:
      HANDLER_NAME    : VideoHandler
      DURATION        : 00:03:01.715000000
      encoder         : Lavc59.28.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      DURATION        : 00:03:01.741000000
      encoder         : Lavc59.28.100 aac
frame= 5446 fps= 52 q=-1.0 Lsize=   70309kB time=00:03:01.74 bitrate=3169.1kbits/s speed=1.73x
video:67233kB audio:2883kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.275729%
[libx264 @ 000001c9e4707900] frame I:206   Avg QP:15.23  size: 35854
[libx264 @ 000001c9e4707900] frame P:1725  Avg QP:18.23  size: 18403
[libx264 @ 000001c9e4707900] frame B:3515  Avg QP:20.05  size:  8454
[libx264 @ 000001c9e4707900] consecutive B-frames: 10.4%  8.0%  8.0% 73.6%
[libx264 @ 000001c9e4707900] mb I  I16..4: 11.1% 75.5% 13.4%
[libx264 @ 000001c9e4707900] mb P  I16..4:  6.1% 31.7%  3.0%  P16..4: 21.3%  9.1%  2.6%  0.0%  0.0%    skip:26.1%
[libx264 @ 000001c9e4707900] mb B  I16..4:  1.0%  4.4%  0.5%  B16..8: 27.7%  8.4%  1.4%  direct: 3.8%  skip:52.8%  L0:45.5% L1:46.4% BI: 8.1%
[libx264 @ 000001c9e4707900] 8x8 transform intra:76.6% inter:80.3%
[libx264 @ 000001c9e4707900] direct mvs  spatial:99.7% temporal:0.3%
[libx264 @ 000001c9e4707900] coded y,uvDC,uvAC intra: 53.5% 0.1% 0.1% inter: 12.6% 0.0% 0.0%
[libx264 @ 000001c9e4707900] i16 v,h,dc,p: 40% 16%  5% 39%
[libx264 @ 000001c9e4707900] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 11% 11%  4%  6% 11%  5%  9%  5%
[libx264 @ 000001c9e4707900] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 12%  9%  5%  9% 12%  6%  7%  4%
[libx264 @ 000001c9e4707900] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 000001c9e4707900] Weighted P-Frames: Y:9.1% UV:0.2%
[libx264 @ 000001c9e4707900] ref P L0: 65.3%  8.8% 16.7%  5.0%  3.7%  0.5%  0.0%
[libx264 @ 000001c9e4707900] ref B L0: 86.0%  9.4%  3.7%  0.8%
[libx264 @ 000001c9e4707900] ref B L1: 97.5%  2.5%
[libx264 @ 000001c9e4707900] kb/s:3030.95
[aac @ 000001c9e44c00c0] Qavg: 641.690
yschrs likes this post
Reply
#3
If you really want to make your Python programme to do this of course go ahead! I'm sure you'll get there in the end. I wouldn't know how to do that.

But, if you just want to do things with videos, the command line can be cryptic, you might try Handbrake, which can do all kinds of things and has all kinds of options, in a nice window.

Not being a Windoze user, I don't know if there is a Windoze version of Handbrake. But I know Handbrake is fantastic!
yschrs likes this post
Reply
#4
Thank you so much for your answers, I will experiment with all of this :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to crop eyes/nose/mouth in the face only? [OpenCV] buzzdarkyear 0 2,187 Jan-11-2022, 01:41 PM
Last Post: buzzdarkyear
  Crop Image to Bounding Box Coordinates sallyjc81 2 5,095 Jul-23-2020, 08:46 AM
Last Post: sallyjc81

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020