Videos, Audios Help using Linux Command Line

Videos, Audios Help using Linux Command line

Converting mp4 to flv using ffmpeg

To convert a mp4 file to flash video, type:

# ffmpeg -i “thistime.mp4” -ar 44100 -ab 96 -f flv “thistime.flv”

Getting Video Information using ffmpeg

To get information about a video file, type:

# ffmpeg -i Demi\ Lovato\ ++\ Skyscraper.mp4

Duration: 00:04:05.74, start: 0.000000, bitrate: 2657 kb/s
Stream #0.0(und): Video: h264, yuv420p, 1920×1080, 2500 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 148 kb/s

# ffmpeg -i skycraper_cover.avi

Duration: 00:04:40.88, start: 0.000000, bitrate: 407 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 854×480 [PAR 1:1 DAR 427:240], 25 tbr, 25 tbn, 25 tbc
Stream #0.1: Audio: mp2, 44100 Hz, 2 channels, s16, 64 kb/s
At least one output file must be specified

Anatomy of a VOB FIle

What is VOB?

VOB standards for “Video Object”. It is the file type to store video on a DVD disc. It is actuallly a MPEG-2 video, with special extension to support PCM, AC3, DTS audio, subpictures, and button navigation commands.

To decode DVD-VIDEO, you will need both GPL MPEG-2 Decoder, and AC-3 Decoder.

Each VOB file on the DVD may contain multiple videos. Each video may span over multiple VOB files.

This picture below makes it easier to understand.

Use mpg123 to Play mp3 in Linux

Download and install mpg123 to play mp3 files:

#apt-get install mpg123

# mpg123 Lady\ Antebellum\ -\ Just\ a\ Kiss.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
version 1.12.1; written and copyright by Michael Hipp and others
free software (LGPL/GPL) without any warranty but with best wishes

Playing MPEG stream 1 of 1: Lady Antebellum – Just a Kiss.mp3 …
Title:   Just a Kiss                     Artist: Lady Antebellum
Album:   Just a Kiss – Single
Year:    2011                            Genre:  Country
MPEG 1.0 layer III, 320 kbit/s, 44100 Hz joint-stereo

Making Movies from Images Using fmmpeg

Create a folder where you store the images. Make sure you rename the images like 001.jpg, 002.jpg and so on.

Then run the following command:

# ffmpeg -r 1 -b 1800 -i %03d.jpg test1800.mp4

You can change the value of -r. This is the frame per second parameter. -r 1 means 1 frame per second. If you put -r 10, then this will becomes 10 frames per second! The movie will be very fast. This will provide delay to the output video file. A sort of transition delay from one image to the other.

Play the video file using any video player.

The following command also work

# ffmpeg -r 1 -f image2 -i image%d.png video.mp4

In this case your image filename must be formatted as image1.png.

The following also works.

# ffmpeg -r 1 -f image2 -i image%d.png video.avi

Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3

Explanations :

  • Source video : source_video.avi
  • Audio bitrate : 192kb/s
  • output format : mp3
  • Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv

Or:

ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg

Explanations :

  • target pal-dvd : Output format
  • ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
  • aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg

Ripping Audio from VOB File

Using vobcopy, you can rip vob files from DVDs. To extract the audio from a DVD/VOB file, type:

# mplayer -vo null -vc dummy -ao pcm -ao pcm: 2channels.wav VTS_03_2.VOB -aid 128

The rename the file

# mv audiodump.wav audiomyvob.wav

Ripping wav file from vob file

To extract wav file from a vob/dvd file, type:

# mplayer -vo null -aid 128 -ao pcm:file=vob2wav.wav VTS_03_2.VOB

The following will extract the audio into ac3 format, but it does not dump the file. It simply play in ac3 format:

# mplayer -vo null -nogui -dumpaudio -dumpfile vob2ac3.ac3 VTS_03_2.VOB

Extracting Audio from mpg and avi file

    • MPG -> MP2: mplayer -vo null -nogui -dumpaudio -dumpfile audio.mp2 myvideo.mpg
      This will extract the audio to a file called audio.mp2.

  • AVI -> WAV: mplayer -vo null -nogui -ao pcm -aofile audio.wav myvideo.avi
    This will extract the audio, convert it to PCM and write the resulting .WAV to audio.wav.

Extracting Audio from Flash videos

To extract audio from flash videos, type

#ffmpeg -i thevideoinflv.flv yoursongtitle.mp3

The preceding command only works if the flash video was encoded in mp3 format. You can find out what audio encoder is being used by typing:

#ffmpeg -i thevideoinflv.flv

At the bottom of the output you should see the audio encoder like this:

