Multimedia conversions 4 newbies [FFmpeg]

Homitsu
  9 years ago
  8

- INTRO -

FFmpeg is a free software project that produces libraries and programs for handling multimedia data. The most notable parts of FFmpeg are libavcodec, an audio/video codec library used by several other projects, libavformat, an audio/video container mux and demux library, and the ffmpeg command line program for transcoding multimedia files. FFmpeg is published under the GNU Lesser General Public License 2.1+ or GNU General Public License 2+ (depending on which options are enabled).
 
The official site of FFmpeg is http://ffmpeg.org/index.html. There you can find a huge documentation about the software and the best way to use it.
 
If you are a newbie it's not a a good idea to use FFmpeg command lines to convert your video collection. Conversion operations are always very long and find that you've missed a parameter after working hours and having to redo everything is annoying. Very annoying ...
 
For a "quick and dirty" work you can use Arista. For best results, Handbrake is the best conversion software ever [IMHO].
 
But with FFmpeg you can quick launch some useful trick for your everyday multimedia life.
 
Let's play.

- WHAT YOU NEED TO KNOW -

To understand this tutorial you must know:
  • how to open a terminal.
I assume that all files we'll treat are in your home folder.

- TO INSTALL FFMPEG -

sudo apt-get install ffmpeg
You shoul'd not need to add any repo. FFmpeg is in the repos of all the major distros [Mint included].

- TO KNOW A LOT OF INFOS ABOUT A VIDEO FILE -

ffmpeg -i myvideo.avi
Of course the suffix of file must be the same of the file you want to analyze and not always .avi.

- TO CREATE A JPEG FROM EVERY FRAME OF A VIDEO -

ffmpeg -i video.avi image%d.jpg
If you want to try this, work inside a specific folder or you'll fill your home with thousands of jpeg.

- TO CREATE A VIDEO FROM A SERIES OF JPEG -

ffmpeg -f image2 -i imagepercent03d.jpg myvideo.mpg
Note the parameter imagepercent03d.jpg. You must type in terminal % and not percent [I must use this trick beacuse editor misunderstand the combination %zerosometing]. This one works on files named "image001.jpg", "image002.jpg", "image999.jpg". You can adjust it to your need. For example %d is good for images named image1.jpg, image2.jpg, etc. Jpeg are the most common type, but you can work with every kind of bitmap file.
 
The command is really useful if you're working on a stopmotion video and want a quick test. We can do more, setting fps and bitrate this way.
ffmpeg -r 24 -b 1800 -i image%d.jpg myvideo.mpg
-r 24 means "24 frames per second" and -b 1800 means "video bitrate at 1800 kb/s".

- TO EXTRACT THE AUDIO TRACK FROM A VIDEO AND SAVE IT MP3 -

ffmpeg -i myvideo.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 myaudio.mp3
This means:
  • Original video: myvideo.avi
  • Sampling frequency: 44100 Hz
  • Audio bitrate: 192 kb / s
  • Output Format: mp3
  • Audio generated: myaudio.mp3

The quick&dirty version is:

ffmpeg -i myvideo.avi myaudio.mp3

- TO CONVERT A VIDEO FROM FORMAT A TO FORMAT B -

ffmpeg -i originalvideo.avi convertedvideo.mpg
Here we are converting an AVI file into an MPEG one [quick&dirty mode = ON].

- TO QUICK CONVERT A VIDEO TO iPhone -

This is good for 4:3 videos.
ffmpeg -i originalvideo.avi -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 convertedvideo.mp4
Change -aspect 4:3 to -aspect 16:9 if you are working on a 16:9 video.

- TO CONVERT A VIDEO TO iPad -

When the going gets tough, the toughs get going! Don't fear, just sneak where the files names are and the -aspect parameter.
ffmpeg -y -i originalvideo.avi -acodec aac -ar 48000 -ab 128k -ac 2 -s 1024×768 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 convertedvideo.mp4

- TO QUICK CONVERT A VIDEO TO WEBM -

ffmpeg -i originalvideo.avi convertedvideo.webm
WebM is an audio-video format designed to provide a royalty-free, open video compression format for use with HTML5 video. The project's development is sponsored by Google.

- TO CAPTURE SCREEN AND MIC - 

ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 10 -i :0.0 -sameq -f mp4 -s wvga -y mydesktopmovie.mp4
With this one you can capture screen and mic input using FFmpeg and ALSA.

- MAIN REFERENCES - 

