Videos shot on mobile often huge in size, because they cam set to high resolution. Of course most of the cases those settings were intentional but my motive is to help people who wanted to reduce the size of a video, whether it is shot on mobile or a movie file.
Let me share my experience, I shot a video of my nephew's school event which is 30 min long, later I noticed my mobile was dying without space. I found the video clip was huge it's 2.2 GB, I couldn't figure out that, even a 2-hour movie doesn't exceed 1 Gb with 720p. I want the video but not at the cost of 2.2Gb. So I wanted to compress the video, sorry sorry, not compress reduce the size, hope you figured out the difference.
Lots of online websites I found on google say that help me, but I don't want to upload my video. I'm going to use a command-line tool called FFmpeg. It's a huge framework with tons of options, what we do is not even 1% of its capacity. You can read more at https://ffmpeg.org/about.html.
Installation:
brew install ffmpeg on mac
you can download FFmpeg for other OS from official download here https://ffmpeg.org/download.html
Usage:
Specifications of video I'm using for tutorial.
Shot on mobile at 1080p
Duration 1 Min
Size 116Mb
I want to reduce its resolution to 720p and 480p to see how much I reduce the size and how good video quality is preserved.
disclaimer: it's the reader's responsibility to take a backup of your original video clip before following this tutorial, you could end up overwriting/corrupting the original clip if something goes wrong.
720p
gil@localhost# ffmpeg -i ~/Desktop/116MB.mp4 -s 1280x720 /tmp/hd720.mp4
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/gil/Desktop/116MB.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2021-05-30T06:03:44.000000Z
com.android.version: 10
Duration: 00:01:00.39, start: 0.000000, bitrate: 15393 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1080x2340, 15195 kb/s, SAR 1:1 DAR 6:13, 47.32 fps, 60 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 192 kb/s (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7f8bbd02be00] using SAR=27/104
[libx264 @ 0x7f8bbd02be00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f8bbd02be00] profile High, level 3.2, 4:2:0, 8-bit
[libx264 @ 0x7f8bbd02be00] 264 - core 161 r3049 55d517b - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=25 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, mp4, to '/tmp/hd720.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
com.android.version: 10
encoder : Lavf58.76.100
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m, progressive), 1280x720 [SAR 27:104 DAR 6:13], q=2-31, 60 fps, 15360 tbn (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
encoder : Lavc58.134.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, mono, fltp, 69 kb/s (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 aac
frame= 3624 fps= 49 q=-1.0 Lsize= 9216kB time=00:01:00.35 bitrate=1251.0kbits/s dup=766 drop=0 speed=0.823x
video:9111kB audio:11kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.028394%
[libx264 @ 0x7f8bbd02be00] frame I:18 Avg QP:20.63 size: 51692
[libx264 @ 0x7f8bbd02be00] frame P:1129 Avg QP:21.59 size: 6286
[libx264 @ 0x7f8bbd02be00] frame B:2477 Avg QP:20.21 size: 525
[libx264 @ 0x7f8bbd02be00] consecutive B-frames: 6.2% 5.7% 7.4% 80.8%
[libx264 @ 0x7f8bbd02be00] mb I I16..4: 30.0% 36.2% 33.9%
[libx264 @ 0x7f8bbd02be00] mb P I16..4: 4.8% 3.1% 1.5% P16..4: 11.3% 3.4% 2.1% 0.0% 0.0% skip:73.8%
[libx264 @ 0x7f8bbd02be00] mb B I16..4: 0.4% 0.2% 0.0% B16..8: 7.8% 0.4% 0.0% direct: 0.3% skip:90.9% L0:50.2% L1:46.0% BI: 3.8%
[libx264 @ 0x7f8bbd02be00] 8x8 transform intra:32.7% inter:49.7%
[libx264 @ 0x7f8bbd02be00] coded y,uvDC,uvAC intra: 14.9% 17.9% 9.9% inter: 2.3% 1.6% 0.5%
[libx264 @ 0x7f8bbd02be00] i16 v,h,dc,p: 18% 79% 2% 1%
[libx264 @ 0x7f8bbd02be00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 25% 54% 1% 1% 0% 2% 0% 2%
[libx264 @ 0x7f8bbd02be00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 48% 19% 1% 2% 1% 5% 1% 5%
[libx264 @ 0x7f8bbd02be00] i8c dc,h,v,p: 62% 33% 4% 1%
[libx264 @ 0x7f8bbd02be00] Weighted P-Frames: Y:1.9% UV:1.6%
[libx264 @ 0x7f8bbd02be00] ref P L0: 62.0% 9.4% 16.7% 11.9% 0.1%
[libx264 @ 0x7f8bbd02be00] ref B L0: 69.9% 23.9% 6.2%
[libx264 @ 0x7f8bbd02be00] ref B L1: 95.0% 5.0%
[libx264 @ 0x7f8bbd02be00] kb/s:1235.58
[aac @ 0x7f8bbd02d600] Qavg: 65521.922
480p
git@localhost# ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.29)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/gil/Desktop/116MB.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2021-05-30T06:03:44.000000Z
com.android.version: 10
Duration: 00:01:00.39, start: 0.000000, bitrate: 15393 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1080x2340, 15195 kb/s, SAR 1:1 DAR 6:13, 47.32 fps, 60 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 192 kb/s (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7f8585815600] using SAR=9/26
[libx264 @ 0x7f8585815600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f8585815600] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x7f8585815600] 264 - core 161 r3049 55d517b - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=25 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, mp4, to '/tmp/420.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
com.android.version: 10
encoder : Lavf58.76.100
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m, progressive), 640x480 [SAR 9:26 DAR 6:13], q=2-31, 60 fps, 15360 tbn (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : VideoHandle
vendor_id : [0][0][0][0]
encoder : Lavc58.134.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, mono, fltp, 69 kb/s (default)
Metadata:
creation_time : 2021-05-30T06:03:44.000000Z
handler_name : SoundHandle
vendor_id : [0][0][0][0]
encoder : Lavc58.134.100 aac
frame= 3624 fps= 88 q=-1.0 Lsize= 4485kB time=00:01:00.35 bitrate= 608.8kbits/s dup=766 drop=0 speed=1.47x
video:4380kB audio:11kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.139495%
[libx264 @ 0x7f8585815600] frame I:18 Avg QP:20.86 size: 28212
[libx264 @ 0x7f8585815600] frame P:1130 Avg QP:22.35 size: 3083
[libx264 @ 0x7f8585815600] frame B:2476 Avg QP:22.88 size: 199
[libx264 @ 0x7f8585815600] consecutive B-frames: 6.1% 6.2% 6.3% 81.3%
[libx264 @ 0x7f8585815600] mb I I16..4: 28.2% 27.7% 44.1%
[libx264 @ 0x7f8585815600] mb P I16..4: 4.6% 2.0% 1.7% P16..4: 13.8% 4.1% 2.7% 0.0% 0.0% skip:70.9%
[libx264 @ 0x7f8585815600] mb B I16..4: 0.3% 0.1% 0.0% B16..8: 8.0% 0.5% 0.1% direct: 0.2% skip:90.8% L0:47.1% L1:48.0% BI: 4.9%
[libx264 @ 0x7f8585815600] 8x8 transform intra:24.0% inter:44.1%
[libx264 @ 0x7f8585815600] coded y,uvDC,uvAC intra: 19.6% 22.3% 13.8% inter: 3.1% 1.7% 0.7%
[libx264 @ 0x7f8585815600] i16 v,h,dc,p: 20% 77% 2% 2%
[libx264 @ 0x7f8585815600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 27% 52% 1% 1% 1% 2%5 0% 3%
[libx264 @ 0x7f8585815600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 47% 18% 2% 3% 2% 6% 1% 5%
[libx264 @ 0x7f8585815600] i8c dc,h,v,p: 55% 39% 5% 1%
[libx264 @ 0x7f8585815600] Weighted P-Frames: Y:2.4% UV:1.9%
[libx264 @ 0x7f8585815600] ref P L0: 60.7% 9.7% 15.9% 13.5% 0.2%
[libx264 @ 0x7f8585815600] ref B L0: 69.2% 22.0% 8.7%
[libx264 @ 0x7f8585815600] ref B L1: 94.1% 5.9%
[libx264 @ 0x7f8585815600] kb/s:593.92
[aac @ 0x7f8585816e00] Qavg: 65521.922
Video is successfully converted 720p and 480p, let's if this method worth trying.
git@localhost #
-rwxr-----@ 1 gil wheel 111M May 30 19:59 /tmp/116MB.mp4
-rw-r--r-- 1 gil wheel 9.0M May 30 19:51 /tmp/hd720.mp4
-rw-r--r-- 1 gil wheel 4.4M May 30 19:57 /tmp/420.mp4
0 Comments