Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -lt 3 ]; then
  3. echo "[-] $0 $action <in-video-audio-file> <start-time-as-HH:MM:SS> <end-time-as-HH:MM:SS/num_seconds> [out-file]"
  4. exit
  5. fi
  6. in_audio_file="$1"
  7. start_time="$2"
  8. end_time_num_seconds="$3"
  9.  
  10. if [ -z "$out_file" ]; then
  11. in_file_ext="${in_audio_file##*.}"
  12. in_file_name_without_ext="${in_audio_file%.*}"
  13. out_file=`echo "$in_file_name_without_ext""_modified.$in_file_ext"`
  14. fi
  15. echo "[+] out_file: $out_file"
  16.  
  17. if [ ! -f "$in_audio_file" ]; then
  18. echo "[-] File: $in_audio_file not found."
  19. exit
  20. fi
  21.  
  22. if [ ! -z `echo "$end_time_num_seconds" | grep ":"` ]; then
  23. end_time="$end_time_num_seconds"
  24. hh_end=`echo "$end_time" | cut -d":" -f1 | sed 's/^0//'`
  25. mm_end=`echo "$end_time" | cut -d":" -f2 | sed 's/^0//'`
  26. ss_end=`echo "$end_time" | cut -d":" -f3 | sed 's/^0//'`
  27.  
  28. hh_st=`echo "$start_time" | cut -d":" -f1 | sed 's/^0//'`
  29. mm_st=`echo "$start_time" | cut -d":" -f2 | sed 's/^0//'`
  30. ss_st=`echo "$start_time" | cut -d":" -f3 | sed 's/^0//'`
  31.  
  32. echo "[*] $hh_end,$mm_end,$ss_end $hh_st,$mm_st,$ss_st"
  33. num_seconds=$(( (hh_end-hh_st)*3600 + (mm_end-mm_st)*60 + (ss_end-ss_st) ))
  34.  
  35. if [ "$num_seconds" -lt 0 ]; then
  36. echo "[-] End time must be before start time. num_seconds: $num_seconds < 0."
  37. exit
  38. fi
  39. else
  40. num_seconds="$end_time_num_seconds"
  41. fi
  42. echo "[+] num_seconds: $num_seconds"
  43.  
  44. echo "[*] Extracting audio between start time: $start_time and num_seconds: $num_seconds"
  45. 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