FFmpeg official site- INTRO -
FFmpeg is a free software project that produces libraries and programs for handling multimedia data. The most notable parts of FFmpeg are libavcodec, an audio/video codec library used by several other projects, libavformat, an audio/video container mux and demux library, and the ffmpeg command line program for transcoding multimedia files. FFmpeg is published under the GNU Lesser General Public License 2.1+ or GNU General Public License 2+ (depending on which options are enabled).
Wikipedia http://en.wikipedia.org/wiki/FFmpeg
 
The official site of FFmpeg is http://ffmpeg.org/index.html. There you can find a huge documentation about the software and the best way to use it.
 
If you are a newbie it's not a a good idea to use FFmpeg command lines to convert your video collection. Conversion operations are always very long and find that you've missed a parameter after working hours and having to redo everything is annoying. Very annoying ...
 
For a "quick and dirty" work you can use Arista. For best results, Handbrake is the best conversion softare ever [IMHO].
 
But with FFmpeg you can quick launch some useful trick for your everyday multimedia life.
 
Let's play.
 
- WHAT YOU NEED TO KNOW -
To understand this tutorial you must know:
how to open a terminal.
 
I assume that all files we'll treat are in your home folder.
 
- TO INSTALL FFMPEG -
sudo apt-get install ffmpeg
 
You shoul'd not need to add any repo. FFmpeg is in the repos of all the major distros [Mint included].
 
- TO KNOW A LOT OF INFOS ABOUT A VIDEO FILE -
ffmpeg -i myvideo.avi
Of course the suffix of file must be the same of the file you want to analyze and not always .avi
 
- TO CREATE A JPEG FROM EVERY FRAME OF A VIDEO -
ffmpeg -i video.avi image%d.jpg
If you want to try this, work inside a specific folder or you'll fill your home with thousands of jpeg.
 
- TO CREATE A VIDEO FROM A SERIES OF JPEG -
ffmpeg -f image2 -i imaged.jpg myvideo.mpg
 
Note the parameter imaged.jpg. This one works on files named "image001.jpg", "image002.jpg", "image999.jpg". You can adjust "" to your need. For example %d is good for images named image1.jpg, image2.jpg, etc. Jpeg are the most common type, but you can work with every kind of bitmap file.
 
The command is really useful if you're working on a stopmotion VIDEO and want a quick test. We can do more, setting fps and bitrate this way.
ffmpeg -r 24 -b 1800 -i image%d.jpg myvideo.mpg
-r 24 means "24 frames per second" and -b 1800 means "video bitrate at 1800 kb/s".
 
- TO EXTRACT THE AUDIO TRACK FROM A VIDEO AND SAVE IT MP3 -
ffmpeg -i myvideo.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 myaudio.mp3
This means:
Original video: myvideo.avi
Sampling frequency: 44100 Hz
Audio bitrate: 192 kb / s
Output Format: mp3
Audio generated: myaudio.mp3
The quick&dirty version is:
ffmpeg -i myvideo.avi myaudio.mp3
 
- TO CONVERT A VIDEO FROM FORMAT A TO FORMAT B -
fmpeg -i originalvideo.avi convertedvideo.mpg
Here we are converting an AVI file into an MPEG one. In this tutorial I'll not write commands more complex than this one. If you want to fine tune your conversion, use Handbrake or wait for [read: help me with] a FFmpeg advanced tut.
 
- TO QUICK CONVERT A VIDEO TO iPhone -
This is good for 4:3 videos.
ffmpeg -i originalvideo.avi -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 convertedVIDEO.mp4
Change -aspect 4:3 to -aspect 16:9 if you are working on a 16:9 video.
 
- TO QUICK CONVERT A VIDEO TO iPad -
When the going gets tough, the toughs get going! Don't fear, just sneak where the files names are and the -aspect parameter.
ffmpeg -y -i originalvideo.avi -acodec aac -ar 48000 -ab 128k -ac 2 -s 1024×768 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 convertedvideo.mp4
 
- TO QUICK CONVERT A VIDEO TO WEBM -
ffmpeg -i originalvideo.avi convertedvideo.webm
WebM is an audio-video format designed to provide a royalty-free, open video compression format for use with HTML5 video. The project's development is sponsored by Google.
 
- TO CAPTURE SCREEN AND MIC - 
ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 10 -i :0.0 -sameq -f mp4 -s wvga -y mydesktopmovie.mp4
With this one you can capture screen and mic input using FFmpeg and ALSA.
 
