
- Лицензия
- LGPL v2.1+
- Project Website
- ffmpeg.org
- Report an Issue
- trac.ffmpeg.org
- Support the Author
- ffmpeg.org

FFmpeg is a Linux utility for processing audio and video content, subtitles and associated metadata.
FFmpeg can be installed in any familiar and convenient way:
Install via GNOME Software
In three clicks 😊
Follow the link install FFmpeg and confirm the “open application” operation in the browser. The Application Center will open, select the source "Sisyphus" in it, and click the "download" button
Installation via terminal
su -
apt-get update
apt-get install ffmpegepm -i ffmpegSpecify input file
ffmpeg -iTo view the entire list of all supported formats, use:
ffmpeg -formatsHide the banner about the information of the FFmpeg program itself in the output
ffmpeg -hide_banner1. ffmpeg -i input_file.mp4
2. ffmpeg -i /home/input_file.mp4The example contains two methods:
Regardless of the file extension, information about the media file will be displayed.
Convert various multimedia formats. To do this, you can simply specify the file names, since FFmpeg will get the required format from the extensions. This works to convert video to video and audio to audio.
Examples:
ffmpeg -i "video_input.mp4" "video_output.avi"
ffmpeg -i "video_input.webm" "video_output.flv"
ffmpeg -i "audio_input.mp3" "audio_output.ogg"
ffmpeg -i "audio_input.wav" "audio_output.flac"Подсказка
Below are examples where you can iterate through all the files in the current directory, which will ultimately affect absolutely all files, regardless of their extension. Instead of for i in *.mkv; write for i in *;
Another simple task for FFmpeg. All you need to do to resize a video is specify the new resolution using the s flag
The -c copy flag is used to preserve the original quality (In simple terms, repacking from one container to another while making changes)
ffmpeg -i "File.avi" -s 1024x576 -c copy "File1.avi"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -s 1024x576 -c copy "/mnt/Hard/Result/${i}"; doneFor example, you can cut the first 45 minutes from a video:
ffmpeg -i "Video.mkv" -ss 00:45:00 -c copy "Video2.mkv"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -ss 00:45:00 -c copy "/mnt/Hard/Result/${i}"; doneTrim video from a specific time to a specific time:
ffmpeg -i "Видео.mkv" -ss 00:45:00 -to 1:55:00 -c copy "Видео2.mkv"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -ss 00:45:00 -to 1:55:00 -c copy "/mnt/Hard/Result/${i}"; doneThere are several options with which you can get closer to the original:
-qscale 0 - constant bitrate. If you need to process audio in parallel with this option, you need to separately specify -q:a or -aq q, since by default only the video codec is processed.-crf 18 - variable bitrate. If you specify a lower CRF, the file will be larger with better visual quality.18 - often considered “visually lossless” compression23 - considered standard.Внимание
In FFmpeg support you can often find a mention that -qscale does not work well with H.264
ffmpeg -hide_banner -i "File.avi" -qscale 0 "File.mp4"
ffmpeg -hide_banner -i "File.avi" -crf 18 "File.mp4"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -qscale 0 "/mnt/Hard/Restul/${i}"; done
for i in *.mkv; do ffmpeg -hide_banner -i "$i" -crf 18 "/mnt/Hard/Restul/${i}"; doneA handwritten script extracts the video bitrate from the input file to preserve the original quality during conversion.
for i in *; do
bitrate=$(ffmpeg -hide_banner -i "$i" 2>&1 | grep -oP 'bitrate: \K[0-9]+')
ffmpeg -hide_banner -i "$i" -map 0:v:0 -map 0:a:0 -c:v libx264 -b:v ${bitrate}k -c:a copy "/mnt/Hard/Result/${i%.*}.mkv";
doneИнформация
To use hardware acceleration of the video card, edit the -c:v libx264 key
-c:v h264_nvenc-c:v h264_amf-c:v h264_qsvLet's say we have a video file with 5 audio tracks and 3 subtitle tracks, and we need a video specifically with the first audio track and the second subtitle stream.
ffmpeg -hide_banner -i "файл.mkv" -map 0:v:0 -map 0:a:0 -map 0:s:1 -c:v copy -c:a copy -c:s copy "/path/to/save/file.mkv"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -map 0:v:0 -map 0:a:0 -map 0:s:1 -c:v copy -c:a copy -c:s copy "/path/to/save/${i}"; done-map 0:v:0-map 0:a:0-map 0:s:1-c copy is equivalent to specifying -c:v copy -c:a copy -c:s copy if the desired tracks were previously selected.Be careful
Track indexing starts at zero, so the first track will be numbered 0 rather than 1.
The key for copying the audio codec (-c:a copy) is replaced with another key: -c:a ac3
ffmpeg -hide_banner -i "file.mkv" -map 0:v:0 -map 0:a:0 -map 0:s:1 -c:v copy -c:a ac3 -c:s copy "/path/to/save/file.mkv"for i in *.mkv; do ffmpeg -hide_banner -i "$i" -map 0:v:0 -map 0:a:0 -map 0:s:1 -c:v copy -c:a ac3 -c:s copy "/path/to/save/${i}"; done.mkv (current directory), audio with the extension .mka and subtitles with the extension .ass with the same names. The originality of the name and extension of video files is also preserved. Let's assume that you have a series and two catalogs with the desired audio translation and subtitles:
for i in *.mkv; do
ffmpeg -hide_banner -i "$i" \
-i "/path/to/audio/${i%.*}.mka" \
-i "/path/to/subtitles/${i%.*}.ass" \
-map 0:v:0 -map 1:a -map 2:s \
-c copy \
"/path/to/result/${i%.*}.mkv"
donefor i in *.mkv; do
ffmpeg -hide_banner -i "$i" \
-i "/path/to/audio/${i%.*}.mka" \
-map 0:v:0 -map 1:a \
-c copy \
"/path/to/result/${i%.*}.mkv"
donefor file in *; do
echo "File: $file"
ffprobe -v error -select_streams a -show_entries stream=codec_name,channels,tags:stream_tags=language,title -of csv=p=0 "$file"
doneИнформация
To specify a search parameter, change the line "Stream\|Audio\|Subtitle", \| - the "or" operator.
for file in *; do
if [[ -f "$file" ]]; then
echo "$file"
ffmpeg -i "$file" 2>&1 | grep "Stream\|Audio\|Subtitle"
fi
doneConvert videos with MP4 extension to GIF
ffmpeg -i "file.mp4" "file.gif"MP4 conversion with 3 frames per second and 320 width scaling (height adjusts automatically):
ffmpeg -i "video.mp4" -vf "fps=3,scale=320:-1:flags=lanczos" "gif.gif"GIF animation is 2 times slower. By editing the option setpts=PTS*2 the animation speed is adjusted:
ffmpeg -i "gif.gif" -filter_complex "setpts=PTS*2" "gif1.gif"Splitting a GIF into separate frames:
ffmpeg -i "gif.gif" "gif_%04d.png"Splitting GIF into separate frames, but independently adjusting the number by editing the value fps=10:
ffmpeg -i "gif.gif" -vf "fps=10" "gif_%04d.png"Combining images into GIF:
Внимание
It is necessary to rename the files using one pattern: gif_0001.png, gif_0002.png and so on
ffmpeg -i "gif_%04d.png" -vf "fps=10" "gif.gif"Adding text at bottom center:
ffmpeg -i gif.gif -vf "drawtext=text='ALT Gnome Wiki':x=(w-text_w)/2:y=main_h-text_h-10:fontsize=24:fontcolor=white" text.gifHow to upload a short video without sound to Telegram so that it is saved as a video and not converted to GIF:
ffmpeg -i "file.mp4" -f lavfi -i anullsrc -c:v copy -c:a aac -shortest "file2.mp4"