20 FFmpeg command to a plurality of exemplary novice

942697-f5904547fa23e488.jpg

In this tutorial, I will use an example to illustrate how to use the FFmpeg media framework to do a variety of audio, video transcoding operations and conversion. I have for beginners brings together the most commonly used more than 20 FFmpeg command, I will from time to time to add more examples to keep updating this guide. Please give this guide bookmarking, come back later to check for updates. Let's get started, if you have not installed FFmpeg on your Linux system, refer to the following guidelines.

FFmpeg installed in Linux

For more than 20 FFmpeg command for beginners

FFmpeg typical syntax of the command is:

FFmpeg [Global options] {[input tab] -i} ... address input _url_ 

{[Output File option]} ... address output _url_

Now we will look at some important and useful FFmpeg command.

1, to obtain an audio / video file information

To show the details of your media files, run:

$ ffmpeg -i video.mp4

Sample output:

ffmpeg version n4.1.3 Copyright (c) 2000-2019 the FFmpeg developers 

built with gcc 8.2.1 (GCC) 20181127 

configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3 

56. libavutil 22.100 / 22.100 56 

libavcodec 58. 35.100 / 58. 35.100 

libavformat 58. 20.100 / 58. 20.100 

libavdevice 58. 5.100 / 58. 5.100 

libavfilter 7. 40.101 / 7. 40.101 

libswscale 5. 3.100 / 5. 3.100 

libswresample 3. 3.100 / 3. 3.100 

libpostproc 55. 3.100 / 55. 3.100 

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4': 

Metadata: 

major_brand : isom 

minor_version : 512 

compatible_brands: isomiso2avc1mp41 

encoder : Lavf58.20.100 

Duration: 00:00:28.79, start: 0.000000, bitrate: 454 kb/s 

Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 318 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default) 

Metadata: 

handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019. 

Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default) 

Metadata: 

handler_name : ISO Media file produced by Google Inc. Created on: 04/08/2019. 

At least one output file must be specified

As you can see in the above output, FFmpeg display the media file information, as well as FFmpeg details such as version, configuration details, copyright mark, build parameters and library options, and more.

If you do not want to see FFmpeg banners and other details, but simply want to see the media file information, use -hide_banner flag, as follows.

$ ffmpeg -i video.mp4 -hide_banner

Sample output:

942697-85b2470ea50419d9.png
Use FFMpeg view audio, video file information.

did you see it? Now, it displays only media files details.

2, convert video files to different formats

FFmpeg is a powerful audio and video converter, therefore, it can convert media files between different formats. For example, the file you want to convert mp4 to avi file, run:

$ ffmpeg -i video.mp4 video.avi

Similarly, you can convert media files to any format of your choice.

For example, to convert YouTube flv format video to mpeg format, run:

$ ffmpeg -i video.flv video.mpeg

If you want to maintain the quality of your source video files, use -qscale 0 parameters:

$ ffmpeg -i input.webm -qscale 0 output.mp4

FFmpeg is a check list of supported formats, run:

$ ffmpeg -formats

3, convert video files to audio files

I converted a video file to an audio file, simply indicate the specific output formats, such as .mp3, or .ogg, or any other audio formats.

The above command will convert video files to output.mp3 input.mp4 audio files.

$ ffmpeg -i input.mp4 -vn output.mp3

In addition, you can also use a variety of audio transcoding options for the output file, like the following presentation.

$ ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 output.mp3

it's here,

-vn - indicates that we have to disable video recording in the output file.

-ar - Audio frequency setting output file. Values ​​commonly used are 22050 Hz, 44100 Hz, 48000 Hz.

-ac - Set the number of audio channels.

-ab - show audio bit rate.

-f - Output file format. In our example, it is mp3 format.

4, change the video resolution file

If you want to set up a video file to a specified resolution, you can use the following command:

$ ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4

or,

$ ffmpeg -i input.mp4 -s 1280x720 -c:a copy output.mp4

The above command will set the resolution of a given video file to 1280 × 720.

Similarly, a conversion to the above file size 640 × 480, run:

$ ffmpeg -i input.mp4 -filter:v scale=640:480 -c:a copy output.mp4

