Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ $# -lt 3 ]; then
- echo "[-] $0 $action <in-video-audio-file> <start-time-as-HH:MM:SS> <end-time-as-HH:MM:SS/num_seconds> [out-file]"
- exit
- fi
- in_audio_file="$1"
- start_time="$2"
- end_time_num_seconds="$3"
- if [ -z "$out_file" ]; then
- in_file_ext="${in_audio_file##*.}"
- in_file_name_without_ext="${in_audio_file%.*}"
- out_file=`echo "$in_file_name_without_ext""_modified.$in_file_ext"`
- fi
- echo "[+] out_file: $out_file"
- if [ ! -f "$in_audio_file" ]; then
- echo "[-] File: $in_audio_file not found."
- exit
- fi
- if [ ! -z `echo "$end_time_num_seconds" | grep ":"` ]; then
- end_time="$end_time_num_seconds"
- hh_end=`echo "$end_time" | cut -d":" -f1 | sed 's/^0//'`
- mm_end=`echo "$end_time" | cut -d":" -f2 | sed 's/^0//'`
- ss_end=`echo "$end_time" | cut -d":" -f3 | sed 's/^0//'`
- hh_st=`echo "$start_time" | cut -d":" -f1 | sed 's/^0//'`
- mm_st=`echo "$start_time" | cut -d":" -f2 | sed 's/^0//'`
- ss_st=`echo "$start_time" | cut -d":" -f3 | sed 's/^0//'`
- echo "[*] $hh_end,$mm_end,$ss_end $hh_st,$mm_st,$ss_st"
- num_seconds=$(( (hh_end-hh_st)*3600 + (mm_end-mm_st)*60 + (ss_end-ss_st) ))
- if [ "$num_seconds" -lt 0 ]; then
- echo "[-] End time must be before start time. num_seconds: $num_seconds < 0."
- exit
- fi
- else
- num_seconds="$end_time_num_seconds"
- fi
- echo "[+] num_seconds: $num_seconds"
- echo "[*] Extracting audio between start time: $start_time and num_seconds: $num_seconds"
- yes | ffmpeg -i "$in_audio_file" -ss "$start_time" -t "$num_seconds" -acodec copy "$out_file"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement