How to specify pixel format in FFmpeg?

I have one video with ‘ yuv422p ’ pixel format and I want to change the pixel format of the video ‘ yuv420p ’ with transcoding, is there any parameter in FFmpeg that can help me to specify the pixel format.

Hey!
You may use the -pix_fmt option in FFmpeg to specify the desired pixel format during transcoding, which will allow you to change the video’s pixel format.
You would use the following FFmpeg command to convert the pixel format from ‘yuv422p’ to ‘yuv420p’:

ffmpeg -i input.mp4 -pix_fmt yuv420p output.mp4

In the above command:

  • input.mp4 is the input video with the ‘yuv422p’ pixel format.
  • -pix_fmt yuv420p specifies the desired output pixel format as ‘yuv420p’.
    * output.mp4 is the name of the output video.

With the content and other video parameters preserved, this command will convert the video from ‘yuv422p’ to ‘yuv420p’.

Remember that modifying the pixel format could have an impact on the video’s file size and quality, so it’s important to select the one that best meets your unique needs.

Thank you

It doesn’t work for me :slightly_frowning_face:

Getting the same issue again
$ ffmpeg -i DJI_0090.MOV -pixel_format yuv420p test.mp4

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe2d0002600] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1920x1080): unspecified pixel format.

Consider increasing the value for the ‘analyzeduration’ and ‘probesize’ options.

Hey!

According to me, FFmpeg provides a -pix_fmt option for specifying pixel format if you add -pix_fmt before the input file or -i parameter then the frame will be read in the specified pixel format input file.

You can also try:
ffmpeg -pix fmts

If you want to see the list of pixel formats.
Thanks

1 Like

Got it! Thank you all for your help. It really works.

From the discussion thread, it seems you are trying to change the pixel format of a video file using FFmpeg but encountering some issues. Based on the responses, I’d like to provide a more detailed solution.

The correct syntax for specifying the pixel format is -pix_fmt (not -pix_format or -pixel_format). To change the pixel format to ‘yuv420p’, you should use the following command:

ffmpeg -i DJI_0090.MOV -pix_fmt yuv420p test.mp4

However, if you’re still encountering the error mentioning ‘unspecified pixel format,’ you might need to increase the ‘analyzeduration’ and ‘probesize’ options, as suggested above. This can be done using the following command:

ffmpeg -probesize 50M -analyzeduration 100M -i DJI_0090.MOV -pix_fmt yuv420p test.mp4

Adjust the values for ‘probesize’ and ‘analyzeduration’ as needed. These options help FFmpeg analyze more data from the input file, enabling it to correctly identify the codec parameters and pixel format.

Additionally, it’s mentioned above that you can use the ffmpeg -pix_fmts command to see a list of supported pixel formats in FFmpeg, which can be helpful if you need to choose a different format in the future.

I hope this helps you successfully change the pixel format of your video file using FFmpeg. Let me know if you have any further questions or need additional assistance.

Can I convert a video to a specific pixel format without re-encoding the entire video stream?

1 Like

Yes, without re-encoding the entire video stream, it is possible to convert a video to a particular pixel format, although there are some restrictions. The video codec used in the original video, the source and target pixel formats, and other factors strongly influence whether this is possible.

If the source and desired target pixel formats are both supported and compatible with the video codec, FFmpeg can convert the pixel formats without having to re-encode the entire video. A passthrough or bitstream copy is what FFmpeg refers to as this procedure.

Follow these methods to see if your video can be converted to pixel format without re-encoding:

1. Check Video Information

To view comprehensive details about the video file, including the pixel format, use the FFmpeg command:

ffmpeg -i input.mp4

Find the pix_fmt field on the line that begins with `Stream #0:0 (or something similar). This displays the video stream’s current pixel format.

2. Check Supported Pixel Formats

Although FFmpeg supports a large variety of pixel formats, not all of them can be converted without re-encoding. The following command can be used to list the supported pixel formats for a particular codec:

ffmpeg -pix_fmts

3. Choose a Compatible Pixel Format

You can proceed with the conversion without re-encoding if the codec supports and is compatible with the chosen target pixel format.

4. Perform Pixel Format Conversion

Use the following FFmpeg command to perform the pixel format conversion:

ffmpeg -i input.mp4 -c:v copy -pix_fmt target_format output.mp4

Replace target_format with the desired pixel format (e.g., yuv420p, yuv444p, rgb24, etc.).

1 Like