#!/bin/sh ## ## Nautilus ## SCRIPT: 07_1movieFile_SCALE-resize_WxHpixels_ffmpeg-s_toMP4-H264-AAC.sh ## ## PURPOSE: Scale the frame-size of a movie file, down or up. ## ## METHOD: Uses 'zenity --entry' to prompt for the new pixel size. ## ## Uses 'ffmpeg' with '-s' (scale) --- and container, video codec, ## and audio codec specified with '-f', '-vcodec', and '-acodec ## respectively. ## ## Shows the new, scaled movie file in a movie player. ## ## NOTE on TESTING: ## This script has not been tested on a wide variety of movie types --- ## such as '.mpg', '.mp4', '.mkv', '.wmv', '.asf', '.avi', '.mov', ## '.ogg' suffix files. ## ## I may add comments here on which input formats (container,video,audio) ## have been tested and the outcome. ## ## HOW TO USE: In Nautilus, select a movie file. ## Then right-click and choose this script to run (name above). ## ############################################################################# ## Started: 2013jun25 Based on FE Nautilus Scripts ## 07_1movieFile_SCALE-resize_WxHpixels_ffmpeg-s-Vdefault-Adefault_PRELIM.sh ## and ## 04b_1movieFile_CROP_Npixels_ffmpeg-crop-pad_toMP4-H264-AAC.sh ## Changed: 2012 ############################################################################# ## FOR TESTING: (display the executed statements) # set -x ############################################## ## Get the filename of the selected file. ############################################## FILENAME="$1" # FILENAMES="$@" # FILENAMES="$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ################################################################## ## Check that the selected file is a 'supported' movie file type, ## according to the suffix. ## SKIP THE CHECK, for now. ## ## ## Types (suffixes) that MAY be 'supportable' are ## 'mkv', 'mp4', 'flv', 'mpg', 'mpeg', 'wmv', 'avi', 'asf', ## and others. ## ## (Assumes just one dot [.] in the filename, at the extension.) ################################################################## FILEEXT=`echo "$FILENAME" | cut -d\. -f2` # if test "$FILEEXT" != "mkv" -a "$FILEEXT" != "mp4" -a \ # "$FILEEXT" != "flv" -a \ # "$FILEEXT" != "mpg" -a "$FILEEXT" != "mpeg" -a \ # "$FILEEXT" != "wmv" -a "$FILEEXT" != "avi" -a \ # "$FILEEXT" != "asf" # then # exit # fi ########################################################### ## Prompt for Scale-to values --- width and height (pixels). ########################################################### SCALE_WxH="" SCALE_WxH=$(zenity --entry \ --title "SCALE-TO values --- width and height (pixels)." \ --text "\ Enter the size wanted for the video frames, width and height (pixels). Examples: 320x240 or 640x480 or 800x600 or 1024x768 or 1920x1080 (You will probably want to choose values that preserve the aspect ratio of the input movie file.) The new file will have the string '__SCALEDmmmxnnn' in the filename." \ --entry-text "640x480") if test "$SCALE_WxH" = "" then exit fi ############################### ## Prepare the output filename. ############################### FILENAMECROP=`echo "$FILENAME" | cut -d\. -f1` FILEOUT="${FILENAMECROP}_SCALED${SCALE_WxH}_h264-aac.mp4" if test -f "$FILEOUT" then rm -f "$FILEOUT" fi ################################################################### ## Use 'ffmpeg' to make the scaled down/up movie file. ################################################################### ## FOR TEST: # set -x xterm -hold -fg white -bg black -geometry 90x48+100+100 -e \ ffmpeg -i "$FILENAME" -f mp4 \ -vcodec libx264 \ -vpre /usr/share/ffmpeg/libx264-lossless_slow.ffpreset \ -crf 22 \ -acodec libfaac -ab 128k -ar 22050 -ac 1 \ -s $SCALE_WxH -threads 0 "$FILEOUT" ## These options come FROM the FE 'VIDCAP_CONVERT' Nautilus Script ## 30a_1mkvCapFile_CONVERTto_MP4-H264-AAC_4youtube_ffmpeg.sh ## To reduce the size of the audio data we may use parms like ## '-ab 96k -ar 22050 -ac 1' OR '-ab 64k -ar 22050 -ac 1' ## instead of parms like ## '-ab 128k -ar 44100 -ac 2' ## Change '-ac 1' to '-ac 2' if you want to preserve stereo. ## Most of the parameters for this 'ffmpeg' command came ## FROM "HOWTO: Proper Screencasting on Linux" by verb3k : ## ## "We use the preset 'slow' and a CRF value of 22 for rate control. ## The lower you set the CRF value, the better your video's quality ## will be, and consequently the file size and encoding time will ## increase, and vice-versa. ## ## For a good guide on encoding with FFmpeg+x264, see ## http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide/" ## Originally tried ## -vcodec libx264 -vpre slow -crf 22 \ ## BUT vpre 'slow' was not found. ## Fixed that by using the fully-qualified name above. (2011may06) ## This documents exactly which vpre file we are using. ## 'libfaac' was not found in ## ... -acodec libfaac -ab 128k -ac 2 \ ## Got 'Unknown encoder' msg. ## 'ffmpeg -formats' shows 'libfaad' and 'aac'. ## Tried 'libfaad'. Another 'Unknown encoder' msg. ## Trying 'aac'. Another 'Unknown encoder' msg. ## Googling found ## http://ubuntuforums.org/showthread.php?t=1117283 which points out cmds: ## ## sudo wget http://www.medibuntu.org/sources.list.d/`lsb_release -cs`.list --output-document=/etc/apt/sources.list.d/medibuntu.list ## sudo apt-get -q update ## sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring ## sudo apt-get -q update ## sudo apt-get install ffmpeg libavcodec-extra-52 ## ## to install 'libfaac'. That worked. (2011may06) ## FOR TEST: # set - ################################################################### ## Meaning of some 'popular' ffmpeg parms: ## ## -i val = input filename ## ## Video: ## -f val = specifies container format (for video plus audio) ## -vcodec codec - to force the video codec. ## Example: -vcodec mpeg4 ## Try "ffmpeg -formats" ## -r val = frame rate in frames/sec ## -b val = video bitrate in kbits/sec (default = 200 kbps) ## -s val = frame size, wxh where w and h are pixels or abbrevs: ## qqvga = 160x120 ## qvga = 320x240 ## vga = 640x480 ## svga = 800x600 ## xga = 1024x768 ## sxga = 1280x1024 ## uxga = 1600x1200 ## ## Audio: ## -acode codec - to force the audio codec. Example: ## -acodec libmp3lame ## -ab val = audio bitrate in bits/sec (default = 64k) ## -ar val = audio sampling frequency in Hz (default = 44100 Hz) ## -ac channels - for stereo or monaural - default = 1 ## -an - disable audio recording ## ## Some other useful params: ## ## Other Video [ for cropping, etc. ] : ## -aspect (4:3, 16:9 or 1.3333, 1.7777) ## -croptop pixels ## -cropbottom pixels ## -cropleft pixels ## -cropright pixels ## -padtop (bottom, left, right) ## -padcolor <6 digit hex number> ## -vn - disable video recording [for audio extract] ## -target type - where type is vcd or svcd or dvd or ..., then ## bitrate, codecs, buffersizes are set automatically. ## -pass n, where n is 1 or 2 ## ## Other: ## -t duration - format is hh:mm:ss[.xxx] ## -ss position - seek to given position, in secs or hh:mm:ss[.xxx] ## -y = overwrite output file(s) ## -fs file-size-limit ## -debug ## -threads count ####################################################################### ################################## ## Show the (scaled) movie file. ################################## if test ! -f "$FILEOUT" then exit fi # MOVIEPLAYER="/usr/bin/vlc" # MOVIEPLAYER="/usr/bin/mplayer" # MOVIEPLAYER="/usr/bin/gnome-mplayer" # MOVIEPLAYER="/usr/bin/totem" MOVIEPLAYER="/usr/bin/ffplay -stats" xterm -fg white -bg black -hold -geometry 90x24+100+100 -e \ $MOVIEPLAYER "$FILEOUT" ############################################### ## Use a user-specified MOVIEPLAYER. Someday? ############################################### # . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi # . $DIR_NautilusScripts/.set_VIEWERvars.shi # $MOVIEPLAYER "$FILEOUT" &