FFmpeg is a powerful open-source multimedia framework that allows you to manipulate and convert audio and video files. In this article, we will explore how to use FFmpeg to crop videos, change their resolution, and adjust the frames per second (FPS) all in one process. These techniques can be useful for various purposes, such as resizing videos for different devices or platforms, removing unwanted portions of a video, or adjusting the playback speed.
Cropping Videos
Cropping a video involves removing unwanted portions from the edges of the frame. This can be useful when you want to focus on a specific part of the video or remove black bars. FFmpeg provides a simple way to crop videos using the crop filter.
To crop a video, you need to specify the desired width and height of the cropped frame, as well as the x and y coordinates of the top-left corner of the cropped area. Here's an example command:
ffmpeg -i input.mp4 -vf "crop=640:480:100:100" output.mp4
In this command, input.mp4 is the path to the input video file, and output.mp4 is the desired name of the output file. The crop filter is used with the parameters 640:480:100:100, where 640 and 480 represent the width and height of the cropped frame, and 100 and 100 represent the x and y coordinates of the top-left corner of the cropped area.
Changing Resolution
Changing the resolution of a video involves resizing the frame to a different width and height. This can be useful when you want to adapt a video for different screen sizes or platforms. FFmpeg provides a straightforward way to change the resolution using the scale filter.
To change the resolution of a video, you need to specify the desired width and height of the output frame. Here's an example command:
ffmpeg -i input.mp4 -vf "scale=1280:720" output.mp4
In this command, input.mp4 is the path to the input video file, and output.mp4 is the desired name of the output file. The scale filter is used with the parameters 1280:720, where 1280 and 720 represent the desired width and height of the output frame.
Adjusting FPS
Adjusting the frames per second (FPS) of a video involves changing the speed at which the frames are played. This can be useful when you want to create slow-motion or time-lapse effects. FFmpeg allows you to adjust the FPS using the setpts filter.
To adjust the FPS of a video, you need to specify the desired output FPS. Here's an example command:
ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" output.mp4
In this command, input.mp4 is the path to the input video file, and output.mp4 is the desired name of the output file. The setpts filter is used with the parameter 0.5*PTS, where 0.5 represents the desired output FPS. You can adjust this value to slow down or speed up the video.
Combining Cropping, Resolution Change, and FPS Adjustment
Now that we understand how to crop, change the resolution, and adjust the FPS of a video individually, let's see how we can combine these operations into a single FFmpeg command. Here's an example:
ffmpeg -i input.mp4 -vf "crop=640:480:100:100,scale=1280:720,setpts=0.5*PTS" output.mp4
In this command, we are cropping the video to a resolution of 640x480, then changing the resolution to 1280x720, and finally adjusting the FPS to 0.5 times the original speed. You can modify the parameters according to your specific requirements.
FFmpeg is a versatile tool that allows you to perform various video manipulations, including cropping, changing resolution, and adjusting FPS. By combining these operations into a single process, you can efficiently modify your videos according to your needs. Remember to experiment with different parameters and settings to achieve the desired results.
References
| Source | Link |
|---|---|
| FFmpeg Documentation | https://ffmpeg.org/documentation.html |
| FFmpeg Wiki | https://trac.ffmpeg.org/wiki |