Convert Flash Videos on a directory to MP4


/ Published in: Bash
Save to your folder(s)

This will convert videos to MP4 that's optimized and plays on my phone. The said videos should be stored on a directory so this script could parse them.

Requires unstripped codecs from the Medibuntu repository (libavcodec-unstripped-52, libavdevice-unstripped-52, libavformat-unstripped-52, etc.) which contains the MP4 and libfaac Encoders. See: http://ubuntuforums.org/showthread.php?t=1117283 and http://www.medibuntu.org/repository.php

This script also requires the libnotify1 package for the notify-send command (or you can just echo it, instead of using the desktop notification daemon)

Update the ffmpeg statement as needed, check the documentation at http://www.ffmpeg.org/ffmpeg-doc.html


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. ############################################################
  4. ## License: Public Domain
  5. ## Author: Dax Solomon Umaming
  6. ##
  7. ## Save in ~/bin then execute on a directory
  8. ## with the videos you wish to convert
  9. ##
  10. ## Take note that you'll need ffmpeg restricted libraries
  11. ## On Ubuntu, you can download and install them from the
  12. ## Medibuntu Repository at http://medibuntu.org/
  13. ## check the howtos for instruction on how to install them
  14. ## you'll need the *-unstripped and *-extra libraries
  15. ##
  16. ## You'll also need to have libnotify1 package installed
  17. ## Since ffmpeg already outputs tons of messages on the
  18. ## terminal, the messages this script outputs will only
  19. ## be readable (or even usable) using the desktop
  20. ## notification daemon
  21. ##
  22. ############################################################
  23.  
  24. # get filenames in a directory
  25. for origfilename in *
  26. do
  27.  
  28. # skip mp4 files, since that is - afterall - our target file format
  29. if expr "$origfilename" : "\(.*\.[Mm][Pp]4$\)" > /dev/null 2>&1
  30.  
  31. then echo "Skipping $origfilename"
  32.  
  33. # process non-mp4 files
  34. else
  35. # placeholder to be utilized by the array
  36. newfilename=$origfilename
  37.  
  38. # set video file extensions in an array
  39. vidextensions=(flv avi mkv 3gp ogv m4v f4v)
  40.  
  41. # remove above-declared extensions from the file name
  42. for vidext in "${vidextensions[@]}"
  43. do
  44. newfilename=`echo $newfilename|sed 's/\.'${vidext[@]}'$//g'`
  45. done
  46.  
  47. # convert video files to mp4 format
  48. notify-send "Converting $origfilename to mp4"
  49. ffmpeg -i "$origfilename" -acodec libfaac -ac 2 -vcodec mpeg4 -r 25 -s qvga -metadata title="$newfilename" "$newfilename.mp4"
  50.  
  51. fi
  52.  
  53. done
  54. notify-send "Done converting all videos to MP4"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.