Five ffmpeg commands every video geek should know about

FFmpeg is a leading multimedia framework which offers command line utilities to deal with video, audio and image files. Having some experience with FFmpeg, I can truly say that it is a great framework which can be utilized by the heavy computer geek to process their multimedia files. Not only is the FFMpeg multimedia framework free of charge, but it is also open source, which means that those who have some coding experience in the C programming language can study its components and also customize them based on their specific needs.

There are many commandline utilities offered by the FFMpeg multimedia framework such as ffmpeg, ffprobe, ffplay and ffserver. Based on my personal experience with the FFmpeg multimedia framework, each one of the utilities being offered by it has a specific role. For example the ffprobe utility is mostly being used to gather information on the multimedia files such as their number of streams and format. On the other hand, the ffmpeg utility is being used to do the heavy processing of the multimedia files such as conversion from one format to another.

With the main purpose of keeping things practical, I highly recommend that you launch a console on your own operating system so you can run the commands shared through this article by yourself.

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

The first command which we are going to explore, is found in the ffprobe utility which comes shipped by default within the FFMpeg multimedia framework.

Once you have managed to launch a new console on your own operating system, run the following command on a video file .

ffprobe -show_format test.mp4

Once the above command got executed on my interactive console, I got the following output.

[FORMAT]
filename=test.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=312.866000
size=42861126
bit_rate=1095961
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:encoder=Lavf57.56.100
[/FORMAT]

As you can see from the above output, the command ffprobe -show_format gathers specific information on the video container format such as the number of streams, the bit rate of the multimedia file, the size and also its duration in seconds.

A very useful command to the video geek, part of the ffprobe utility, is the one which finds specific information on each stream that the multimedia file is composed of.

The following example, makes use of the command ffprobe -show_streams. Make sure to run it on your console the exact way like it is shown below.

ffprobe -show_streams test.mp4

Once the above command got executed on my console, the following output was displayed.

[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=avc1
codec_tag=0x31637661
width=1280
height=720
coded_width=1280
coded_height=720
has_b_frames=2
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=31
color_range=N/A
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/24000
start_pts=0
start_time=0.000000
duration_ts=7507512
duration=312.813000
bit_rate=965808
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=7500
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=VideoHandler
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/44100
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=2
channel_layout=stereo
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=0
start_time=0.000000
duration_ts=13796332
duration=312.841995
bit_rate=125225
max_bit_rate=128000
bits_per_raw_sample=N/A
nb_frames=13474
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=SoundHandler
[/STREAM]

As you can see from the above output, the command which we executed, gathered specific information on each one of streams that the video file named test.mp4 is composed of.

The specific information for each one of the streams is being stored inside the [STREAM], [/STREAM] tags.

Based on the above output, one can easily understand that each one of the streams has a specific index. The first stream has an index of zero, the second one has an index of one.

The above information gives information on the type of stream too. For example the first stream which has an index of zero is of type video. One can easily understand it by taking a look at the codec_type.

[STREAM]
index = 0
.........
.........
............
codec_type = video
[/STREAM]

On the other hand, the second stream has a different index and it is of type audio.

[STREAM]
index = 1
.........
.........
............
codec_type = audio
[/STREAM]

Long story short, the data which is being stored inside the [STREAM], [/STREAM] tags stores specific data to the stream.

Once the video geek has gathered some basic information on their multimedia file by making use of the ffprobe utility, they can easily process it based on their specific needs.

For example, one can easily convert their video from one format to another by making use of the ffmpeg utility like shown below.

ffmpeg -i test.mp4 test.avi

As you can see, the above command takes as input the name of the video file for the conversion process, and also the output, which in this case is test.avi.

Once I executed the above command on my console, the conversion process started and I got the test.avi video file on my own operating system.

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame= 1538 fps=236 q=31.0 size=    4614kB time=00:01:04.15 bitrate= 589.2kbits/s speed=9.84x

Feel free to specify your format to your needs during the conversion process. One can easily convert their video from mp4 to flv too by making use of the following command.

ffmpeg -i test.mp4 test.flv

Not only can the ffmpeg utility part of the FFMpeg multimedia framework be used to convert one video from one format to another, but it can also be utilized to cut a video file.

The syntax for cutting a video file is being shown below.

ffmpeg -i video_input -ss start_cut -to end_cut -c copy video_output

To cut the first ten seconds of my video file, I make use of the above command like shown below.

ffmpeg -i test.mp4 -ss 00:00:00 -to 00:00:10 -c copy cut_video_10_seconds.mp4

Now that you learned how to gather information on a video file, how to convert it to another format and also how to cut it, it is time for you to learn how to extract the audio stream from your own video file.

The syntax for the command which can be easily used to extract the audio stream from a video file, is being shown below.

ffmpeg -i video_input -vn -acodec copy output_audio

Based on my personal experience with the above command, it just copies the audio stream, it does not re-encode it. The option -vn stands for video not.

So to extract the audio stream from my video file named test.mp4 I make use of the following command.

ffmpeg -i test.mp4 -vn -acodec copy audio_stream.aac

And last, but not least, you will learn how to extract the video stream from your video file. The syntax for accomplishing it is being shown below.

ffmpeg -i video_input -an -vcodec copy output_video

To extract the video stream from my video file, I make use of the following command.

ffmpeg -i test.mp4 -an -vcodec copy video_stream.mp4

As you have probably guessed by now, the option -an in the above command, stands for audio not.

Final thoughts

FFMpeg is a great multimedia framework when it comes to processing video files. Completely free of charge and open source too, it offers many utilities to the heavy video geek. Through this tutorial we went through the basics every video nerd should know about. On future tutorials we will take a look at advanced stuff and also teach you guys how to script FFMpeg utilities with the Python computer programming language.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Leave a Reply

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

*