Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A convert shell script from ts to mp4 with ffmpeg
#!/bin/bash
CMDNAME=`basename $0`
dir_d="/mnt/d/ほげ"
dir_f="/mnt/f/ふが"
directory="$dir_f"
while getopts dfn: OPT
do
case $OPT in
"d" ) directory="$dir_d" ;;
"f" ) directory="$dir_f" ;;
"n" ) VAL_N="$OPTARG" ;;
# * ) echo "Usage: $CMDNAME [-d] [-f] [-n VALUE]" 1>&2
# exit 1 ;;
esac
done
src_ext="ts"
dst_ext="mp4"
files=$directory"/*."$src_ext
MAX_FILES=${VAL_N:-100}
#echo $MAX_FILES
#echo $directory
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 "$directory/$file_name.$dst_ext" ] ; then
command="ffmpeg -i \"$directory/$file_name.$src_ext\" -strict -2 -pix_fmt yuv420p -b:v 0.5M \"$directory/$file_name.$dst_ext\""
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.