Use ffmpeg to generate test videos and pictures

To use FFmpeg to generate test videos and pictures, you need to install FFmpeg and use the command line tool to execute corresponding commands.

1. Generate a test video

Create a test video source file test.mp4:

ffmpeg -f lavfi -i testsrc=duration=5:size=1280x720:rate=30 test.mp4

The above command can generate a test video source file test.mp4 with a duration of 5 seconds, a resolution of 1280x720, and a frame rate of 30.

Compress and encode test.mp4 to generate output file output.mp4:

ffmpeg -i test.mp4 -c:v libx264 -crf 23 -preset fast -c:a copy output.mp4

The above command uses the H.264 encoder to compress and encode test.mp4 and output the file output.mp4. Among them, -crf 23 indicates that the compression quality factor is 23, and the smaller the value, the higher the compression quality; -preset fast indicates that the fast compression mode is used.

2. Generate test pictures

Use FFmpeg to generate a test picture test.jpg:

ffmpeg -f lavfi -i color=c=red:s=320x240:d=5 -pix_fmt rgb24 test.jpg

The above command uses FFmpeg to generate a test picture test.jpg with a resolution of 320x240, a red color, and a duration of 5 seconds.

Extract a frame at a certain point in time from a video as a picture:

ffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 -q:v 2 output.jpg

The above command extracts the video frame of the 5th second from the video file input.mp4, and uses a quality factor of 2 to generate the output image output.jpg. -ss specifies the time point to extract, -i specifies the input file, -frames:v specifies the number of frames to extract.

 

Guess you like

Origin blog.csdn.net/huapeng_guo/article/details/130008759