barjac

MOVdir2mov

Jan 25th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # MOVdir2mov
  3. # Converts all .MOV files in a dir to .mov and chops "frames to crop" frames from end
  4.  
  5. if [[ ${#1} = 0 ]] || [[ ${#2} = 0 ]] ; then
  6.     echo "Usage  : MOVdir2mov <path to dir> <frames to crop> "
  7.     exit 1
  8. fi
  9.  
  10. frames_to_crop=$2
  11. path_to_ffmpeg=/home/$USER/kdenlive/20110124/bin/
  12.  
  13. MOV2mov()
  14. {
  15.  
  16. filename=$1
  17. # Create output path and filename
  18. outfile=$(echo $filename | cut -d. -f1)".mov"
  19.  
  20. # Get clip duration
  21. duration=$(ffmpeg -i $filename 2>&1| grep Duration |sed 's/: /*/'|cut -d* -f2|cut -d, -f1)
  22. echo "duration "$duration
  23.  
  24. # Convert duration to seconds
  25. oldifs=$IFS
  26. IFS=:
  27. arr=($duration)
  28. IFS=$oldifs
  29. dursecs=$(echo ${arr[0]}*3600 + ${arr[1]}*60 + ${arr[2]} | bc)
  30.  
  31. # Convert duration to frames
  32. frames=$(echo "$dursecs * 29.97" | bc)
  33.  
  34. # Round up frames to integer
  35. frames=$(echo "($frames + 0.9999)/1" | bc)
  36. echo "Frames in clip "$frames
  37.  
  38. # Subtract frames from total
  39. ((oframes="$frames"-"$frames_to_crop"))
  40. echo "Frames to output "$oframes
  41.  
  42. # Render with ffmpeg
  43. "$path_to_ffmpeg"ffmpeg -vsync 0 -i $filename -vframes $oframes -r 29.97 -vcodec copy -acodec copy $outfile
  44. #ffmpeg -vsync 0 -i $filename -vframes $oframes -r 29.97 -vcodec copy -acodec copy $outfil
  45. }
  46.  
  47. for i in "$1"/*.MOV ; do
  48. MOV2mov $i
  49. done
  50.  
  51. # end of file ------------------------
Add Comment
Please, Sign In to add comment