Skip to content

Instantly share code, notes, and snippets.

@Matthew238
Last active November 9, 2020 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Matthew238/3eee437dc505c708014df3f0171b9b62 to your computer and use it in GitHub Desktop.
Save Matthew238/3eee437dc505c708014df3f0171b9b62 to your computer and use it in GitHub Desktop.
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
@Matthew238
Copy link
Author

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