/ ENGLISH / WORK / VIDEO

FFmpeg Tips & Trick

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" "cut-$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 starts from the beginning for five minutes. The result will be saved on the same directory with the “cut-“ 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"

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 and 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"

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 the 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.