Last active
April 10, 2018 03:41
-
-
Save Matthew238/08949530a3119f8342feda1fed79b3ef to your computer and use it in GitHub Desktop.
A convert shell script from ts to mp4 with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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