Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A convert shell script from ts to mp4 with VLC
#!/bin/bash
vlc="/mnt/c/Program\ Files/VideoLAN/VLC/vlc.exe"
directory="tvrec"
lin_directory="/mnt/f/"$directory
win_directory="f:\\"$directory
src_ext="ts"
dst_ext="mp4"
files=$lin_directory"/*."$src_ext
#filearr=()
MAX_FILES=${1:-100}
file_counter=0
for file_path in $files ; do
if [ -f "$file_path" ] ; then
file_full_name="${file_path##*/}"
file_name=("${file_full_name%.*}")
file_counter=$((file_counter + 1))
if [ ! -f "$lin_directory/$file_name.$dst_ext" ] ; then
command=$vlc" -I dummy \"$win_directory\\$file_name.$src_ext\" --sout='#transcode{vcodec=h264,vb=1024,scale=1,deinterlace,audio-sync}:standard{access=file,mux="$dst_ext",dst=\""$win_directory\\$file_name.$dst_ext\""}' vlc://quit"
echo $file_counter : $file_name
eval $command
if [ $file_counter -ge $MAX_FILES ] ; then
break
fi
else
echo $file_counter : $file_name : skipped.
fi
fi
done
Owner

Matthew238 commented Jul 23, 2017

Rev 4 : This change can show a progress number and a processing file name each processing.
Rev 5 : This script skips a convert process if there is already the mp4 file that is converted to.
Rev 6 : Done refactoring and adding an argument to give a maximum number of times to convert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment