YouTube >
(FFmpeg)
Table of Contents [hide]
Determining the dimensions of your video ∞
ffmpeg -i filename.avi
Spoiler
FFmpeg version SVN-r12143, Copyright (c) 2000-2008 Fabrice Bellard, et al. configuration: --prefix=/usr --enable-shared --libdir=/usr/lib --enable-pp --enable-liba52 --enable-gpl --enable-pthreads --enable- x11grab --enable-libfaad --enable-libfaac --enable-libxvid --enable-libamr-nb --enable-libamr-wb --enable-libmp3lame --enable-libx264 --enable-nonfree libavutil version: 49.6.0 libavcodec version: 51.50.1 libavformat version: 52.7.0 libavdevice version: 52.0.0 built on Feb 19 2008 15:20:20, gcc: 4.1.1 20060724 (prerelease) (4.1.1-4pclos2007) Input #0, avi, from 'filename.avi': Duration: 00:00:26.8, start: 0.000000, bitrate: 1090 kb/s Stream #0.0: Video: mpeg4, yuv420p, 688x304 [PAR 1:1 DAR 43:19], 25.00 tb(r) Stream #0.1: Audio: mp3, 44100 Hz, stereo, 128 kb/s Must supply at least one output file
Notice 688×304
NOTE – If you have issues with FFmpeg, try MPlayer.
mplayer filename.avi
Spoiler
MPlayer 1.0rc2-4.1.1 (C) 2000-2007 MPlayer Team
CPU: AMD Sempron(tm) Processor 3300+ (Family: 15, Model: 44, Stepping: 2)
CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing filename.avi.
AVI file format detected.
[aviheader] Video stream found, -vid 0
[aviheader] Audio stream found, -aid 1
VIDEO: [XVID] 688x304 12bpp 25.000 fps 947.4 kbps (115.6 kbyte/s)
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
==========================================================================
==========================================================================
Trying to force audio codec driver family libmad...
Opening audio decoder: [libmad] libmad mpeg audio decoder
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [mad] afm: libmad (libMAD MPEG layer 1-2-3)
==========================================================================
AO: [oss] 44100Hz 2ch s16le (2 bytes per sample)
Starting playback...
VDec: vo config request - 688 x 304 (preferred colorspace: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is 2.26:1 - prescaling to correct movie aspect.
VO: [xv] 688x304 => 688x304 Planar YV12 [zoom]
A: 0.6 V: 0.6 A-V: 0.017 ct: 0.041 16/ 16 10% 5% 2.0% 0 0
Exiting... (Quit)
Notice 688×304
Converting a video ∞
-
Calculate the resize and the padding needed.
- Example: 688×304 becomes 640×282 with a top/bottom pad of 38/40
SETTINGS="-y -sameq" SIZE=640x282 TOP=38 BOTTOM=40 LEFT=0 RIGHT=0 ffmpeg -i filename.avi $SETTINGS -s $SIZE -padtop $TOP -padbottom $BOTTOM -padleft $LEFT -padright $RIGHT ~/01-high-quality-test1.avi
TODO – ffmpeg video resizing bash notes ∞
TODO – Make the resizing calculation auto-magical with bash math!
# urk.. I'm not sure what I'm doing.. tackle this another day. DIMENSIONS_SOURCE=688x304 DIMENSIONS_TARGET=640x360 source_width=${DIMENSIONS_SOURCE%x*} source_height=${DIMENSIONS_SOURCE#*x} #determine source ratio source_ratio=`divide $source_width $source_height` if [ $source_ratio -gt 1 ]; then # It's wider than it is tall. echo wider echo wider: $source_width / $source_ratio new_width=$source_width new_height=`divide $source_width $source_ratio` else # It's taller than it is wide. echo taller: $source_width x $source_ratio new_height=$source_width new_width=`multiply $source_width $source_ratio` fi echo source ratio: $source_ratio echo $new_width x $new_height //calculate the image ratio $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; }
Example: 688×304 becomes 640×282 with a top/bottom pad of 38/40
source_width=688 source_height=304 target_width=640 target_height=340 # => becomes 640x282 with a top/bottom pad of 38/40 ratio=`divide $source_width $source_height` ## 688/304 = 2.26 if [ $source_width > $target_width ]; then ## 688 > 640 (true) if $source_height > $target_height ## 304 > 340 (false) # both are over... # - learn which is over the least # - if width_diff < height_diff - reduce height by ? (width_diff*ratio)? # - if height_diff < width_diff - reduce width by ? else # $source_width > $target_width ## ( 304 < 340 ) (true) new_width=$target_width diff=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_1" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_1');" >[ 1 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_1" class="footnote_tooltip" > $source_width - $target_width </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_1').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_1', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> ## 688 - 640 (48) echo $diff ## 48 # FIXME: this subtraction will fail because subtration won't work with fractions. # TODO: implement a rounding function new_height=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_2" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_2');" >[ 2 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_2" class="footnote_tooltip" > $source_height - `divide $diff $ratio` </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_2').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_2', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> ## 304 - (48/2.26) = 304-21 = 283 # TODO: Round it down echo $new_width x $new_height fi else # $source_width < $target_width if $source_height > target_height ... else # both ( $source_width < $target_width ) and ( $source_height < $target_height ) ... fi fi
if both are over…
diff1=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_3" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_3');" >[ 3 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_3" class="footnote_tooltip" > $a - $c </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_3').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_3', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> diff2=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_4" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_4');" >[ 4 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_4" class="footnote_tooltip" > $b - $d </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_4').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_4', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> if [ $diff1 -lt $diff2 ]; then # goal becomes ( $c - $diff1 ) newb=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_5" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_5');" >[ 5 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_5" class="footnote_tooltip" > `multiply $diff1 $ratio` + $b2 </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_5').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_5', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> else newa=$<span class="footnote_referrer" ><a><sup id="footnote_plugin_tooltip_25527_6" class="footnote_plugin_tooltip_text" onclick="footnote_moveToAnchor_25527('footnote_plugin_reference_25527_6');" >[ 6 ]</sup ></a><span id="footnote_plugin_tooltip_text_25527_6" class="footnote_tooltip" > $a + `multiply $diff2 $ratio` </span ></span><script type="text/javascript"> jQuery('#footnote_plugin_tooltip_25527_6').tooltip({ tip: '#footnote_plugin_tooltip_text_25527_6', tipClass: 'footnote_tooltip', effect: 'fade', predelay: 0, fadeInSpeed: 200, delay: 400, fadeOutSpeed: 200, position: 'top center', relative: true, offset: [1, 0], });</script> fi echo $newa x $newb
Example: 688×304 becomes 640×282 with a top/bottom pad of 38/40
SETTINGS="-y -sameq" SIZE=640x282 TOP=38 BOTTOM=40 LEFT=0 RIGHT=0 ffmpeg -i filename.avi $SETTINGS -s $SIZE -padtop $TOP -padbottom $BOTTOM -padleft $LEFT -padright $RIGHT ~/01-high-quality-test1.avi