Stream #0.1: Audio: aac, 44100 Hz, stereo, s16, 131 kb/s

In my case as shown above, it is encoded using AC3 and not MP3. So to extract the audio from such video, you will have to use the AC3 encoder and at the same time specify the bit rate as shown below:

ffmpeg -i someflashvideo.flv -acodec ac3 -ab 192k yourchoicefilename.mp3

That’s it. You can play the mp3 file using any media player.

Installing vobcopy

vobcopy is use to copy vob/DVD files

#apt-get install vobcopy

Converting wav file to mp3

You can use ffmpeg. Type the following:

ffmpeg -i your_wav_file.wav newfile.mp3

You can also include the bitrate

ffmpeg -i your_wav_file.wav -b 192k newfile.mp3

In my case, I had no luck in using the ffmeg command. Thus I use lame command.

If you do not have lame, install it by typing:

apt-get install lame

After that use lame command to covert wav to mp3

#lame -V2 wavefile.wav newfile.mp3

I tried again using ffmpeg, but this time I use ac3 as the encoder

# ffmpeg -i childrensong.wav –acodec ac3 -ab 192k childrensongffmpeg.mp3

Note that running the following command will give you a list of the codecs and formats that ffmpeg can work with:

$ ffmpeg -formats

Converting flv to mpg

After you have downloaded the flv from YouTube, read the details of the flv fileL

# ffmpeg -i The-Wanted-Lightning\[www.savevid.com\].flv

Stream #0.0: Video: h264, yuv420p, 854×480, 739 kb/s, 25 tbr, 1k tbn, 50 tbc
Stream #0.1: Audio: aac, 44100 Hz, stereo, s16, 129 kb/s

convert the flv to mpg by typing:

# ffmpeg -i The-Wanted-Lightning\[www.savevid.com\].flv -target ntsc-dvd -aspect 4:3 WantedLightning.mpg

Now read the file format of the mpg

# ffmpeg -i WantedLightning.mpg

Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720×480 [PAR 8:9 DAR 4:3], 9000 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0.1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 448 kb/s

Explanations:

  • -target ntsc-dvd
    “-target” is one of the most useful options of ffmpeg. It instructs ffmpeg to just “do what it takes” for the target file to be usable on an NTSC DVD-Video in this case (there are other pre-defined targets). This includes selecting the correct audio and video codecs, appropriate bit rates, image size, frame rate and other parameters. Indeed, if we look at the lines in the “Output #0″ section of the output above, we see that the video is set to MPEG2 video, yuv420p color encoding, 720×480 pixel image size, 6 mbit/s bit rate, 29.97 frames per second (the q=2-31 part is the admissible quality levels, 2, the best, to 31). The audio stream is ac3-encoded with a sampling rate of 48 KHz, mono at 448 kbit/s. These are standard parameters for a DVD-Video with a mono soundtrack and can be overridden.
  • -aspect 4:3
    MPEG2 video allows for anamorphic display. This means that the aspect ratio (width divided by the height) of the physical picture displayed on-screen can be different from the ratio obtained by dividing the pixel-width of the image by its pixel-height. This has to be built in to the video specification used with DVDs because, regardless of whether we’re viewing a movie in old 4:3 aspect ratio or a movie in 16:9 widescreen format, the pixel size of the digital image is still 720×480 for an NTSC DVD (720×576 for PAL). The image is in fact stretched such that its aspect ratio is as specified by the “-aspect” option. This usually involves stretching it only along its width or along its height, hence the name “anamorphic”.

Let’s transcode it to MPEG4, bring the picture size back down to 320×240 and the frame rate down to 10 fps, see if we can drop the video bit rate to 300 kbit/s, and convert the AC3-encoded, 48000 Hz, 448 kbit/s audio to MP3, 22050 Hz, 64 kbit/s:

Convert from mpg to avi with audio codec ac3 and video codec mpeg4

# ffmpeg -i WantedLightning.mpg -vcodec mpeg4 -s 320×240 -b 300k -r 10 -acodec ac3 -ar 22050 -ab 64k -f avi WantedLightning.avi

This will produce a smaller resolution file, and thus smaller file size. When playback it is pixelated.

  • The “-target” option tells ffmpeg to set a whole bunch of parameters automatically in order to comply with standards related to the specified target. The list of predefined automatic targets is available in the man page for ffmpeg.
  • The parameters defined automatically with a “-target” option can be overridden manually or can all be set manually if the “-target” option isn’t used at all.
  • The video codec is selected with the “-vcodec” option, the picture size with the “-s” option, the video bitrate with “-b” and the frame rate with “-r”.
  • The “-f” option selects the container format. “ffmpeg -formats” lists the available formats.

