Created
June 4, 2020 01:07
-
-
Save alexnum/b660f6a697877db6a8a6b7305675a51d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
find -name "* *" -type f | rename 's/ /_/g' | |
list=$(ls ./ | grep .mkv) | |
i=0; | |
for file in $list | |
do | |
BASE_FILE_NAME=$(echo $file | awk -F".mkv" '{print $1}') | |
mkvextract tracks ./$file 2:./${BASE_FILE_NAME}.srt | |
startTimeLine=$(cat ${BASE_FILE_NAME}.srt | grep "Episode Title" | head -n 2 | tail -1 | sed 's/^.*\( 0,0.*\)/\1/g') | |
startTime=$(node -e "console.log('${startTimeLine}'.split(',')[1].split('.')[0])") | |
#endingTime fica como Ending PT | |
endTimeLine=$(cat ${BASE_FILE_NAME}.srt | grep "Ending PT" | head -n 2 | tail -1 | sed 's/^.*\( 0,0.*\)/\1/g') | |
endTime=$(node -e "console.log('${endTimeLine}'.split(',')[1].split('.')[0])") | |
duration=$(node -e "var tu = require('./timeUtils'); console.log(tu.getTimeStr(tu.getSeconds('${endTime}') - tu.getSeconds('${startTime}')))"); | |
echo "START of ${baseFileName}: ${startTime}" | |
startCmd="-ss ${startTime}" | |
endCmd="-t ${duration}" | |
if [ $i == 0 ]; then | |
startCmd="" | |
duration=$(node -e "var tu = require('./timeUtils'); console.log(tu.getTimeStr(tu.getSeconds('${endTime}')))"); | |
endCmd="-t ${duration}" | |
elif [ $i == $len - 1]; then | |
endCmd="" | |
fi | |
#ffmpeg -ss ${startTime} -t ${duration} -i ${BASE_FILE_NAME}.mkv -codec copy ${BASE_FILE_NAME}_crop.mkv | |
ffmpeg ${startCmd} ${endCmd} -i ${BASE_FILE_NAME}.mkv -codec copy ${BASE_FILE_NAME}_crop.mkv | |
echo "'./${BASE_FILE_NAME}.mkv' - ${startTime}" >> ~/one_piece_tempos.txt | |
echo "file './${BASE_FILE_NAME}_crop.mkv'" >> files.txt | |
i=$((i+1)) | |
done | |
ffmpeg -f concat -safe 0 -i files.txt -c copy join_01_05.mkv |
This file contains hidden or 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
module.exports = { | |
getSeconds: function(timeStr){ | |
var a = timeStr.split(':'); // split it at the colons | |
var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]); | |
return seconds; | |
}, | |
getTimeStr: function(seconds){ | |
return new Date(seconds * 1000).toISOString().substr(11, 8) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment