@iluhin

1 %
Ilya Anisimov
Front-end Development
Soft/Hard Repair
  • City:
    Murmansk
  • Age:
    40 years
  • Education:
    Higher
  • Family:
    Single
  • Kids:
    No
WordPress
PHP / JS
HTML / CSS
Microsoft 365
0 %
Bitrix24
0 %
1C:Enterprise
0 %
Skills
  • Personnel management
  • Staff training
  • Sales techniques
  • Cash discipline
  • Inventory

FFmpeg: working with video

30.11.2024

Many Windows users already have plenty of applications to download, install, activate one more to work with video. Let's do without all that hassle!

FFmpeg is a functional video and audio converter. It has no graphical interface, so you need to perform operations from the console. At the same time, the program's functionality and the quality of its work exceeds that of conventional converters.

FFmpeg basic features:

  • file conversion;
  • resolution change;
  • framing;
  • trimming and gluing files;
  • replace, add, extract audio tracks and subtitles;
  • watermarking;
  • encoding or streaming streaming video.

FFmpeg is actually easy to use and will be useful for both professionals working with video and amateurs who decide to process their home video archive.

FFmpeg Installation.

Unzip the contents of the downloaded archive, for example, to Program Files or Windows or Windows\System32 (or another folder where you may have portable programs stored).

  • File nameffmpeg.zip (прямая ссылка)
  • Версия: 7.1
    module versions

    libavutil 59. 47.101 / 59. 47.101
    libavcodec 61. 26.100 / 61. 26.100
    libavformat 61. 9.100 / 61. 9.100
    libavdevice 61. 4.100 / 61. 4.100
    libavfilter 10. 6.101 / 10. 6.101
    libswscale 8. 12.100 / 8. 12.100
    libswresample 5. 4.100 / 5. 4.100
    libpostproc 58. 4.100 / 58. 4.100
  • File size: 63.9 MByte
  • Requirement: OS Windows x64
  • MD5: c09f1cb1758fd2e48bbb65f3972ac273

To avoid writing a long path to the program every time, for example: C:\Program Files/ffmpeg/bin/ffmpeg.exe. I recommend adding it to the system variable Pathto do so, please go to:

Start → Options → System → About → Advanced System Options → Environment Variables

or

Run "Run" by clicking win+R and execute sysdm.cplthen go to the "Advanced" tab, and there you will find "Environment Variables".

In the User Environment Variables window, double-click on the line Pathwhere you create a new one with the path to the folder with the FFmpeg\bin containing ffmpeg.exe.

FFmpeg: working with video
Path environment variable

Now, in order to call FFmpeg use the following command in the console (PowerShell or CMD):

ffmpeg.exe -version

If the FFmpeg version message appears in the console, then the program is working! If the message appears: "ffmpeg.exe" is not internal or external
command, executable program or batch file
then you should restart your computer.

FFmpeg: video conversion.

After installation FFmpeg you can work with media files, for example, convert video in the console.

ffmpeg -i input.avi output.mp4

This command will convert a video from a file input.avi в output.mp4. The default setting for mov and mp4 files is H.264 codec. The frame size and fps will be taken from the original file.

In the example above, the default settings may be different from your desired settings, so you can set the parameters explicitly.

Additional parameters
  • -i name of the source file to be converted, if there are several files, you should specify -i before each of them;
  • -y will answer yes to all questions from FFmpeg if they arise during the encoding process, e.g. to overwrite a file if it already exists;
  • -vcodec or briefly c:v - video codec settings, or copy (if transcoding is not required), or an empty parameter (default);
  • -f - container format;
  • -b:v (-vb, -b) - video bitrate in kilobits or megabits per second is specified by the letter K or M;
  • -aspect - picture aspect ratio (4:3, 16:9, 1.3333, 1.7777);
  • -r - frame rate;
  • -s - resolution, both numeric values (640×480) and letter designations (e.g. qcif, qvga) are supported;
  • -vf (or -filter:v) - an option with a list of filters that will be applied to the video;
  • -c:a (or -acodec) - audio codec parameters, or copy (if the audio track is to be left as is), or an empty parameter (default);
  • -f - audio format;
  • -af (or -filter:a) - an option with a list of filters to be applied to the audio;
  • -ab (or -b:a) - audio bitrate;
  • -ar - frequency of discrediting;
  • -ac - number of channels.

