Home / Alt manpages / pammixinterlace(1)

  • pammixinterlace(1)
  • User command
  • linux

Reduce Interlace Flicker with pammixinterlace

You will finish with a filtered Netpbm image in which each output row blends the corresponding input row with its neighbours. This can soften the time difference between odd and even fields in an interlaced video capture. The examples use the installed Netpbm 11.5.2 command, from Debian package version 2:11.05.02-1.1build1.

Allow about fifteen minutes. You need pammixinterlace, a readable PNM or PAM image, and a writable output directory. The command reads one input image and writes one image to standard output. It does not need root privileges. This guide does not overwrite the source image.

1. Check the installed command

Confirm which executable will run and record its Netpbm build. These are ordinary, read-only checks:

$ command -v pammixinterlace
/usr/bin/pammixinterlace
$ pammixinterlace --version
pammixinterlace: Using libnetpbm from Netpbm Version: 11.5.2
...
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

The version text after the first line varies with the build, so the useful checks are the executable path and the reported Netpbm version. Read the local manual if your package is different:

$ man pammixinterlace

Checkpoint: you are ready when command -v finds the expected binary and the package query identifies the package you intend to use.

2. Preserve the source and choose an output name

pammixinterlace accepts an optional input filename. With no filename it reads standard input, which makes it suitable for a pipeline. The output always goes to standard output, so shell redirection is the normal way to save it.

Do not redirect straight over the only copy of an input image. Shell redirection truncates its destination before the program starts. Use a new destination first:

$ INPUT='/path/to/interlaced-input.pam'
$ OUTPUT='/path/to/interlaced-output.pam'
$ test -r "$INPUT" && echo 'input is readable'
input is readable
$ pammixinterlace "$INPUT" > "$OUTPUT.new"
$ pamfile "$OUTPUT.new"
/path/to/interlaced-output.pam.new: PAM ...

The exact pamfile description depends on the input format. The important result is that it recognises a Netpbm image with the expected dimensions. Only after checking the output should you replace an existing file:

$ mv -- "$OUTPUT.new" "$OUTPUT"

This move changes the destination name but does not alter the source. If processing fails, remove the incomplete "$OUTPUT.new" and the original output remains available. Do not run an rm cleanup command blindly if that temporary name might refer to something else.

3. Run the default FIR filter

The default filter is fir, a size-5 finite impulse response low-pass filter. It is the sensible first test when the capture shows combing or line-to-line motion differences:

$ pammixinterlace -filter=fir "$INPUT" > "$OUTPUT.new"
$ pamfile "$OUTPUT.new"
/path/to/interlaced-output.pam.new: PAM ...

Conceptually, the command works on each output row using the matching input row and neighbouring rows. The manual describes the general mix as half of the main row and a quarter of each adjacent row. The FIR choice uses its own size-5 low-pass calculation, so do not assume that every filter has the same coefficients.

A successful exit status means the command completed and wrote output. It does not prove that the picture looks better. Open a copy in your normal image viewer, or convert it with another installed Netpbm tool, while keeping the source unchanged for comparison.

4. Compare the available filters

There are three filter names: linear, fir and ffmpeg. The default is fir. Produce separate files if you want to compare their visual effect:

$ pammixinterlace -filter=linear "$INPUT" > /tmp/interlace-linear.pam
$ pammixinterlace -filter=fir "$INPUT" > /tmp/interlace-fir.pam
$ pammixinterlace -filter=ffmpeg "$INPUT" > /tmp/interlace-ffmpeg.pam
$ pamfile /tmp/interlace-linear.pam /tmp/interlace-fir.pam /tmp/interlace-ffmpeg.pam

The linear filter is a linear blend. ffmpeg uses the formula documented for FFmpeg by the Netpbm manual. These names select algorithms; they are not input file formats and do not call an external FFmpeg executable.

Use a fresh temporary directory for comparisons if the images are valuable. The files under /tmp are disposable, but removing them is still destructive:

$ rm -- /tmp/interlace-linear.pam /tmp/interlace-fir.pam /tmp/interlace-ffmpeg.pam

5. Try adaptive filtering when stationary detail matters

Add -adaptive when you want the program to modify only pixels that are obviously part of a comb pattern:

$ pammixinterlace -filter=fir -adaptive "$INPUT" > "$OUTPUT.new"
$ pamfile "$OUTPUT.new"
/path/to/interlaced-output.pam.new: PAM ...

Adaptive mode is not a promise that all motion will be repaired or that every unchanged pixel is correct. Compare its output with the ordinary FIR result on the same frame. If you are scripting the command, keep the filter explicit so a future reader can see which behaviour was tested.

6. Handle short images and failures

The installed command warns when an image is less than five rows high and does no mixing. That is easy to miss if you only check that a file was created:

$ pammixinterlace -filter=linear short.pgm > short-output.pgm
pammixinterlace: WARNING: Image height less than 5.  No mixing done.

For such an input, inspect the warning and compare the output with the source before treating the operation as a successful deinterlace. A file can be valid while still not containing the transformation you wanted.

An unknown filter is rejected with a non-zero status:

$ pammixinterlace -filter=nope "$INPUT" > /tmp/unused.pam
pammixinterlace: The filter name 'nope' is not known.
$ printf 'exit status: %s\n' "$?"
exit status: 1

If the input cannot be opened, check the path and permissions without changing them:

$ ls -l -- "$INPUT"
$ test -r "$INPUT" && echo readable

Do not add sudo merely because a filter failed. Use elevated access only when the source directory genuinely denies your account access, and prefer copying the source to a working directory with appropriate permissions.

Done means

  • The installed executable and Netpbm version are known.
  • The source image remains untouched.
  • A chosen filter produced a recognisable output image with the expected dimensions.
  • You checked for the short-image warning and understand that no mixing occurs below five rows.
  • You compared ordinary and adaptive output when preserving stationary detail mattered.
  • Any replacement happened only after the new file was inspected, and the temporary file can be removed safely.