Home / Alt manpages / yuvtoppm(1)

  • yuvtoppm(1)
  • User command
  • linux

Convert Abekas YUV Bytes to PPM with yuvtoppm

You will turn a raw Abekas YUV file into a PPM image, check that the dimensions are right, and keep the original bytes safe if the conversion needs repeating. The examples match Netpbm 11.5.2, installed here as Debian package netpbm 2:11.05.02-1.1build1.

Allow about ten minutes. You need a shell, a readable YUV file, and the image dimensions in pixels. This is a read-and-write conversion, so it normally needs no elevated privileges. Do not use sudo unless the input directory or destination genuinely requires it.

1. Confirm the converter and the input dimensions

Check which executable will run, then record the width and height supplied by the system or device that produced the file:

$ command -v yuvtoppm
/usr/bin/yuvtoppm
$ yuvtoppm --version
yuvtoppm: Using libnetpbm from Netpbm Version: 11.5.2
$ file /path/to/frame.yuv
/path/to/frame.yuv: data

Replace /path/to/frame.yuv with your real file. The file command usually cannot identify raw YUV because it has no header. That is expected. The width and height must come from outside the byte stream: yuvtoppm cannot infer them.

Checkpoint: write down values such as 720 by 576 before running the conversion. The width must be even for this Abekas format because each four-byte code represents two side-by-side pixels.

2. Convert the bytes to a new PPM file

Pass width and height as ordinary positional arguments. The input may be a filename or standard input; the output is written to standard output, so shell redirection gives it a filename:

$ yuvtoppm 720 576 /path/to/frame.yuv > frame.ppm
$ printf 'exit status: %s\n' "$?"
exit status: 0

The first number is the number of columns and the second is the number of rows. They describe the existing raster. They do not resize it. A successful exit status means the program completed the conversion; it does not prove that the dimensions came from the right source or that the image looks correct.

Standard input is useful in a pipeline or when the bytes are held by another command:

$ yuvtoppm 720 576 < /path/to/frame.yuv > frame.ppm

Keep the input path and output path visibly different. Shell redirection truncates an existing output before yuvtoppm starts, so a typo in frame.ppm could destroy a useful PPM. If you must replace an existing image, use a temporary destination and move it only after checking it:

$ yuvtoppm 720 576 /path/to/frame.yuv > frame.ppm.new
$ file frame.ppm.new
frame.ppm.new: Netpbm image data, size = 720 x 576, rawbits, pixmap
$ mv frame.ppm.new frame.ppm

Recovery

If conversion fails, leave the old output alone and investigate frame.ppm.new. Remove that incomplete file only after confirming that it is not useful. The mv command above is the state-changing step and normally needs no root access.

3. Verify the PPM header and dimensions

Use file as a quick check that the output is a PPM of the requested size:

$ file frame.ppm
frame.ppm: Netpbm image data, size = 720 x 576, rawbits, pixmap
$ test -s frame.ppm && echo 'non-empty PPM'
non-empty PPM

For a more direct header check, read only the first few lines. Do not treat the binary pixel data after the header as text:

$ head -n 3 frame.ppm
P6
720 576
255

The PPM header identifies a raw RGB image with a maximum sample value of 255. A viewer or a later Netpbm converter can now read the file. For example, if pnmtopng is installed, create a separate PNG after the PPM check:

$ pnmtopng frame.ppm > frame.png
$ file frame.png
frame.png: PNG image data, 720 x 576, 8-bit/color RGB, non-interlaced

That PNG command is not part of yuvtoppm. If the viewer shows shifted colours or a torn image, stop before deleting the source and check the recorded dimensions and byte format.

4. Understand the input format boundary

This command is for raw Abekas YUV bytes, not any file that happens to contain the letters YUV in its name. The related ppmtoyuv manual describes each four-byte code as two pixels: the second byte carries the left pixel's Y value, the fourth carries the right pixel's Y value, and the first and third carry weighted U and V averages. Rows run from top to bottom and pixels run from left to right.

That layout is different from common YUV formats such as YUV4MPEG2 and the various 4:2:x arrangements. Do not feed a camera, video or streaming file to yuvtoppm unless its producer explicitly says that its payload is this Abekas layout. A command can produce a syntactically valid PPM from the wrong bytes while displaying incorrect colours.

The input sample maximum is assumed to be 255. There is no option here to describe another maximum, and there are no yuvtoppm-specific switches. The program does accept common libnetpbm options, but they do not replace the required width and height.

5. Diagnose the usual failures

An odd width is rejected because two pixels share each four-byte YUV code:

$ yuvtoppm 721 576 /path/to/frame.yuv > frame.ppm
yuvtoppm: Number of columns (721) is odd.  A YUV image must have an even number of columns.

Use the actual even width from the source, not a nearby value that makes the command run. A wrong even width can still produce output, but row boundaries and the resulting picture will be wrong.

If the input cannot be opened, check the path and read permission without changing anything:

$ ls -l /path/to/frame.yuv
$ test -r /path/to/frame.yuv && echo readable

If the output is unexpectedly short or the program reports extraneous data, the dimensions may not match the byte count. Reconfirm the producer's format and dimensions. Do not pad or edit the raw file blindly: extra bytes can indicate that it is a different container or that more than one frame is present.

Done means

  • The installed command is Netpbm 11.5.2 or a version you have checked for the same behaviour.
  • The input is confirmed as raw Abekas YUV, with an even width and known height.
  • The conversion writes to a new PPM name or a temporary replacement, not blindly over a useful file.
  • file reports the expected PPM dimensions and the output is non-empty.
  • The original YUV bytes remain available until the image has been inspected.