or,

$ ffmpeg -i input.mp4 -s 640x480 -c:a copy output.mp4

This technique will help you scale your video files to a small display device, such as tablets and mobile phones.

5, compressed video files

Reduced to a smaller size of media files to save space hardware is always a good idea.

The following command will compress and reduce the size of the output file.

$ ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4

Please note that if you try to reduce the size of the video file, you will lose video quality. If 24 is too aggressive, you can reduce -crf value to or lower value.

You can use the following options to convert the encoded audio bit rate reduction, so that stereo feeling, thereby reducing the size.

-ac 2 -c:a aac -strict -2 -b:a 128k

6, compressed audio files

Just as compressed video files, in order to save some disk space, you can also use -ab logo compressed audio files.

For example, you have an audio file of a bit rate of 320 kbps. Do you want to compress it by changing any bit rate to a lower value, as follows.

$ ffmpeg -i input.mp3 -ab 128 output.mp3

A wide variety of available audio bit rate list is:

96kbps

112kbps

128kbps

160kbps

192kbps

256kbps

320kbps

7, to remove audio stream from a video file

If you do not want a video file, audio, use -an flag.

$ ffmpeg -i input.mp4 -an output.mp4

Here, -an that there is no audio recording.

The above command will undo all audio-related signs, because we do not come from input.mp4 audio.

8, remove the video from a streaming media file

Similarly, if you do not want the video stream, you can use -vn flag simply remove it from the media file. On behalf of -vn No video recording. In other words, this command converts the given media file is an audio file.

The following command from the given media file to remove the video.

$ ffmpeg -i input.mp4 -vn output.mp3

You can also use -ab flag to indicate the bit rate of the output file, as shown in the following example.

$ ffmpeg -i input.mp4 -vn -ab 320 output.mp3

9, the image extracted from the video

Another useful feature of FFmpeg is that we can extract images from a video file easily. If you want to create a photo album from a video file, which can be very useful.

To extract an image from a video file, use the following command:

$ ffmpeg -i input.mp4 -r 1 -f image2 image-%2d.png

it's here,

-r - set frame rate. That is, to extract the digital image frames per second. The default value is 25.

-f - shows the output format, that is, an image in our example.

image-% 2d.png - shows how we want to name the extracted image. In this example, the name should start like this image-01.png, image-02.png, image-03.png and so on. If you use% 3d, then the name of the image as the image-001.png, image-002.png etc. start.

10, crop the video

FFMpeg allows us to select any range of cutting a given media file.

Cut a video file syntax given below:

ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" output.mp4

it's here,

input.mp4 - source video file.

-filter: v - denotes a video filter.

crop - represents a cut filter.

w - the width we want from the source video cropping rectangle.

h - the height of the rectangle.

x - x-coordinate we want from the source video cropping rectangle.

y - y coordinates of the rectangle.

Say you want a location (200, 150) from the video, and has a 640 pixel width and 480 pixel height of the video, the command should be:

$ ffmpeg -i input.mp4 -filter:v "crop=640:480:200:150" output.mp4

Please note that the cut will affect the quality of the video. Unless necessary, do not cut.

Specifically section 11, a video conversion

Sometimes, you may want to convert only a specific part of the video file to a different format. In illustration, the following command to convert a given video input.mp4 beginning 10 seconds and video files .avi format.

$ ffmpeg -i input.mp4 -t 10 output.avi

Here, we specify the time in seconds. Further, in order to specify the time format hh.mm.ss are possible.

12, a video aspect ratio

You can use -aspect flag a video file aspect ratio, as follows.

$ ffmpeg -i input.mp4 -aspect 16:9 output.mp4

Aspect ratio is commonly used:

16:9

4:3

16:10

5:4

2:21:1

2:35:1

2:39:1

13, the poster image to add audio files

You can add to your poster image file, so that the image will be displayed while playing audio files. This is useful for hosted video hosting website host or shared audio files.

$ ffmpeg -loop 1 -i inputimage.jpg -i inputaudio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4

14, using the start and stop times cut a media file

You can use start and stop times for the small pieces to cut a video clip, we can use the following command.