- MAIN REFERENCE - 
FFmpeg official site- INTRO -
FFmpeg is a free software project that produces libraries and programs for handling multimedia data. The most notable parts of FFmpeg are libavcodec, an audio/video codec library used by several other projects, libavformat, an audio/video container mux and demux library, and the ffmpeg command line program for transcoding multimedia files. FFmpeg is published under the GNU Lesser General Public License 2.1+ or GNU General Public License 2+ (depending on which options are enabled).
Wikipedia http://en.wikipedia.org/wiki/FFmpeg
 
The official site of FFmpeg is http://ffmpeg.org/index.html. There you can find a huge documentation about the software and the best way to use it.
 
If you are a newbie it's not a a good idea to use FFmpeg command lines to convert your video collection. Conversion operations are always very long and find that you've missed a parameter after working hours and having to redo everything is annoying. Very annoying ...
 
For a "quick and dirty" work you can use Arista. For best results, Handbrake is the best conversion softare ever [IMHO].
 
But with FFmpeg you can quick launch some useful trick for your everyday multimedia life.
 
Let's play.
 
- WHAT YOU NEED TO KNOW -
To understand this tutorial you must know:
how to open a terminal.
 
I assume that all files we'll treat are in your home folder.
 
- TO INSTALL FFMPEG -
sudo apt-get install ffmpeg
 
You shoul'd not need to add any repo. FFmpeg is in the repos of all the major distros [Mint included].
 
- TO KNOW A LOT OF INFOS ABOUT A VIDEO FILE -
ffmpeg -i myvideo.avi
Of course the suffix of file must be the same of the file you want to analyze and not always .avi
 
- TO CREATE A JPEG FROM EVERY FRAME OF A VIDEO -
ffmpeg -i video.avi image%d.jpg
If you want to try this, work inside a specific folder or you'll fill your home with thousands of jpeg.
 
- TO CREATE A VIDEO FROM A SERIES OF JPEG -
ffmpeg -f image2 -i imaged.jpg myvideo.mpg
 
Note the parameter imaged.jpg. This one works on files named "image001.jpg", "image002.jpg", "image999.jpg". You can adjust "" to your need. For example %d is good for images named image1.jpg, image2.jpg, etc. Jpeg are the most common type, but you can work with every kind of bitmap file.
 
The command is really useful if you're working on a stopmotion VIDEO and want a quick test. We can do more, setting fps and bitrate this way.
ffmpeg -r 24 -b 1800 -i image%d.jpg myvideo.mpg
-r 24 means "24 frames per second" and -b 1800 means "video bitrate at 1800 kb/s".
 
- TO EXTRACT THE AUDIO TRACK FROM A VIDEO AND SAVE IT MP3 -
ffmpeg -i myvideo.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 myaudio.mp3
This means:
Original video: myvideo.avi
Sampling frequency: 44100 Hz
Audio bitrate: 192 kb / s
Output Format: mp3
Audio generated: myaudio.mp3
The quick&dirty version is:
ffmpeg -i myvideo.avi myaudio.mp3
 
- TO CONVERT A VIDEO FROM FORMAT A TO FORMAT B -
fmpeg -i originalvideo.avi convertedvideo.mpg
Here we are converting an AVI file into an MPEG one. In this tutorial I'll not write commands more complex than this one. If you want to fine tune your conversion, use Handbrake or wait for [read: help me with] a FFmpeg advanced tut.
 
- TO QUICK CONVERT A VIDEO TO iPhone -
This is good for 4:3 videos.
ffmpeg -i originalvideo.avi -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 convertedVIDEO.mp4
Change -aspect 4:3 to -aspect 16:9 if you are working on a 16:9 video.
 
- TO QUICK CONVERT A VIDEO TO iPad -
When the going gets tough, the toughs get going! Don't fear, just sneak where the files names are and the -aspect parameter.
ffmpeg -y -i originalvideo.avi -acodec aac -ar 48000 -ab 128k -ac 2 -s 1024×768 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 convertedvideo.mp4
 
- TO QUICK CONVERT A VIDEO TO WEBM -
ffmpeg -i originalvideo.avi convertedvideo.webm
WebM is an audio-video format designed to provide a royalty-free, open video compression format for use with HTML5 video. The project's development is sponsored by Google.
 
- TO CAPTURE SCREEN AND MIC - 
ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 10 -i :0.0 -sameq -f mp4 -s wvga -y mydesktopmovie.mp4
With this one you can capture screen and mic input using FFmpeg and ALSA.
 
- MAIN REFERENCE - 
FFmpeg official site