#!/bin/bash ################################################################################################# # Nautilus Ogv to Flv Converter script v.1.0 # # ------------------------------------------ # # # # A frontend for converting .ogg/.ogv files to flv format made with gtk-recordmydesktop. # # Should work just fine for all .ogg/.ogv formats. # # # # Code put together by Jean-Claude, Oct 2008 - https://wiki.ubuntu.com/JeanClaude # # This code is licensed under the General Public License as released by the # # Free Software Foundation. You may use, modify and distribute as long as you use # # the GPL2 or later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # ################################################################################################# # # About # ----- # # I put this together to make it easier to convert videos from gtk-recordmydesktop's ogg/ogv # files into flv for web uploads. # # Initially I used ffmpeg, but had an issue converting recordmydesktop files with the newer # 0.3.7.2-0 version. The older 0.3.6-1 recordmydesktop had no such issues. No clue as to why! # So, for now, I have to convert to AVI format before converting over to FLV. # # Source viewed for inspiration, examples and guidance: # "Video Convertor Script" by Craig Szymanski, Sept 2005 - http://szone.berlinwall.org # # Updates: # -------- # # Added better error handling: # - When installing mencoder for you, the script should detect if it did not succeed. After # installing, script will continue without prompting you, unless the above error is detected. # - If one selects the wrong file format, you should get an error. # # Requirements # ------------ # # - Zenity (Included with Gnome 2.4) # - Mencoder # # Installation # ------------ # # Copy this file to your "/home/username/.gnome2/nautilus-scripts" folder and make sure it is executable. # Right click over the file and select "Properties" -> "Permissions" and select the # checkbox "Allow executing file as program" or "chmod +x filename" from a terminal. # # Known Issues # ------------ # # - It's kind of slow, but it takes a little while to re-encode video anyway. Doing it # from the terminal will take just as long! :-) # - The process of converting to AVI first is not the best way, but it works. # - Cancel buttons do not work, yet! Unfortunetly this seems to be a problem on some Distros # like the popular "Ubuntu" based systems. https://bugs.launchpad.net/ubuntu/+source/zenity/+bug/220656 # - The resulting file has two extensions; filename.ogv.flv for example. # # Contact # ------- # # Please let me know if you've used this script and how it's working out for you. Also, if you have # any problems, e-mail me at siafulinux@gmail.com. No promises that I'll be able to get back to # you, but at least I can try to look at the issue. # # https://wiki.ubuntu.com/JeanClaude # ######################################################## # LETS MAKE SURE MENCODER IS INSTALLED mencoder_exists=`which mencoder | grep -c "mencoder"` # GIVE ERROR IF MENCODER IS NOT INSTALLED! if [ $mencoder_exists -eq "0" ]; then mencoder_error=`zenity --error --title="Error - Convertor Required!" --text="You need to have mencoder installed to use this script.\n\nAbout to install mencoder for you, if this fails, please enable Universe repositories and type 'sudo apt-get install mencoder' in a terminal to install."`; install_mencoder=`gksudo apt-get install mencoder | zenity --progress --pulsate --title "Installing files..." --text "Installing mencoder." --auto-close`; fi # LETS MAKE SURE MENCODER IS INSTALLED AGAIN. IF IT DOESN'T, ERROR AGAIN AND EXIT, ELSE JUST CONTINUE. # THIS SECTION PROBABLY NEEDS TO BE REVISED; BUT WORKS. mencoder_exists2=`which mencoder | grep -c "mencoder"` if [ $mencoder_exists2 -eq "0" ]; then zenity --error --title="Error!" --text="Something went wrong. Please try to manually install mencoder with 'sudo apt-get install mencoder'."; exit; fi #if [ $mencoder_exists2 != "0" ]; then # zenity --info --title="Mencoder Installed" --text="Mencoder installed correctly, continuing with file conversion."; #fi # ALERT USER IF NO FILE IS SELECTED #if [ $1 -eq 0 ]; then # zenity --error --title="Error" --text="You must select a file to process..." # exit 1 #fi # DETECT MIME TYPE mime=`file -bi "$1"` correct_video="0" # MAKE SURE FILE IS OGG OR OGV FORMAT if echo "$1" | grep -q '.ogg'; then echo "File is in .ogg Format" video_type="ogg" correct_video="1" elif echo "$1" | grep -q '.ogv'; then echo "File is in .ogv Format" video_type="ogv" correct_video="1" #file -bi "$1" | grep -i '.ogv' elif echo "$1" | grep -q '.flv'; then echo "File is in .flv Format" video_type="flv" correct_video="1" #file -bi "$1" | grep -i '.ogv' else zenity --error --title="Error" --text="Please select a valid ogv, ogg or flv file for processing." exit 1 fi # IF VIDEO FORMAT IS CORRECT, THEN... if [ $correct_video -eq "1" ]; then # Have the user select a size for conversion # scale=`zenity --list --title="Choose the scale size for your video" --radiolist --column="Check" --column="Size" "" "320:240" "" "640:480" "" "800:600" "" "1024:768"` if [ $scale -eq ""]; then zenity --error --text="Size not defined by user. Please choose a scale to use. " exit 1 fi # LETS ENCODE THE VIDEO NOW! # FIRST WE NEED TO ENCODE THE VIDEO TO AVI TO BE COMPATIBLE WITH gtk-recordmydesktop v 0.3.7.2-0 encode_avi=`mencoder -idx "$1" -ovc lavc -oac mp3lame -o avi_output.avi | zenity --progress --pulsate --title "Converting file..." --text "Converting to temporary avi format." --auto-close`; # NOW CONVERT THE AVI FILE TO FLV encode_flv=`mencoder -forceidx "avi_output.avi" -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=250:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -vf scale=$scale -o "$1".flv $1 | zenity --progress --pulsate --percentage=0 --title "Converting file..." --text "Converting temporary file to \"$1.flv\"." --auto-close`; # REMOVE AVI WORK FILE remove_file=`rm avi_output.avi | zenity --progress --pulsate --percentage=0 --title "Converting .$video_type Video File to .flv" --title "Cleaning Up" --text "Cleaning Up" --auto-close`; fi if [[ $encode_flv != 0 ]]; then zenity --info --title "Success!" --text "Successfully converted \"$1\" to .flv format!"; else zenity --error --title "Error!" -- text "An error occured, please try again!"; fi