$ ffmpeg -i input.mp4 -ss 00:00:50 -codec copy -t 50 output.mp4

it's here,

-ss - indicates the start time of the video clip. In our example, the start time is 50 seconds.

-t - represents the total duration.

When you want to use the start and end times cut a part from an audio or video file, it is very useful.

Similarly, we can cut the audio as follows.

$ ffmpeg -i audio.mp3 -ss 00:01:54 -to 00:06:53 -c copy output.mp3

15, a plurality of video file segmentation section

Some sites will only allow you to specify the size of the video to upload. In such a case, you can cut large video files divided into smaller units, as follows.

$ ffmpeg -i input.mp4 -t 00:00:30 -c copy part1.mp4 -ss 00:00:30 -codec copy part2.mp4

it's here,

-t 00:00:30 represents the first 30 seconds of the video part of the video creation from the beginning of the video.

-ss 00:00:30 for the next part of the display start timestamp video. It means that Part 2 will begin in the first 30 seconds, and will continue until the end of the original video file.

16, joined or merged into a plurality of portions of video

FFmpeg plurality of video portions may be bonded, and create a single video file.

Create a join.txt you want to engage the exact path of the file. All documents should be in the same format (the same encoding format). The path of all files should be listed one by one, like below.

file /home/sk/myvideos/part1.mp4 

file /home/sk/myvideos/part2.mp4 

file /home/sk/myvideos/part3.mp4 

file /home/sk/myvideos/part4.mp4

Now, joining all the files, use the command:

$ ffmpeg -f concat -i join.txt -c copy output.mp4

If you get something like the following error;

[concat @ 0x555fed174cc0] Unsafe file name '/path/to/mp4' 

join.txt: Operation not permitted

Add -safe 0:

$ ffmpeg -f concat -safe 0 -i join.txt -c copy output.mp4

The above command will engage part1.mp4, part2.mp4, part3.mp4 and part4.mp4 files into a single file called the output.mp4.

17, add subtitles to a video file

We can add captions to a video file using FFmpeg. You download the correct video captions, and add it to your as shown in the video.

$ fmpeg -i input.mp4 -i subtitle.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mp4

18, preview or test video or audio files

You may want to verify whether files by preview or test output has been properly transcoded coded. To complete the preview, you can play it from your terminal, use the command:

$ ffplay video.mp4

Similarly, you can test the audio file, as shown below.

$ ffplay audio.mp3

19, increase / decrease the speed of video playback

FFmpeg allows you to adjust the video playback speed.

To increase the speed of video playback, run:

$ ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4

This command will double the speed of the video.

To reduce the speed of the video you, you need to use a multiple greater than one. To reduce the playback speed, run:

$ ffmpeg -i input.mp4 -vf "setpts=4.0*PTS" output.mp4

20, create animated GIF

For various purposes, we use GIF images on almost all social and professional networks. Use FFmpeg, we can simply create animation and video files quickly. The following guide explains how to create an animated GIF file using ImageMagick and FFmpeg in Unix-like systems.

How to create animated GIF in Linux

21, create a video from a PDF file

I collected over many years, a lot of PDF documents, most Linux tutorials, saved my tablet. Sometimes I'm too lazy to read them from the tablet. So, I decided to create a video from PDF files, view them on a large screen device (like a TV or a computer) in. If you want to know how to make a movie from a group of PDF file, the following guidelines will help you.

How to create a video from PDF files in Linux

22, Getting Help

In this guide, I've covered FFmpeg command most often used. It has many different options to do a variety of advanced features. To learn more about usage, please refer to the manual page.

$ man ffmpeg

That's all. I hope this guide will get you started FFmpeg. If you found this guide helpful, please share it on your social and professional networks. More good things to come. Stay tuned!

Thank you!

via: https://www.ostechnix.com/20-ffmpeg-commands-beginners/

Author: SK  topics: lujun9972  Translator: robsean  proofread: wxy

This article from the  LCTT  original compiler, Linux China  is proud

Reproduced in: https: //www.jianshu.com/p/16cba8166b00

Guess you like

Origin blog.csdn.net/weixin_33843947/article/details/91307529