The following uses mpeg4 video codec and high resolution but the frame rate (fps – frames per second) -r is low 10. The output will be pixelated.

# ffmpeg -i WantedLightning.mpg -vcodec mpeg4 -s 720×480 -b 300k -r 10 -acodec ac3 -ar 22050 -ab 64k -f avi WantedLightningmpeg4.avi

-b refers to video bit rate e,g sharp ones go as high as 2000k

-r refers to frames per second (fps) good ones are 24

I convert another flv file to avi using video codec, mpeg2video, with fps 24 and video bit rate of 2000k

# ffmpeg -i The-Wanted-Lightning\[www.savevid.com\].flv -vcodec mpeg2video -s 720×480 -b 2000k -r 24 -acodec ac3 -ar 22050 -ab 64k -f avi WantedLightning_flvtompeg2_720x480_vbr2000kfps24.avi

Option to take note in ffmpeg is -target

-target type
Specify target file type (“vcd”, “svcd”, “dvd”, “dv”, “dv50”, “pal-
vcd”, “ntsc-svcd”, … ). All the format options (bitrate, codecs,
buffer sizes) are then set automatically. You can just type:

ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg

Each audio format intended for DVD has different compression ratio and quality. There are three main types of audio: AC3 (Dolby Digital), PCM (uncompressed), and MP2 (MPEG Layer II). The most common quality of audio in DVD is 48hz (frequency), with Dolby Digital 5.1 (surround sound).

AC3

It’s a Dolby Digital Audio. AC3 supports not only stereo, but also surround. Audio bitrate range: from 128Kbit/s to 384Kbit/s. 192Kbit/s is the most common bitrate.
Surround sound must have at least 6 separate source channels. Taking a stereo or mono audio file and forcing it into Dolby 5.1 format will only waste space and provide no advantages.
Pros:  AC3 format has very good quality, surround sound support and very high level of compression. That’s why the size of audio information is small.

AC3 is the best format to use in DVD

PCM

Cons:  The main disadvantage of Uncompressed PCM (WAV or AIFF) audio format is size. It stores all audio information without compression. It’s a recommended format for audio editing. Do not use PCM in final versions of DVD. Only leave it as PCM if final disc size is unimportant or if unusual distortion occurs from AC3 or MP2 compression. Common bitrate is 1536k.
Pros:  The main advantage of the PCM audio is excellent quality. With PCM you can preserve all audio frequencies (even outside the range of human hearing).

MP2

Another form of MPEG audio is MP2. Also known as MPEG Layer II and .mpa files. This format is not officially supported for NTSC video. If you have MP2 audio then do not recompress it to AC3, recompression may destroy the quality. So, leave it untouched. But if you have PCM uncompressed source, I definitely recommend to use AC3 instead of MP2. Common bitrate is 256Kbit/s.
Pros:  The main advantage of MP2 is good compression level and ease of audio conversion from SVCD or VCD.
Cons:  The main disadvantage of MP2 is not very good quality, and lack of support by all devices.

Using Audacity to Change Sampling Rate of MP3

Open the mp3 file using Audacity and look at the bottom left hand corner, and locate Project Rate. Select the rate you want and after that export the file to mp3.

Convert AC3 to MP3 Using ffmpeg

To convert ac3 to mp3 use:

ffmpeg -i raihan.mp3 -acodec libmp3lame output.mp3

Don’t get confuse eventhough raihan.mp3 is a mp3 file, in reality the audio part is a ac3. This is proved by typing:

ffmpeg -i raihan.mp3

Stream #0.0: Audio: ac3, 44100 Hz, stereo, s16, 192 kb/s

You see the audio part is in fact ac3 .

You have to use the audio codec libmp3lame which can be install by typing

apt-get install apt-get install libavcodec-extra-52

So with the libmp3lame codec you can now convert the ac3 to mp3.

After the conversion, check the information of the newly created mp3 file, by typing

ffmpeg -i output.mp3

Stream #0.0: Audio: mp3, 44100 Hz, 2 channels, s16, 64 kb/s

Yes now the Audio is mp3 not AC3. This is useful because certain media player cannot play ac3 files and you have to do the necessary conversion.

Increase Audio Volume in Flash Videos Using ffmpeg

ffmpeg -i input.flv -vol 1280 -vcodec copy output.flv



This entry was posted in ac3, audio, dvd, ffmpeg, flv, lame, mp3, mpeg, mplayer, video, vob, vobcopy, wav. Bookmark the permalink.

Leave a comment