FFmpeg Tips & Trick

According to it's official site, FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. I personally use it for doing video conversion for my mobile phone and dvd player. I made some bash scripts that can help us to work with those tasks.

cut-video.sh
#!/bin/bash

ffmpeg -i "$1" -sameq -acodec copy -vcodec copy -ss "$2" -t "$3" "cutted-$1"
How To Use:
cut-video.sh videofile startpos length

Example:
$ cut-video.sh video.mp4 00:00:00 00:05:00

The example told the script to cut video.mp4 start from beginning for five minutes length. The result will saved on same directory with "cutted-" prefix.

mp4-mobile.sh
#!/bin/bash

ffmpeg -i "$1" -s 480x320 -aspect 4:3 -r 15 -b 512k -ab 128k -ac 2 -ar 44100 -acodec aac -vcodec mpeg4 -strict experimental "$2"
Note: Make sure to put all ffmpeg syntax above in one line! I put it that way only for display purpose.

How To Use:
mp4-mobile.sh videofile resultfile

Example:
$ mp4-mobile.sh whatever.flv resultvideo.mp4

The example told the script to convert video from whatever.flv (or any other ffmpeg supported format) to resultvideo.mp4 (MP4 Format). I use this script to convert any video for my Samsung GALAXY Spica (Android) Video Player.

You may change the script parameter as you wish i.e. changing to higher resolution, aspect or video and audio quality. But make sure your player is capable to play it!

As you notice, I use experimental (free) AAC audio encoder (considering that libfaac is not free anymore) so that's why we have to use -strict experimental option.

mp4-dvd.sh
#!/bin/bash

ffmpeg -i "$1" -s 480x320 -aspect 4:3 -r 25 -b 512k -ab 128k -ac 2 -ar 44100 -acodec ac3 -vcodec libxvid "$2"
Note: Make sure to put all ffmpeg syntax above in one line! I put it that way only for display purpose.

How To Use:
mp4-dvd.sh videofile resultfile

Example:
$ mp4-dvd.sh anyvideo.avi dvdvideo.mp4

The example told the script to convert video from anyvideo.avi (or any other ffmpeg supported format) to dvdvideo.mp4 (MP4 DVD Format/DivX Compatible). I use this script to convert any video for my LG DVD/MP4/DivX Player (should work with another DVD/MP4/DivX player too). Just burn all converted files in one DVD and play them on your player.

Again, you may change the script parameter as you wish i.e. changing to higher resolution, aspect or video and audio quality. But don't change video and audio codec parameter, also make sure your player is capable to play it!

Don't forget to make all of those script executable and available on system path and of course you should have fully functional FFmpeg on your system.