#!/bin/sh # Nautilus-script's MPEG2XviD script v1.0a by Marco Luethy ( http://marco.luethy.net/ ) # Licenced under the GPL # Requires transcode and xterm # INSTALLATION # Install (or, rather copy) script to ~./.gnome2/nautilus-scripts. Right click on a file you wish # to transcode and go to the "Scripts" option, and select the MPEG2XviD script. If the "Scripts" # option does not appear underneath "Create Folder" when right-clicking, in Nautilus's address # bar, go to the folder ~./.gnome2/nautilus-scripts # PRESET VARIABLES # For convenience you may want to change these variables to fit your system. tmp_dir="/tmp/encoding" default_indir=`pwd` default_outdir="/media1/new" # I/O # Script's support for transcode. Might be a good idea to auto-detect input, and let user choose output. # this would make the script not just a MPEG2 to XviD script, but anything to anything supported by transcode. decode="mpeg2" decode_name="MPEG2" encode="xvid4" encode_name="XviD" # DYNAMIC VARIABLES # No change should be needed here. file_input="$default_indir/$1" file_output_t=`echo $1 | sed 's/.mpg/ (XviD).avi/'` file_outdir="`gdialog --title "Output Directory" --inputbox "Save output in directory:" 25 25 "$default_outdir" 2>&1`" file_output="`gdialog --title "Output File" --inputbox "Save output to:" 25 25 "$file_output_t" 2>&1`" if `gdialog --title "Begin Transcoding?" --yesno "Setup complete!\nInput: $file_input\nOutput: $file_outdir/$file_output\n\nDoes this sound right?" 25 25` then mkdir $tmp_dir # Mpegs are usually coded anamorph, that means you should rescale the video when transcoding to xvid # I would suggest -Z 640x,fast If you leave out the height of -Z, transcode tries to be smart and guesses it based on the import aspect rati # regarding the segfault: chech the exit code `$?' it will be different form a canceled exit and a segfault # -R n[,f1[,f2]] enable multi-pass encoding (0-3) [0,divx4.log,pcm.log] (SEE dvdrip implementation) #--config_dir dir Assume config files are in this dir [off] # Audio/video bitrate>filesize conversions. # Audio: 45 bytes * # of frames + 12kb * # of seconds # and you just have to get all your units to megabytes in there # and then you take your target file size subtract that # # and then you take tha file size # turn it into kilobits # and divide by # of seconds in the movie # and that's about it # it's off by 5-10 kbps cause they do some rounding I don't see # and then you take your target # and subtract your audio # and that's your video # and you turn that into kbps # from megabytes # just *1024 * 8 # and then divide by total seconds if `xterm +sb -geometry 70x5 -title "Transcoding (encoding $decode_name to $encode_name) $file_output_t" -e "transcode -i '$file_input' -x $decode -o '$tmp_dir/$file_output' -y $encode --a52_drc_off -E 44100 -J resample -b 96,0,0 -w 1024 -V"` then task=1 else gdialog --title "Error!" --msgbox "An error has occured." 25 25 exit fi mv "$tmp_dir/$file_output" "$file_outdir/$file_output" if `gdialog --title "Transcoding Completed." --defaultno --yesno "Transcoding from $decode_name to $encode_name complete.\nInput: $file_input\nOutput: $file_outdir/$file_output\n\nDelete Original file?\nNOTE: Check new file before deleting old." 25 25` then rm -Rf "$file_input" exit else exit fi else gdialog --title "Transcoding Canceled" --msgbox "Transcode script canceled." 25 25 fi #FILE_INPUT="/media1/new/Star Trek Voyager - 7x15 - The Void_L001.avi" #DATA=`tcprobe -i "$FILE_INPUT" | tail -c 56 | sed -e 's/[^:]//' -e 's/[=]//g' -e 's/[_]//g' -e 's/[ *][a-zA-z]*//g' -e 's/[,]/ /g'` #DURATION=`echo $DATA | awk '{print $3 ; }' | sed -e 's/[:]/ /g'` #FRAMES=`echo $DATA | awk '{print $1 ; }'` #HOUR=`echo $DURATION | awk '{print $1 ; }'` #MIN=`echo $DURATION | awk '{print $2 ; }'` #SEC=`echo $DURATION | awk '{print $3 ; }'` #TARGET_SIZE=200 #AUDIO_BITRATE=96 ## if SEC contains a decimal, SEC is chopped off at decimal, and incremented. 23.33 becomes 24 #SECONDS=$(( ($HOUR*60*60)+($MIN*60)+$(( `echo $SEC | sed -e 's/[.]/ /g' | awk '{ print $1 ; }'`+1 )) )) #MB_AUD=$(( (((60*$FRAMES)/1024)/1024)+((($AUDIO_BITRATE/8)*$SECONDS)/1024) )) #MB_VID=$(( $TARGET_SIZE-$MB_AUD )) #VIDEO_BITRATE=$(( ((($MB_VID*1024*8)/$SECONDS)+10) )) #echo "Data: $DATA" #echo "Duration: $SECONDS s" #echo "Audio size: $MB_AUD MB" #echo "Video size: $MB_VID MB" #echo "Video Bitrate: $VIDEO_BITRATE kbps"