For an example, consider the following command:

ffmpeg -y -i input.avi -c:v libx264 -preset medium -b:v 17000K -aspect 16:9 -r 25 -c:a aac -b:a 128K output.mp4

This command will transcode input.avi file to output.mp4. If the output.mp4 file is contained in the destination folder, it will be overwritten (option -y). The codec used will be libx264 with medium speed/quality ratio (-preset medium). The final bitrate is 17000 kbps, the picture aspect ratio is 16:9, and the frame rate is 25 frames per second. AAC with bitrate 128kbps will be used as audio codec.

FFmpeg: Useful commands.

To get information about a video file, follow the steps below: ffmpeg -i video.mp4

To get information about keys and parameters: ffmpeg -help

Source and destination files can be of any format, FFmpeg works with almost all of them. List of supported formats ffmpeg -formats

List of supported codecs: ffmpeg -codecs


Trimming video

ffmpeg -i input.mp4 -ss 00:00:05 -t 00:05:15 -c copy output.mp4

FFmpeg allows you to trim or cut video into fragments. The -ss option sets the start of trimming, and the -t option sets the duration of the fragment. Time is set in the format "hours:minutes:seconds".

Video stitching

ffmpeg -i "concat:file1.avi|file2.avi" -vcodec copy -acodec copy output.avi

The concat operator is used for gluing. After a colon, it is passed input files separated by a vertical dash. The files to be concatenated must be single format (video and audio), their parameters must match.

Audio Conversion

ffmpeg -i input.wav -ar 44100 -ac 2 -ab 192K -f mp3 output.mp3

Audio files can be converted independently of video.

Changing resolution and cropping

ffmpeg -i input.mp4 -s 1280x720 output.mp4

To change the resolution of the final video you can use the -s option.

Changing resolution and cropping

ffmpeg -i input.mp4 -s 1280x720 output.mp4

To change the resolution of the final video you can use the -s option. However, using the scale filter will give a better result.

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4

The crop filter is intended for cropping the image. Its parameters have the following form crop=w:h:x:y, where w is the width of the rectangle to be cropped from the source video, h is the height of the rectangle, x and y are x-coordinates of the cropping start point.

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

The command above will cut a rectangle 640 pixels wide and 480 pixels high from the frame, starting at position (200,150).

Party ratio

The aspect ratio is set with the -aspect option.

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

Another example: ffmpeg -i input.mp4 -aspect 16:9 -vf scale=1280:720 output.mp4
The most popular aspect ratios are 16:9 | 4:3 | 16:10 | 5:4 | 2:21:1 | 2:35:1 | 2:39:1.

Adding, extracting and deleting and audio

To add an audio track to a video file use the -i option where you specify the path to the audio file.

ffmpeg -i noaudio.mpg -i audio.acc -vcodec copy -acodec copy output.mpg

You can remove the audio track from a video file using the -an (audio not) option.

ffmpeg -i input.mpg -vcodec copy -an noaudio.mpg

Save the audio track from a video file

ffmpeg -i input.mpg audio.wav

If you want to save the track in a specific format, specify the parameters explicitly:

ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192K -f mp3 audio.mp3

The -ar option specifies the sampling rate, -ac specifies the number of channels, and -ab specifies the bitrate. The -vn option means that video information will be discarded, and the -f option indicates the format of the resulting file (mp3 in the example).

If there are several audio tracks, to save a separate audio track from a video file (demultiplexing) use the -map option and specify its stream ID.

ffmpeg -i input.avi -map 0:2 audio.wav

The example below shows how to add multiple audio tracks to a video file (multiplexing).

ffmpeg -i video.avi -i audio1.mp3 -i audio2.mp3 -map 0:0 -map 0:1 -map 0:2 output.mkv

Since there is only one output file in the example above, the 0 before the colon can be omitted.

Volume change

To change the volume in FFmpeg there is an audio filter volume.

The next command will reduce the volume by half:

ffmpeg -i input.mp3 -af 'volume=0.5' output.mp3

Similarly, the volume can be increased (one and a half times in the example below):

ffmpeg -i input.mp4 -c:v copy -af 'volume=1.5' output.mp4


FFmpeg's capabilities don't stop there, so you can read more at teams и filters on the official website.

Рубрика: СофтМетки:
Написать комментарий

en_USEN