DrKLO/Telegram · error

Unexpected input format!\n

Error message

Unexpected input format!\n

What it means

yuvjpeg computes the expected 4:2:0 byte size as luma_width*luma_height + 2*chroma_width*chroma_height (chroma dims = ceil(luma/2)) and compares it to the YUV file size from ftell. If they differ it closes the file, prints `Unexpected input format!`, and returns 1. This catches dimension/file mismatches and non-4:2:0 layouts before decoding.

Source

Thrown at TMessagesProj/jni/mozjpeg/yuvjpeg.c:164

  /* Will check these for validity when opening via 'fopen'. */
  yuv_path = argv[3];
  jpg_path = argv[4];

  yuv_fd = fopen(yuv_path, "r");
  if (!yuv_fd) {
    fprintf(stderr, "Invalid path to YUV file!\n");
    return 1;
  }

  fseek(yuv_fd, 0, SEEK_END);
  yuv_size = ftell(yuv_fd);
  fseek(yuv_fd, 0, SEEK_SET);

  /* Check that the file size matches 4:2:0 yuv. */
  if (yuv_size !=
   (size_t)luma_width*luma_height + 2*chroma_width*chroma_height) {
    fclose(yuv_fd);
    fprintf(stderr, "Unexpected input format!\n");
    return 1;
  }

  yuv_buffer = malloc(yuv_size);
  if (!yuv_buffer) {
    fclose(yuv_fd);
    fprintf(stderr, "Memory allocation failure!\n");
    return 1;
  }

  if (fread(yuv_buffer, yuv_size, 1, yuv_fd) != 1) {
    fprintf(stderr, "Error reading yuv file\n");
  };

  fclose(yuv_fd);

  frame_width = (luma_width + (16 - 1)) & ~(16 - 1);
  frame_height = (luma_height + (16 - 1)) & ~(16 - 1);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Match the WxH argument exactly to the source frame's luma dimensions.
  2. Ensure the input is raw planar 4:2:0 (I420) with no container/header/stride padding.
  3. Strip any Y4M headers or convert NV12/other layouts to I420 first.
  4. Verify file size equals W*H + 2*((W+1)/2)*((H+1)/2) before invoking.

Example fix

// before
yuvjpeg 90 1280x720 frame.yuv out.jpg   # frame is actually 1920x1080
// after
yuvjpeg 90 1920x1080 frame.yuv out.jpg
Defensive patterns

Strategy: validation

Validate before calling

#include <sys/stat.h>
/* expected 4:2:0 (I420) byte size for the declared dimensions */
long cw = (luma_width + 1) / 2, ch = (luma_height + 1) / 2;
size_t expected = (size_t)luma_width * luma_height + 2 * cw * ch;
struct stat st;
if (stat(yuv_path, &st) != 0 || (size_t)st.st_size != expected) {
    /* dimensions do not match file; reject before invoking yuvjpeg */
}

Prevention

When it happens

Trigger: The declared WxH does not match the actual YUV frame, the file is truncated/padded, the layout is not 4:2:0 (e.g. 4:4:4 or 4:2:2), or there are extra header/padding bytes.

Common situations: Wrong size argument vs real capture resolution, feeding a Y4M or NV12 container instead of raw I420, endianness/stride padding, or a partially downloaded file.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/b5ffbd0c0630a85d. Report an issue: GitHub.