FFmpeg_flv_extract

Christians-iMac:FFmpeg_flv_extract chunrix$ cat ffmpeg_flv_extract.sh
#!/bin/bash
#Caution1:U must keep 'ffmpeg' file and this script in same folder.
#Caution2:Only the original audio format matches the extracted one, the audio extracting command will work, otherwise pls change the mp4 to any other format in command or just enocde audio as mp4 instead.

##################################
#Extract audio and video from flv file.

script_dir=$(cd "$(dirname "$0")";pwd)
cd "$script_dir"
pwd

read -p 'Pls drag the flv file to extract audio and video:'

fullpath=$(echo $REPLY)
filename=$(basename "$REPLY" | sed 's/.....$//' )
dirname=$(dirname "$REPLY")

#echo 'FULLPATH' "$fullpath".test
#echo 'DIRNAME' "$dirname".test
#echo 'FILENAME without exten' "$filename".test

"$script_dir"/ffmpeg -i "$fullpath" -vcodec copy -an "$dirname"/"$filename".mp4 > /dev/null 2>&1
"$script_dir"/ffmpeg -i "$fullpath" -acodec copy -vn "$dirname"/"$filename".m4a > /dev/null 2>&1
echo 'Extracted Successfully'

##################################
#Merge to MP4 or not.

function merge_to_mp4()
{
"$scriptdir"/ffmpeg -i "$dirname"/"$filename".mp4 -i "$dirname"/"$filename".m4a -vcodec copy -acodec copy "$dirname"/MERGED"$filename".mp4
}

#Ignore upper/lower case
shopt -s nocasematch

echo 'Do you want to merge as MP4 file? (y or n) '
read yesorno
case $yesorno in
yes | y)
merge_to_mp4;;
no | n)
echo '\nU have cancelled the process of merging.\n';;
*) echo '\nPls input yes or no\n';;
esac > /dev/null 2>&1

echo 'Merged Successfully.'

##################################
#Remove Extracted audio and video and original flv file or not.

echo 'Are u sure to remove extracted audio,video and original flv files? (y or n) '
read yesorno
case $yesorno in
yes | y)
rm "$dirname"/"$filename".mp4 "$dirname"/"$filename".m4a
mv "$fullpath" $HOME/.Trash/
mv "$dirname"/MERGED_"$filename".mp4 "$dirname"/"$filename".mp4;;
no | n)
echo '\nU have cancelled the process of removal.\n'
exit 1;;
*) echo '\nPls input yes or no\n';;
esac > /dev/null 2>&1
echo 'Removed Successfully.'

echo 'All Done.'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章