Ffmpeg: converting multimedia formats

Here is a short guide to converting audio files using ffmpeg.

Audio formats

MP3 -> MP3

This is to lower the quality of an MP3:

$ lame -b 64 source_file.mp3 destination_file.mp3

64 will be the new bitrate of the file. Any of the following values ​​can be used: 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320. The higher the bitrate, the higher the audio quality (and the higher the the file size).

MP3 -> OGG

Mp32ogg program required

$ sudo aptitude install mp32ogg

To convert

$mp32ogg music.mp3 music.ogg

To convert the whole folder

$ mp32ogg * .mp3 * .ogg

Here are some common conversions in sound files using Ffmpeg.

WMA -> MP3

After the parameter ab we will specify the bitrate MP3 (192 in the example).

$ ffmpeg -i inputFile.wma -f mp3 -ab 192 OutputFile.mp3

MP3 -> AMR

$ ffmpeg -i music.mp3 -codec amr_nb -ar 8000 -ac 1 -ab 32 music.amr

WAV -> AMR

$ ffmpeg -i music.wav -codec amr_nb -ar 8000 -ac 1 -ab 32 music.amr

MPEG -> MP3

Extract the audio from an MPEG file and convert it to MP3

$ffmpeg -i video.mpg -f mp3 audio_track.mp3

MIDI -> WAV

$ timidity -Ow -s 44100 -o output.wav input.mid

MIDI -> OGG

$ timidity -Og -s 44100 -o output.ogg input.mid

Video formats

Some common conversions in video files are listed below using Ffmpeg.

AVI -> FLV

$ ffmpeg -i movie.avi -codec mp3 -ar 11025 movie.flv

From version 9.04 you have to install the libavcodec-unstripped-52 package and replace '-acodec mp3' with '-acodec libmp3lame' in the command options.

AVI -> VCD

Adding the option -hq use high quality.

$ffmpeg -i myfile.avi -target pal-vcd myfile_vcd.mpg

AVI -> DV

This is the Digital Video format, the same format that a digital video camera produces and is the one that can be used for editing with Kino.

$ ffmpeg -i movie.avi -target pal-dv movie.dv

This gives me some audio timing errors that I don't see being noticed. If you want to avoid them, you will have to do it this way:

$ mencoder movie.avi -ovc lavc -oac pcm -o movie-new.avi $ ffmpeg -i movie-new.avi -s pal -r pal -ac 2 -ar 48000 movie.dv && rm movie-new.avi

Another way to do it:

$ ffmpeg -i movie.avi -vcodec dvvideo -acodec copy -f dv movie.dv -hq

Kino also reads the AVI format generated in this way (for example from an FLV):

$ mencoder -oac mp3lame -ovc xvid -of avi -xvidencopts bitrate = 1350 -o output.avi input.flv

AVI -> PNG

$ ffmpeg -i swing.avi -vcodec png -vframes 1 -an -f rawvideo -s 320x240 swing1.png

3GP -> MPEG4

$ ffmpeg -i movie.3gp -vcodec mpeg4 -codec mp3 movie.avi

RMVB -> AVI

$ mencoder -oac mp3lame -lameopts cbr = 128 -ovc xvid -xvidencopts bitrate = 1200 video_input.rmvb -o video_output.avi

MPEG -> 3GP

$ ffmpeg -i file.mpeg -s qcif -r 12 -ac 1 -ar 8000 -b 30 -ab 12 output.3gp

Or also with more quality:

$ ffmpeg -i file.mpeg -s qcif -r 15 -ac 1 -ar 8000 -b 256000 -ab 15 output.3gp

MPEG -> XviD

$ ffmpeg -i movie.mpg -acodec mp3 -vcodec xvid -b 687 movie.avi

MPEG -> FLV

$ ffmpeg -i movie.mpg -vcodec flv -y movie.flv

The resulting file does not contain the metadata information correctly. This implies that when you use the file in a Flash video viewer like Flash Video Player the file will look good but the progress bar will not update. To fix this use the utility flvtool2 that you will find it in http://inlet-media.de/flvtool2. It is made in Ruby so you will have to install the corresponding package. It is used like this:

$ flvtool2 -U movie.flv

We also have another utility called FLV MetaData Injector that even if it is for Windows, it works perfectly with Wine (at least the command line version). It is used like this:

$ wine flvmdi.exe movie.flv

Another way to convert to FLV format is using memory coder:

$ mencoder movie.avi -o movie.flv -of lavf -oac mp3lame -lameopts br = 32 -af lavcresample = 22050 -srate 22050 -ovc lavc -lavcopts vcodec = flv: vbitrate = 340: autoaspect: mbd = 2: trell: v4mv -vf scale = 320: 240 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames

