LinuxCommandLibrary

ppmtoyuv

Convert PPM images to YUV image format

TLDR

Read a PPM image from the input file, convert it to an Abekas YUV image and store it in the specified output file

$ ppmtoyuv [path/to/input_file.ppm] > [path/to/output_file.yuv]
copy

SYNOPSIS

ppmtoyuv [-p|-o] [-s|-q|-f|-a] [-v] [-gamma value] [-nopan] [-pad] [ppmfile]

PARAMETERS

-p
    Output YUV in plain (no header) format.

-o
    Output YUV in output (with header) format. This is the default.

-s
    Output YUV in standard 4:2:0 format. This is commonly used in video codecs.

-q
    Output YUV in quarter-pixel 4:1:1 format.

-f
    Output YUV in half-pixel 4:2:2 format.

-a
    Output YUV in full-pixel 4:4:4 format. This retains full color information.

-v
    Produce verbose output, showing progress and information messages.

-gamma value
    Apply gamma correction using the specified value.

-nopan
    Suppress the 'pan' error message often generated when image dimensions are not a multiple of 16.

-pad
    Pad the output YUV image dimensions (width and height) to be a multiple of 16. This is often required by video encoders.

DESCRIPTION

ppmtoyuv is a specialized command-line utility from the Netpbm package, designed to convert Portable Pixmap (PPM) image files into various YUV (luminance-chrominance) video formats. PPM is a simple, uncompressed image format, often used as an intermediate format in image processing pipelines. YUV, on the other hand, is a color encoding system primarily used in video systems, particularly for analog and digital television, due to its efficient separation of luminance (brightness) and chrominance (color information).

This tool is crucial when preparing image sequences for video encoding, as many video codecs expect YUV input. ppmtoyuv allows users to select different YUV sampling formats (like 4:4:4, 4:2:2, 4:1:1, or 4:2:0), which represent varying levels of chrominance subsampling, impacting file size and perceived quality. It reads PPM data from standard input or a specified file and outputs the YUV stream to standard output, making it easily integrable into shell scripts and processing pipelines with other tools like ffmpeg or video encoders.

CAVEATS

ppmtoyuv is part of the Netpbm toolkit, so it requires Netpbm to be installed. The YUV output is often raw and typically requires further processing by a video encoder (e.g., ffmpeg) or a specific YUV viewer. The choice of YUV subsampling format (4:4:4, 4:2:2, 4:1:1, 4:2:0) significantly impacts the final file size and perceived color fidelity. Ensure the selected YUV format matches the requirements of downstream video processing tools.

YUV SUBSAMPLING FORMATS

YUV formats like 4:4:4, 4:2:2, 4:1:1, and 4:2:0 describe the ratio of chrominance (color) information sampled relative to luminance (brightness). 4:4:4 means full color information for every pixel. 4:2:2 samples chrominance at half the horizontal resolution. 4:1:1 samples chrominance at a quarter of the horizontal resolution. 4:2:0 samples chrominance at half the horizontal and half the vertical resolution. Lower ratios like 4:2:0 are common in video for efficiency, as the human eye is less sensitive to chrominance detail than luminance.

STANDARD INPUT/OUTPUT USAGE

Like many Netpbm tools, ppmtoyuv can read from standard input and write to standard output. This allows it to be easily chained with other commands using pipes. For example, anytopnm input.jpg | ppmtoyuv -s > output.yuv would convert a JPG to PPM, then to YUV 4:2:0.

HISTORY

ppmtoyuv is a long-standing component of the Netpbm project, which evolved from the original pbmplus package. The Netpbm suite, developed primarily by Bryan Henderson, is a collection of graphics programs and a programming library for handling many different graphic file formats. ppmtoyuv's inclusion reflects the project's broad utility, enabling conversions vital for video production pipelines long before more comprehensive tools like ffmpeg became widespread. Its development has focused on robust and efficient conversion between the versatile PPM format and various YUV representations, catering to the specific needs of video processing workflows.

SEE ALSO

yuvtoppm(1), pnmtoyuv(1), ffmpeg(1), netpbm(1), ppm(5)

Copied to clipboard