FFmpeg simple and practical tutorial, happily use VPS to compress films

888u

Last update at :2024-05-14,Edit by888u


What is FFmpeg and how to install FFmpeg, please see here: https://www.138vps.com/vpsjc/1126.html


First, we need to know that the syntax of FFmpeg is 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 to an AVI file

ffmpeg -i video.mp4 video.avi

If you want to maintain the quality of your source video 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 the audio conversion encoding or audio frequency, etc., I won’t introduce it here, since it is almost useless anyway.


3. Remove audio from video files

We don’t know why there is such a crazy operation.

ffmpeg -i input.mp4 -an output.mp4


4. Change the resolution of video files

For example, if a certain video has a relatively large resolution, we plan to compress it into a size of 640×480.

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

You can also use the following abbreviation

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


5. Compressed video file size

There are two ways to compress the video size. One is to compress the audio and convert the encoded audio to reduce the bit rate. However, the effect is not obvious. Often the exhaustive compression for a long time will only reduce a few MB. It is better not to compress it, so it is generally Use the method of compressing video quality. After compression, the clarity of the video will be reduced.

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

If the video after using crf 24 is too terrible, you can use a smaller number to make the video quality not so bad.


6. Crop video

Just 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.

Say you want a video from position (200,150) with a width of 640 pixels and a height of 480 pixels, the command would 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 by everyone. When building 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 portion of the video from the beginning of the video to the 30th second of the video.

-ss 00:00:30 Displays the start timestamp for the next part of the video. It means that part 2 will start from the 30th second and will last until 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 as follows

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, the command to merge these MP4s into one video is

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


Recommended site search: Mainland China server group, overseas host rental, US server rental, vps host, how much does it cost to rent a server for a year, Korean server rental, US server, foreign server, free web server website, Forum host,

FFmpeg simple and practical tutorial, happily use VPS to compress films

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码