barjac

MOVdir2mov & output

Jan 25th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.61 KB | None | 0 0
  1. Script:-
  2. #!/bin/bash
  3. # MOVdir2mov
  4. # Converts all .MOV files in a dir to .mov and chops "frames to crop" frames from end
  5.  
  6. if [[ ${#1} = 0 ]] || [[ ${#2} = 0 ]] ; then
  7.     echo "Usage  : MOVdir2mov <path to dir> <frames to crop> "
  8.     exit 1
  9. fi
  10.  
  11. frames_to_crop=$2
  12. path_to_ffmpeg=/home/$USER/kdenlive/20110124/bin
  13.  
  14. MOV2mov()
  15. {
  16.  
  17. filename=$1
  18. # Create output path and filename
  19. outfile=$(echo $filename | cut -d. -f1)".mov"
  20. echo "Output file = "$outfile
  21. # Get clip duration
  22. duration=$(ffmpeg -i $filename 2>&1| grep Duration |sed 's/: /*/'|cut -d* -f2|cut -d, -f1)
  23. echo "duration "$duration
  24.  
  25. # Convert duration to seconds
  26. oldifs=$IFS
  27. IFS=:
  28. arr=($duration)
  29. IFS=$oldifs
  30. dursecs=$(echo ${arr[0]}*3600 + ${arr[1]}*60 + ${arr[2]} | bc)
  31.  
  32. # Convert duration to frames
  33. frames=$(echo "$dursecs * 29.97" | bc)
  34.  
  35. # Round up frames to integer
  36. frames=$(echo "($frames + 0.9999)/1" | bc)
  37. echo "Frames in clip "$frames
  38.  
  39. # Subtract frames from total
  40. ((oframes="$frames"-"$frames_to_crop"))
  41. echo "Frames to output "$oframes
  42.  
  43. # Render with ffmpeg
  44. "$path_to_ffmpeg"/ffmpeg -i $filename -vframes $oframes -vcodec copy -acodec copy $outfile
  45.  
  46. }
  47.  
  48. for i in "$1"/*.MOV ; do
  49. MOV2mov $i
  50. done
  51.  
  52. # end of file ------------------------
  53.  
  54.  
  55.  
  56. Output:-
  57. [baz@jackodesktop ~]$ MOVdir2mov /store/Video/croptest/test 4
  58. Output file = /store/Video/croptest/test/100_0008.mov
  59. duration 00:00:07.67
  60. Frames in clip 230
  61. Frames to output 226
  62. FFmpeg version git-5f3b831, Copyright (c) 2000-2011 the FFmpeg developers
  63.   built on Jan 24 2011 14:59:48 with gcc 4.4.3
  64.   configuration: --prefix=/home/baz/kdenlive/20110124 --disable-doc --disable-network --disable-ffserver --enable-gpl --enable-version3 --enable-shared --enable-debug --enable-pthreads --enable-libmp3lame --enable-libx264 --enable-libvpx
  65.   libavutil    50. 36. 0 / 50. 36. 0
  66.   libavcore     0. 16. 1 /  0. 16. 1
  67.   libavcodec   52.108. 0 / 52.108. 0
  68.   libavformat  52. 94. 0 / 52. 94. 0
  69.   libavdevice  52.  2. 3 / 52.  2. 3
  70.   libavfilter   1. 74. 0 /  1. 74. 0
  71.   libswscale    0. 12. 0 /  0. 12. 0
  72. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/store/Video/croptest/test/100_0008.MOV':
  73.   Metadata:
  74.     major_brand     : qt  
  75.     minor_version   : 0
  76.     compatible_brands: qt  
  77.     creation_time   : 2010-12-08 09:30:50
  78.     comment         : KODAK PlaySport Video Camera, Zx3
  79.     comment-eng     : KODAK PlaySport Video Camera, Zx3
  80.   Duration: 00:00:07.67, start: 0.000000, bitrate: 8611 kb/s
  81.     Stream #0.0(eng): Video: h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 8524 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
  82.     Metadata:
  83.       creation_time   : 2010-12-08 09:30:50
  84.     Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 128 kb/s
  85.     Metadata:
  86.       creation_time   : 2010-12-08 09:30:50
  87. Output #0, mov, to '/store/Video/croptest/test/100_0008.mov':
  88.   Metadata:
  89.     major_brand     : qt  
  90.     minor_version   : 0
  91.     compatible_brands: qt  
  92.     creation_time   : 2010-12-08 09:30:50
  93.     comment         : KODAK PlaySport Video Camera, Zx3
  94.     comment-eng     : KODAK PlaySport Video Camera, Zx3
  95.     encoder         : Lavf52.94.0
  96.     Stream #0.0(eng): Video: libx264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], q=2-31, 8524 kb/s, 30k tbn, 29.97 tbc
  97.     Metadata:
  98.       creation_time   : 2010-12-08 09:30:50
  99.     Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, 128 kb/s
  100.     Metadata:
  101.       creation_time   : 2010-12-08 09:30:50
  102. Stream mapping:
  103.   Stream #0.0 -> #0.0
  104.   Stream #0.1 -> #0.1
  105. Press [q] to stop encoding
  106. frame=  226 fps=  0 q=-1.0 Lsize=    7890kB time=7.51 bitrate=8609.6kbits/s    
  107. video:7766kB audio:117kB global headers:0kB muxing overhead 0.089689%
  108. [baz@jackodesktop ~]$
Add Comment
Please, Sign In to add comment