Im getting error "deprecated pixel format used, make sure you did set range correctly using ffmpeg".. can someone check my code below?

Im getting error "deprecated pixel format used, make sure you did set range correctly using ffmpeg".. can someone check my code below?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Fixing the "Deprecated Pixel Format" Error in FFmpeg Thumbnail Generation

When attempting to extract a video thumbnail using FFmpeg, encountering the error [swscaler @ ...] deprecated pixel format used is a common stumbling block for developers who are new to the tool. This specific warning usually stems from a mismatch between the input video's color space and the constraints of the output format you are targeting. In your case, you are trying to convert an H.264 stream directly into MJPEG with the yuvj420p(pc) pixel format, which FFmpeg has flagged as deprecated.

The root cause lies in how modern video containers handle color data versus how older or specific legacy formats expect it. When FFmpeg processes your input MP4 file, it encounters a stream that uses Planar Color (pc). The error message explicitly suggests: "make sure you did set range correctly." In the context of MJPEG encoding, yuvj420p expects a full-range signal, whereas many modern H.264 streams encode in limited-range or specific planar configurations that conflict with the default scaler behavior.

To resolve this, you need to explicitly tell FFmpeg how to handle the color space conversion without relying on automatic heuristics that might trigger deprecated flags. The most robust solution is to force the pixel format conversion before encoding, ensuring the input is in a standard YUV format that the MJPEG encoder accepts natively. You can do this by adding -pix_fmt yuv420p to your command line arguments. This forces FFmpeg to decode the video into a standard full-range YUV 4:2:0 layout before passing it to the MJPEG encoder, effectively bypassing the deprecated format check.

Here is how you can adjust your PHP shell_exec call to incorporate this fix:

$ffmpeg = '/opt/local/bin/ffmpeg';
$image = 'image.jpg';
$video_url ='https://URL/upload/4b8acab123563649f19e07450d810df6.mp4';
$interval = 5;
$size = '320x240';

// Updated command with explicit pixel format and safer error handling
$command = sprintf(
    '%s -i %s -deinterlace -an -ss %s -f mjpeg -t 1 -r 1 -y -s %s -pix_fmt yuv420p %s',
    $ffmpeg,
    $video_url,
    $interval,
    $size,
    $image
);

// Capture stderr to see the actual error if it persists, rather than discarding it
shell_exec($command . ' 2>&1');

By adding -pix_fmt yuv420p, you ensure that the pixel format used is standard and compatible with the MJPEG encoder, eliminating the warning. Additionally, redirecting stderr (2>&1) in your PHP code is a best practice for debugging; it allows you to inspect the actual output if the command still fails or if FFmpeg logs additional warnings about bitrate or resolution limits.

Another consideration in your current setup is the use of -ss before the input file. While this is convenient for seeking, it relies on keyframe intervals and can sometimes result in a thumbnail that is not perfectly aligned with the intended frame time, especially if the video lacks frequent keyframes. For high-precision thumbnails, placing -ss after the -i flag (though slightly slower) ensures you are grabbing exactly the frame at the specified timestamp.

Furthermore, MJPEG is an older compression format often used for compatibility but not ideal for high-quality static images due to its inefficiency compared to JPEG or WebP. If your application does not strictly require MJPEG output, consider switching to the image/jpeg codec using -c:v libx264 (for stills) or simply letting FFmpeg handle the conversion to JPEG natively with -vf format=yuvj420p. However, if MJPEG is a hard requirement for your legacy system, the pixel format fix above is the definitive solution.

Finally, always be mindful of the environment where this code runs. Since you are using shell_exec, ensure that the $ffmpeg path is correct and accessible via the system PATH in the context of your PHP process, especially if running under a specific web server user like www-data. Misconfigurations here can lead to silent failures or permission errors that obscure the real issue.

Our network