Skip to content

Instantly share code, notes, and snippets.

@stdevPavelmc
Created July 12, 2019 19:33
Show Gist options
  • Save stdevPavelmc/b06286b3824f7ba534c033d1bc0a7d60 to your computer and use it in GitHub Desktop.
Save stdevPavelmc/b06286b3824f7ba534c033d1bc0a7d60 to your computer and use it in GitHub Desktop.
#!/bin/sh
######################################################################
# Convert Youtube AV1 video files, Gnome nautilus script
#
# You need ffmped, mencoder and aom video encoder/decoder for AV1 video
#
# Goal here is to convert it as fast as it can with so-so resolution
# and playable in any embedded device, specs follows
#
# * Avi container
# * Video codec is xvid
# * Video aspect and geometry is preserved
# * Bitrate about 750 kbits/s
# * Audio codec is mp3
# * Audio Sampling is preserved
#
# Author is Pavel Milanes (CO7WT) pavelmc@gmail.com
# Date is 12 july 2019
#
######################################################################
# Get current path
mypath="`pwd`"
for filename in "$@"; do
if [ -n "$*,?" ];then
# remove the trailing chars of the extension
cutfilename=`echo "$filename" | rev | cut -d "." -f 2- | rev`
# check if file exist (fail-safe for overwrite)
if [ -f "$mypath/$cutfilename.avi" ] ; then
# add "conv" to the filename
cutfilename=$cutfilename"_conv"
fi
TMP=`mktemp`
# First extract video
aomdec "$mypath/$filename" | mencoder -ovc xvid -xvidencopts pass=2:bitrate=750 -oac copy - -o "$TMP.avi" 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Posición :\\t"$1"\\nCuadro :\\t"$2"\\nPorcentaje :\\t"$3"%\\nRadio de cuadros :\\t"$4"\\nTiempo restante :\\t"$6; fflush();}' | zenity --progress --auto-kill --auto-close --title="Converting video..."
# extracting audio
ffmpeg -i "$mypath/$filename" "$TMP.mp3"
# packing all togother
#ffmpeg -i "$TMP.mp3" -i "$TMP.avi" "$mypath/$cutfilename.avi"
mencoder -ovc copy -audiofile "$TMP.mp3" -oac copy "$TMP.avi" -o "$mypath/$cutfilename.avi" 2>&1 | awk -vRS="\r" '$1 ~ /Pos/ {gsub(/Pos:/," ");gsub(/%\)/," ");gsub(/ \(/," ");print $3"\n#Posición :\\t"$1"\\nCuadro :\\t"$2"\\nPorcentaje :\\t"$3"%\\nRadio de cuadros :\\t"$4"\\nTiempo restante :\\t"$6; fflush();}' | zenity --progress --auto-kill --auto-close --title="Packing the final video..."
# erase the tmp files
rm -rf "$TMP*"
fi
done
zenity --info --text="Video Conversion ended!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment