Location>code7788 >text

Common commands for ffmpeg and ffplay

Popularity:391 ℃/2024-08-06 22:43:11

FFmpeg Common Usage

1. Basic command structure

ffmpeg [global_options] -i input_file [input_options] output_file [output_options]

2. Convert other formats to YUV420p

ffmpeg -i  -pix_fmt yuv420p 
  • -i : Specify the input file
  • -pix_fmt yuv420p: Specifies that the pixel format of the output file is YUV420p.
  • : Specify the output file name as

3. Extract and save video frames as YUV420p images

ffmpeg -i input.mp4 -vf "select=eq(n\,100)" -pix_fmt yuv420p -vsync vfr frame_100.yuv
  • -i input.mp4: Specify the input video fileinput.mp4
  • -vf "select=eq(n\,100)": Select the 100th frame using the filter.
  • -pix_fmt yuv420p: Specifies that the pixel format of the output file is YUV420p.
  • -vsync vfr: Use variable frame rate mode.
  • frame_100.yuv: Specify the output file name asframe_100.yuv

4. Converting YUV420p images to other formats

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i  
  • -s 1920x1080: Specifies the resolution of the input file.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -i : Specify the input file
  • : Specify the output file name as

5. Extract all frames from the video and save them as YUV420p images

ffmpeg -i input.mp4 -vf "fps=1" -pix_fmt yuv420p frame_%
  • -i input.mp4: Specify the input video fileinput.mp4
  • -vf "fps=1": Extracts one frame per second.
  • -pix_fmt yuv420p: Specifies that the pixel format of the output file is YUV420p.
  • frame_%: Specify the output filename format (e.g.frame_0001.yuv, frame_0002.yuv)。

6. YUV420p image into a video

ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 30 -i frame_% -c:v libx264 output.mp4
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -s 1920x1080: Specifies the resolution of the input file.
  • -r 30: Specifies a frame rate of 30 fps.
  • -i frame_%: Specifies the input file name format.
  • -c:v libx264: Specifies that the video codec is H.264.
  • output.mp4: Specify the output file name asoutput.mp4

7. Adjust the resolution of the YUV420p image

Scales YUV420p images from 1920x1080 to 1280x720:

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i  -vf scale=1280:720 -pix_fmt yuv420p 
  • -s 1920x1080: Specifies the resolution of the input file.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -i : Specify the input file
  • -vf scale=1280:720: Adjust the resolution to 1280x720 using the Zoom filter.
  • : Specify the output file name as

8. Crop YUV420p image

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i  -vf "crop=1280:720" -pix_fmt yuv420p 
  • -s 1920x1080: Specifies the resolution of the input file.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -i : Specify the input file
  • -vf "crop=1280:720": Use the Crop filter to crop to a 1280x720 area.
  • : Specify the output file name as

FFplay Common Usage

1. Basic command structure

ffplay [options] input_file

2. Playback of YUV420p images

Specifies the resolution and pixel format:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • : Specify the input file

3. Zoom YUV420p image

Scales YUV420p images to 1366x768:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -vf scale=1366:768 
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • -vf scale=1366:768: Adjust the resolution to 1366x768 using the Zoom filter.
  • : Specify the input file

4. Cycle through YUV420p images

ffplay -loop 0 -f rawvideo -pixel_format yuv420p -video_size 1920x1080 
  • -loop 0: Infinite loop playback of the input file.
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • : Specify the input file

5. Playback of YUV420p image sequence

playback withframe_0001.yuv, frame_0002.yuv etc. named image sequences:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -i frame_%
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • -i frame_%: Specifies the input file name format.

6. Resizing the playback window

Adjust the playback window to 800x600:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -window_size 800x600 
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • `-video

_size 1920x1080`: Specifies the resolution of the input file.

  • -window_size 800x600: Specifies the size of the playback window.
  • : Specify the input file

Advanced Usage of FFmpeg and FFplay

1. Using filters in FFmpeg to process YUV420p images

Add Watermark

Adds a watermark in PNG format to a YUV420p image:

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i  -i  -filter_complex "overlay=10:10" -pix_fmt yuv420p 
  • -s 1920x1080: Specifies the resolution of the input file.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -i : Specify the input file
  • -i : Specify watermark image
  • -filter_complex "overlay=10:10": Use the Complex Filter to add a watermark at coordinates (10,10).
  • : Specify the output file name as

Adjusting brightness and contrast

Adjusts the brightness and contrast of the YUV420p image:

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i  -vf eq=brightness=0.06:contrast=1.5 -pix_fmt yuv420p 
  • -s 1920x1080: Specifies the resolution of the input file.
  • -pix_fmt yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -i : Specify the input file
  • -vf eq=brightness=0.06:contrast=1.5: Adjust the brightness and contrast using the eq filter.
  • : Specify the output file name as

2. Using filters to play YUV420p images in FFplay

Adjusting brightness and contrast

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -vf eq=brightness=0.06:contrast=1.5 
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • -vf eq=brightness=0.06:contrast=1.5: Adjust the brightness and contrast using the eq filter.
  • : Specify the input file

Add Subtitles

Add subtitles when playing back YUV420p images (subtitle files are):

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -vf subtitles= 
  • -f rawvideo: Specifies that the input file format is raw video.
  • -pixel_format yuv420p: Specifies that the pixel format of the input file is YUV420p.
  • -video_size 1920x1080: Specifies the resolution of the input file.
  • -vf subtitles=: Add subtitles using the subtitles filter.
  • : Specify the input file

Common Problems and Solutions

1. Unable to play YUV420p image

Make sure the correct resolution and pixel format are specified:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 

2. Incomplete display of images

utilization-vf scale option resizes the image to fit the screen resolution:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -vf scale=1366:768 

3. Low quality of video or pictures

Adjust the bitrate of the video or picture or use a higher quality encoder:

ffmpeg -i input.mp4 -b:v 2000k output.mp4

official document

FFmpeg Official Documentation

FFplay User Manual