FFmpeg simple and practical tutorial, enjoy VPS compression

2020/12/3123:50:21 entertainment 2194

First, we need to know that the syntax of FFmpeg looks like this:

ffmpeg [global options] {[input file options] -i input_url_address} {[output file options] output_url_address}

Then, run the following Command to see which formats ffmpeg supports

ffmpeg -formats

1, convert video files to different formats

For example, we want to convert an MP4 file into an AVI file

ffmpeg -i video.mp4 video.avi

If you want to maintain your source video For the quality of the file, add -qscale 0

ffmpeg -i video.mp4 -qscale 0 video.avi

2, extract audio from video

ffmpeg -i input.mp4 -vn output.mp3

Of course, if you want to be more responsible, such as changing Audio conversion encoding or audio frequency, etc., will not be introduced here, anyway, it is almost useless.

3, remove audio from the video file

Su Su does not know why there is such a frenzied operation

ffmpeg -i input.mp4 -an output.mp4

4, change the resolution of the video file

For example, a certain video resolution is relatively large, We plan to compress to 640×480 size

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

You can also use the following shorthand

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

5. Compressed video file size

There are two ways to compress video size, one is to compress audio, convert encoded audio to reduce the bit rate, but this effect is not obvious, and it is often reduced after a long time. A few megabytes is better than no compression, so the video quality is usually compressed. After compression, the definition of the video will decrease.

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

If the video after crf 24 is too horrible, you can use a smaller number to make the video quality worse It would be so bad.

6. Crop video

is to crop a certain range in the video

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

w-the width of the rectangle we want to crop from the source video.

h-the height of the rectangle.

x – The x coordinate of the rectangle we want to crop from the source video.

y-the y coordinate of the rectangle.

For example, if you want a video with a width of 640 pixels and a height of 480 pixels from the video position (200,150), the command should be:

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

7, split the video file into multiple parts

I believe this is a commonly used function for everyone, to be a video website, it is important to know how to slice

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

-t 00:00:30 means to create a part of the video from the beginning of the video to the 30th second of the video.

-ss 00:00:30 shows the start timestamp for the next part of the video. It means that Part 2 will start at the 30th second and will continue to the end of the original video file.

8. Merge multiple videos

After downloading the sliced ​​videos, we need to merge them into one file. First prepare a txt file, assuming the file name is: join.txt, the content is probably the following

file /home/sk/myvideos/part1.mp4

file /home/sk/myvideos/part2.mp4

file /home/sk/myvideos/part3 .mp4

file /home/sk/myvideos/part4.mp4

Then, to merge these MP4s into one video, the command is

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

FFmpeg simple and practical tutorial, enjoy VPS compression - DayDayNews

entertainment Category Latest News