FLV -> MPEG

$ ffmpeg -i video.flv video.mpeg

FLV -> AVI

$ ffmpeg -i video.flv video.avi

JPG -> DivX

$ mencoder -mf on: w = 800: h = 600: fps = 0.5 -ovc divx4 -o output.avi * .jpg

So it shows you a photo every two seconds, if you want every four seconds you should put 0.25 in fps.

If this command doesn't work for you, try

$ mencoder "mf: //*.jpg" -mf fps = 0.25 -vf scale = 480: 360 -o output.avi -ovc lavc -lavcopts vcodec = mpeg4

With what you will get a video of all the jpg files located in the path from which you launch the command and that shows you 1 photo every 4 seconds

Include subtitles in a video

$ mencoder -ovc lavc -oac mp3lame movie.avi -o movie_with_subtitles.avi -sub subtitles.srt

Convert a video to OGV Theora format

Ogg Theora is the video codec pre-installed by default in Ubuntu, so you will not need to install any codec pack to play them in Ubuntu (that's the advantage of theora). Below are some examples of video conversions using ffmpeg2theoraTo install it, we open a terminal (applications> accessories> terminal) and write:

$ sudo aptitude install ffmpeg2theora

Ffmpeg2theora is a command program (not graphic), so everything is used from the terminal, the video you want to convert must be in the user's home folder.

any video format -> Ogg Theora

$ ffmpeg2theora video clip.extension

this will create an Ogv Theora file called video clip.ogv. To encode it with another quality, let's say video quality: 7 and audio quality: 3:

$ ffmpeg2theora -v 7 -a 3 video clip.extension

you can also use the v2v Presets to encode your video

$ ffmpeg2theora -p preview video clip.dv

o

$ ffmpeg2theora -p pro video clip.dv

that the encoding of the video starts from the second 10 and ends in the second minute of the video

$ ffmpeg2theora -s 10 -e 120 video clip.extension

that the video britrate is 512 and the audio 96

$ ffmpeg2theora -V 512 -A 96 video clip.extension

the video is resized to 640 × 480

$ ffmpeg2theora -x 640 -y 480 video clip.extension

optimize video size

$ ffmpeg2theora --optimize video clip.extension

specify output name (video already encoded)

$ ffmpeg2theora -o alternate-name video clip.extension

as is obvious you can use the previous commands in a single line

$ ffmpeg2theora -s 10 -e 120 -V 512 -A 96 x 640 -y 480 --optimize -o alternative-name video clip.extension

Check the result

If the target format is not supported by the media player Totem you can use the application ffplay what comes in the package ffmpeg, it will play any format supported by ffmpeg. This is useful, for example, for the AMR mobile audio format.

Other converters

  • Convert for free video files direct to your mobile phone, iPod, PSP, PC It is an online conversion service, so you don't have to have anything installed on your PC.
  • Zamzar Another free online format converter. It allows converting both documents and audio and video.
  • filsh And another online format converter!
  • Mobile Media Converter It is a multiplatform converter with a fairly simple graphical interface. Works with one version Ffmpeg compiled to support additional formats.
  • Edge Transcoder It is a new project that greatly facilitates the conversion of video formats, especially. Graphically it is very nice, although it is not yet packaged for Ubuntu and if you want to try it you will have to do it the old way.
  • Convert Files Convert Files is a new online file conversion service. It is one more option that users have when choosing a service that allows us to enter a file in a specific format so that it can be converted into another file in the same or in another format within the same category.
  • Cometdocs It is a powerful multipurpose online converter that works with more than 50 different formats, allowing you to carry out all kinds of conversions directly from the browser, without the need to install absolutely anything, and completely free of charge.

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Germaine said

    Thank you ... I did not know everything that such a simple but powerful program could do, every day I am more convinced of my decision to switch to Linux (I have OpenSuse 12.2)

  2.   Juan Escobar Arias placeholder image said

    What video editor is the one seen in the photo?

    1.    kike said

      It's called «Cinelerra»

  3.   Let's use Linux said

    Thank you! Regards!

  4.   eM Say eM said

    I take my hat off to such a beautiful topic and valuable information, I have to comment that yesterday 12-12-2011 I was looking for how to change video formats and I came across information from Ffmpeg, after reading I see its true power and today I find this topic with detailed information.
    Excellent topic

  5.   Daniel said

    Another headache healed by this blog. The best on the Internet, without a doubt.

    1.    let's use linux said

      Thanks Dani.
      Hug! Paul.