Ubuntu 22.04 FFMPEG: Difference between revisions
Created page with "=FFMPEG= ===Installing FFmpeg on Ubuntu<br>=== To use FFmpeg on Ubuntu, you need to install it first. You can do this by running the following command in the terminal:<br> <code>sudo apt install ffmpeg</code><br> <br> ==Basic usage== Once you have installed FFmpeg, you can use it to perform various tasks related to video and audio processing. Here are some basic commands to get you started:<br> === Convert video from one format to another=== * This command will convert..." |
(No difference)
|
Latest revision as of 18:45, 11 May 2023
FFMPEG
Installing FFmpeg on Ubuntu
To use FFmpeg on Ubuntu, you need to install it first. You can do this by running the following command in the terminal:
sudo apt install ffmpeg
Basic usage
Once you have installed FFmpeg, you can use it to perform various tasks related to video and audio processing. Here are some basic commands to get you started:
Convert video from one format to another
- This command will convert the input_video.avi file to output_video.mp4 format.
ffmpeg -i input_video.avi output_video.mp4
Convert audio from one format to another
- This command will convert the input_audio.mp3 file to output_audio.ogg format.
ffmpeg -i input_audio.mp3 output_audio.ogg
Extract audio from a video file
- This command will extract the audio from the input_video.mp4 file and save it as output_audio.mp3.
ffmpeg -i input_video.mp4 -vn output_audio.mp3
Extract frames from a video file
- This command will extract one frame per second from the input_video.mp4 file and save them as PNG images in the output_frames folder.
ffmpeg -i input_video.mp4 -r 1 -f image2 output_frames/frame05d.png
Merge audio and video files
- This command will merge the input_video.mp4 and input_audio.mp3 files and save the result as output_video.mp4.
ffmpeg -i input_video.mp4 -i input_audio.mp3 -c:v copy -c:a aac -strict experimental output_video.mp4
More advanced usage
FFmpeg can be used for many advanced video and audio processing tasks, such as trimming, cropping, resizing, adding watermarks, etc. Here are some examples:
Trim a video file
- This command will trim the input_video.mp4 file from the 10th to the 20th second and save the result as output_video.mp4.
ffmpeg -i input_video.mp4 -ss 00:00:10 -to 00:00:20 -c copy output_video.mp4
Trim a Audio file
- This command will will make a 5 second copy. From 00:00:05 to 00:00:10
ffmpeg -i input.mp3 -ss 00:00:05 -t 00:00:05 output.mp3
- -i input
- -ss start time
- -t time, for how long.
- Time syntax HH:MM:SS
- output.mp3 name of output file
Crop a video file
- This command will crop the input_video.mp4 file to 480x360 pixels, starting from (120,60) coordinates, and save the result as output_video.mp4.
ffmpeg -i input_video.mp4 -filter:v "crop=480:360:120:60" -c:a copy output_video.mp4
Resize a video file
- This command will resize the input_video.mp4 file to a width of 640 pixels and adjust the height automatically, maintaining the aspect ratio, and save the result as output_video.mp4.
ffmpeg -i input_video.mp4 -vf scale=640:-2 -c:a copy output_video.mp4
Add a watermark to a video file
- This command will add a watermark.png image to the top-left corner of the input_video.mp4 file and save the result as output_video.mp4.
ffmpeg -i input_video.mp4 -i watermark.png -filter_complex "overlay=10:10" -codec:a copy output_video.mp4
,br>
Concatenating Videos
Concatenating videos using the concat demuxer
The concat demuxer is a FFmpeg component that allows you to concatenate videos by creating a text file that lists the paths of the input video files in the order you want them to be concatenated.
Create a text file
Create a new text file called concat.txt and list the paths of the input video files in the order you want them to be concatenated. For example:
file '/path/to/video1.mp4' file '/path/to/video2.mp4' file '/path/to/video3.mp4'
Concatenate the videos
ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mp4
This command tells FFmpeg to use the concat demuxer (-f concat) and to read the input file paths from the concat.txt file (-i concat.txt).
The -safe 0 option is used to disable some security checks that could prevent FFmpeg from accessing the input files.
The -c copy option is used to copy the video and audio streams from the input files to the output file without re-encoding them, which is faster and preserves the original quality.
The output.mp4 parameter is the name of the output file.