PPMTOMPEG(1)

๐Ÿ“ฆ
version 11.13.03 ยท 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– ppmto... wait, PPMTOMPEG ๐Ÿ’– (Ppmtompeg User Manual, section 1 โ€” General Commands Manual, bestie)

okay so this is the manual for ppmtompeg, and it's a LOT, so buckle up ๐ŸŽ€

โœจ NAME โœจ

ppmtompeg โ€” encode an MPEG-1 bitstream ๐Ÿ‘‘


๐ŸŒธ SYNOPSIS ๐ŸŒธ

ppmtompeg [options] parameter-file

like... options first, then the parameter file. that's the whole vibe check ๐Ÿ’…


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

This program is part of Netpbm(1). ๐Ÿซถ

ppmtompeg produces an MPEG-1 video stream. MPEG-1 is literally the first great video compression method, and it's what gets used in Video CDs (VCD). ppmtompeg originated in the year 1995 โ€” yes, ancient, iconic, historic. DVD uses a more advanced method, MPEG-2. There's an even newer method called MPEG-4 which is also called Divx. I don't know where one finds that used. ๐Ÿ’€

There's technically a difference between a compression method for video and an actual file (stream) format for a movie, and I don't know if it can be validly said that the format of the stream ppmtompeg produces is MPEG-1. ๐Ÿซ 

Mencoder from the Mplayer package is probably superior for most video format generation needs, if for no other reason than that it is more popular. ngl, that's a little shady of it but ok.

The programming library PM2V generates MPEG-2 streams.

Use Mplayer (not part of Netpbm) to do the reverse conversion: to create a series of PNM files from an MPEG stream. ๐Ÿ”

param_file is a parameter file which includes a list of input files and other parameters. The file is described in detail below. ๐Ÿ‘‡

To understand this program, you need to understand something about the complex MPEG-1 format. One source of information about this standard format is the section Introduction to MPEG in the Compression FAQ. ๐Ÿ“š


๐Ÿ’… OPTIONS ๐Ÿ’…

okay first the drama: the -gop, -combine_gops, -frames, and -combine_frames options are all mutually exclusive. pick ONE. they cannot all be together, it's giving toxic love triangle ๐Ÿ˜ญ

  • -stat stat_file โ€” this option causes ppmtompeg to append the statistics that it writes to Standard Output to the file stat_file as well. those statistics use these abbreviations: bits per block (bpb), bits per frame (bpf), seconds per frame (spf), and bits per second (bps). โœจ these statistics include how many I, P, and B frames there were, plus info about compression and quality.
  • -quiet num_seconds โ€” causes ppmtompeg not to report remaining time more often than every num_seconds seconds (unless the time estimate rises, which will happen near the beginning of the run โ€” yeah it's messy at the start, we know ๐Ÿ™ˆ). a negative value tells ppmtompeg not to report at all. 0 is the default (reports once after each frame). note that the time remaining is an estimate and does not take into account time to read in frames. so like, don't come for it ๐Ÿ’€
  • -realquiet โ€” causes ppmtompeg to run silently, with the only screen output being errors. particularly useful when reading input from stdin. this is the equivalent of the -quiet common option of most other Netpbm programs. shhh ๐Ÿคซ
  • -no_frame_summary โ€” this option prevents ppmtompeg from printing a summary line for each frame. no play-by-play, just vibes.
  • -float_dct โ€” forces ppmtompeg to use a more accurate, yet more computationally expensive version of the DCT. accuracy is expensive bestie, main character energy costs ๐Ÿ’ธ
  • -gop gop_num โ€” causes ppmtompeg to encode only the numbered GOP (first GOP is 0). the parameter file is the same as for normal usage. the output file will be the normal output file with the suffix .gop.gop_num. ppmtompeg does not output any sequence information.
  • -combine_gops โ€” causes ppmtompeg simply to combine some GOP files into a single MPEG output stream. ppmtompeg inserts a sequence header and trailer. in this case, the parameter file needs only to contain the SIZE value, an output file, and perhaps a list of input GOP files (see below).

If you don't supply a list of input GOP files, then ppmtompeg assumes you're using the same parameter file you used when you created the input (with the -gop option) and calculates the corresponding gop filenames itself. If this is not the case, you can specify input GOP files in the same manner as normal input files โ€” except instead of using INPUT_DIR, INPUT, and END_INPUT, use GOP_INPUT_DIR, GOP_INPUT, and GOP_END_INPUT. If no input GOP files are specified, then the default is to use the output file name with suffix .gop.gop_num, with gop_num starting from 0, as the input files.

Thus, unless you're mixing and matching GOP files from different sources, you can simply use the same parameter file for creating the GOP files (-gop) and for later turning them into an MPEG stream (-combine_gops). two birds, one parameter file ๐Ÿฆ๐Ÿฆ

  • -frames first_frame last_frame โ€” this option causes ppmtompeg to encode only the frames numbered first_frame to last_frame, inclusive. the parameter file is the same as for normal usage. the output will be placed in separate files, one per frame, with the file names being the normal output file name with the suffix .frame.frame_num. no GOP header information is output. (thus, the parameter file need not include the GOP_SIZE value)

Use ppmtompeg -combine_frames to combine these frames later into an MPEG stream. โœจ

  • -combine_frames โ€” this option causes ppmtompeg simply to combine some individual MPEG frames (such as you might have created with an earlier run of ppmtompeg -frames) into a single MPEG stream. sequence and GOP headers are inserted appropriately. in this case, the parameter file needs to contain only the SIZE value, the GOP_SIZE value, an output file, and perhaps a list of frame files (see below).

The parameter file may specify input frame files in the same manner as normal input files โ€” except instead of using INPUT_DIR, INPUT, and END_INPUT, use FRAME_INPUT_DIR, FRAME_INPUT, and FRAME_END_INPUT. If no input frame files are specified, then the default is to use the output file name with suffix .frame.frame_num, with frame_num starting from 0, as the input files. ๐ŸŽ€

  • -nice โ€” this option causes ppmtompeg to run any remote processes "nicely," i.e. at low priority. (this is relevant only if you are running ppmtompeg in parallel mode. otherwise, there are no remote processes). see man nice. ๐Ÿงš
  • -max_machines num_machines โ€” this option causes ppmtompeg to use no more than num_machines machines as slaves for use in parallel encoding. build your lil squad ๐Ÿ‘‘
  • -snr โ€” this option causes ppmtompeg to include the signal-to-noise ratio in the reported statistics. prints SNR (Y U V) and peak SNR (Y U V) for each frame. in summary, prints averages of luminance only (Y). SNR is defined as 10*log(variance of original/variance of error). peak SNR is defined as 20*log(255/RMSE). note that ppmtompeg runs a little slower when you use this option. worth it tho ๐Ÿ“‰๐Ÿ“ˆ
  • -mse โ€” this option causes ppmtompeg to report the mean squared error per block. it also automatically reports the quality of the images, so there is no need to specify -snr then. it's giving two for one ๐Ÿ“
  • -bit_rate_info rate_file โ€” this option makes ppmtompeg write bit rate information into the file rate_file. bit rate information is bits per frame, and also bits per I-frame-to-I-frame.
  • -mv_histogram โ€” this option causes ppmtompeg to print a histogram of the motion vectors as part of statistics. there are three histograms โ€” one for P frame, one for forward B frame, and one for backward B frame motion vectors.

The output is in the form of a matrix, each entry corresponding to one motion vector in the search window. The center of the matrix represents (0,0) motion vectors. ๐ŸŽฏ

  • -debug_sockets โ€” this option causes ppmtompeg to print to Standard Output messages that narrate the communication between the machines when you run ppmtompeg in parallel mode. gossip mode, but for machines ๐Ÿ’ฌ
  • -debug_machines โ€” this option causes ppmtompeg to print to Standard Output messages that narrate the progress of the conversion on the various machines when you run ppmtompeg in parallel mode. every machine gets a little narration arc ๐Ÿซถ

๐ŸŒˆ PARAMETER FILE ๐ŸŒˆ

The parameter file must contain the following lines (except when using the -combine_gops or -combine_frames options). no skipping, bestie ๐Ÿ“

  • PATTERN pattern โ€” this statement specifies the pattern (sequence) of I frames, P frames, and B frames. pattern is just a sequence of the letters I, P, and B with nothing between. example:
    PATTERN IBBPBBPBBPBBPBB
</pre>

See I Frames, P Frames, B Frames. (yes there is a stray </pre> in there, it's canon, we don't question the ancestors ๐Ÿ’€)

  • OUTPUT output file โ€” this names the file where the output MPEG stream goes. ๐Ÿ“ผ
  • INPUT_DIR directory โ€” this statement tells where the input images (frames) come from. if each frame is in a separate file, directory is the directory where they all are. you may use . to refer to the current directory. a null directory refers to the root directory of the system file tree. ๐ŸŒณ

To have ppmtompeg read all the frames serially from Standard Input, specify

    INPUT_DIR stdin
  • INPUT โ€” this line must be followed by a list of the input files (in display order) and then the line END_INPUT.

There are three types of lines between INPUT and END_INPUT:

  1. a line may simply be the name of an input file. ๐Ÿ“„
  2. the line may be of the form single_star_expr [x-y]. single_star_expr can have a single * in it. it is replaced by all the numbers between x and y inclusive. so, for example, the line tennis*.ppm [12-15] refers to the files tennis12.ppm, tennis13.ppm, tennis14.ppm, tennis15.ppm. cute ๐ŸŽพ
  3. The third type of line is: single_star_expr [x-y+s], where the line is treated exactly as above, except that we skip by s. thus, the line football.*.ppm [001-130+4] refers to the files football.001.ppm, football.005.ppm, football.009.ppm, football.013.ppm, etc. skipping through the numbers like it's nothing ๐Ÿˆ

Uniform zero-padding occurs, as well. for example, the line football.*.ppm [001-130] refers to the files football.001.ppm, football.002.ppm, ..., football.009.ppm, football.010.ppm, ..., football.130.ppm. the zeros are SERVING ๐Ÿ’…

Furthermore, a line may specify a shell command to execute to generate lines to be interpreted as described above, as if those lines were in the parameter file instead. use back ticks, like in the Bourne Shell, like this:

`cat myfilelist`

If input is from Standard Input (per the INPUT_DIR statement), ppmtompeg ignores the INPUT/END_INPUT block, but it still must be present. yep, still gotta be there. the vibes require it ๐Ÿซ 

  • BASE_FILE_FORMAT {PPM | PNM | YUV | JPEG | JMOVIE} โ€” bestie, this is a big one. ppmtompeg literally cannot start doing anything until every single input file has been converted into ONE of these formats: PNM, YUV, JPEG(v4), or JMOVIE. (And ngl, the conversion might be a total no-op if your files are already living in one of those formats. She's easy like that ๐Ÿ’…). So this line picks which of the four. Fun fact: PPM is actually just a subset of PNM, and the reason you can write PPM separately is purely for backward compatibility. In new applications, use PNM, not PPM. Periodt.
  • INPUT_CONVERT conversion_command โ€” you have GOT to tell her how to convert a file into the base file format. If no conversion is needed at all, you just say:
INPUT_CONVERT *

Otherwise, conversion_command is a shell command that makes an image โ€” in the format you picked with BASE_FILE_FORMAT โ€” get written to Standard Output. ppmtompeg runs that command once for every line between INPUT and END_INPUT (that line is normally, but not necessarily, a file name). Inside the conversion command, ppmtompeg swaps each * out for the contents of that line. Iconic substitution behaviour, honestly.

Had a pile of gif files? You'd say:

INPUT_CONVERT giftopnm *

Got a bunch of separate a.Y, a.U, and a.V files (where the U and V have already been subsampled)? Then you'd say:

INPUT_CONVERT cat *.Y *.U *.V
โš ๏ธ Input conversion is not allowed when the input is coming from stdin, so in that case just use INPUT_CONVERT * as described up there. No cap. ๐Ÿ™ˆ
  • SIZE widthxheight โ€” width and height are the width and height of every frame, in pixels.

When ppmtompeg can pull this info out of the input image files herself, she ignores the SIZE parameter and you can just omit it entirely. Slay.

But when the image files are in YUV format, the files don't carry dimension info, so SIZE is required. ๐Ÿ˜ญ

And when ppmtompeg is running in parallel mode, not every process in the network has access to the image files, so SIZE is required too โ€” and it has to give the same dimensions as the input image files.

  • YUV_SIZE widthxheight โ€” this is an obsolete synonym of SIZE. She's giving legacy, we don't use her anymore ๐Ÿ’€.
  • YUV_FORMAT {ABEKAS | PHILLIPS | UCB | EYUV | pattern} โ€” this one only means anything when BASE_FILE_FORMAT says YUV format, and in that case it's required. It specifies the sub-format of the YUV class.
  • GOP_SIZE n โ€” n is the number of frames in a Group of Pictures. Except โ€” plot twist โ€” because a GOP has to start with an I frame, ppmtompeg makes a GOP as much longer than n as it needs to, so that the next GOP starts with an I frame.

Normally it makes sense to make your GOP size a multiple of your pattern length (and that pattern length is set by the PATTERN parameter file statement).

See Group Of Pictures for the tea. โœจ

  • SLICES_PER_FRAME n โ€” n is roughly the number of slices per frame. Heads up though: at least one MPEG player may start complaining if slices don't start at the left side of the image. To make sure that never happens, make sure the number of rows is divisible by SLICES_PER_FRAME.
  • PIXEL {FULL | HALF} โ€” use half-pixel motion vectors, or just full-pixel ones. It's usually important that you use half-pixel motion vectors, because it results in both better quality AND better compression. Bestie, that's a two-for-one, take it. ๐Ÿ‘‘
  • RANGE n โ€” use a search range of n pixels in each of the four directions from a subject pixel. (So the search window is a square, n*2 pixels on a side).
  • PSEARCH_ALG {EXHAUSTIVE | TWOLEVEL | SUBSAMPLE | LOGARITHMIC} โ€” this statement tells ppmtompeg what kind of search technique (algorithm) to use for P frames. You pick your desired combo of speed and compression:
    • EXHAUSTIVE gives the best compression.
    • LOGARITHMIC is the fastest.
    • TWOLEVEL is an exhaustive full-pixel search, followed by a local half-pixel search around the best full-pixel vector (the PIXEL option is ignored for this search technique).
  • BSEARCH_ALG {SIMPLE | CROSS2 | EXHAUSTIVE} โ€” same energy, but this one tells ppmtompeg what kind of search technique (algorithm) to use for B frames:
    • SIMPLE means find the best forward and backward vectors, then interpolate.
    • CROSS2 means find those two vectors, then see what backward vector best matches the best forward vector, and vice versa.
    • EXHAUSTIVE does an n-squared search and is extremely slow in relation to the others (CROSS2 is about half as fast as SIMPLE). ๐Ÿ’€
  • IQSCALE n โ€” use n as the qscale for I frames. See Qscale.
  • PQSCALE n โ€” use n as the qscale for P frames. See Qscale.
  • BQSCALE n โ€” use n as the qscale for B frames. See Qscale.
  • REFERENCE_FRAME {ORIGINAL | DECODED} โ€” this statement decides whether ppmtompeg uses the original images or the decoded images when computing motion vectors.

Using decoded images is more accurate and should bump up the playback quality of your output, but it makes encoding take longer and seems to give worse compression. It also causes some complications with parallel encoding (see the section on parallel encoding, bestie, that one's a whole thing). One trade-off you can do: pick ORIGINAL here, and lower the qscale (see QSCALE) if the quality isn't good enough.

Original or Decoded? (Normalized) ๐Ÿฆ‹

Reference   Compression   Speed   Quality I   Quality P   Quality B
  Decoded      1000       1000      1000         969         919
 Original       885       1373      1000         912         884

The following lines are optional:

  • FORCE_ENCODE_LAST_FRAME โ€” literally does nothing. This statement is obsolete. โœจ

Before Netpbm 10.26 (January 2005), ppmtompeg would drop trailing B frames from your movie, since a movie can't end with a B frame (see I Frames, P Frames, B Frames). You'd have to specify FORCE_ENCODE_LAST_FRAME to stop that from happening and get the same function that ppmtompeg has today.

  • NIQTABLE โ€” this statement specifies a custom non-intra quantization table. If you don't specify it, ppmtompeg uses a default non-intra quantization table.

The 8 lines immediately following NIQTABLE specify the quantization table. Each line defines one table row and consists of 8 integers, whitespace-delimited, which define the table's columns. Clean, methodical, we love her. ๐ŸŽ€

  • IQTABLE โ€” analogous to NIQTABLE, but for the intra quantization table.
  • ASPECT_RATIO ratio โ€” this statement specifies the aspect ratio for ppmtompeg to specify in the MPEG output. Honestly? I'm not sure what this is used for. ๐Ÿ™ˆ

ratio must be 1.0, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, or 1.2015.

  • FRAME_RATE rate โ€” specifies the frame rate for ppmtompeg to specify in the MPEG output. Some players read this value to figure out the playback rate.

rate must be 23.976, 24, 25, 29.97, 30, 50, 59.94, or 60.

  • BIT_RATE rate โ€” specifies the bit rate for Constant Bit Rate (CBR) encoding.

rate must be an integer.

  • BUFFER_SIZE size โ€” specifies the value ppmtompeg is to specify in the MPEG output for the Video Buffering Verifier (VBV) buffer size needed to decode the sequence.

A Video Verifying Buffer is a buffer where a decoder keeps the decoded bits so it can match the uneven speed of decoding with the required constant playback speed.

As ppmtompeg encodes the image, it simulates the decoding process in terms of how many bits would be sitting in the VBV as each frame gets decoded, assuming a VBV of the size you indicate.

If you specify the WARN_VBV_UNDERFLOW statement, ppmtompeg throws a warning every time the simulation underflows the buffer โ€” which suggests an underflow would happen on playback, which suggests the buffer is too small.

If you specify the WARN_VBV_OVERFLOW statement, ppmtompeg throws a warning every time the simulation overflows the buffer โ€” which suggests an overflow would happen on playback, which suggests the buffer is too small.

  • WARN_VBV_UNDERFLOW
  • WARN_VBV_OVERFLOW โ€” see BUFFER_SIZE.

These options were new in Netpbm 10.26 (January 2005). Before that, ppmtompeg issued the warnings always. ๐ŸŒˆ

The following statements apply only to parallel operation:

  • PARALLEL โ€” this statement, paired with END PARALLEL, is the thing that makes ppmtompeg operate in parallel mode. See Parallel Operation.
  • END PARALLEL โ€” this goes with PARALLEL.
  • PARALLEL_TEST_FRAMES n โ€” the master starts off by measuring each slave's speed. She does this by handing each slave n frames to encode and noting how long the slave takes to finish.

These are not just test frames though โ€” they're real frames, and the results become part of the output. ppmtompeg is old and measures time in undivided seconds, so to get useful timings, specify enough frames that it'll take at least 5 seconds to process them. The default is 10.

If you specify FORCE_I_ALIGN, ppmtompeg will increase the test frames value enough to maintain the alignment.

And if there aren't enough frames for every slave to get the indicated number of test frames, ppmtompeg will give some slaves fewer. It's giving fairness era. ๐Ÿซถ

  • PARALLEL_TIME_CHUNKS t โ€” when you specify this statement, the master tries to feed work to the slaves in chunks that take t seconds to process. It uses the speed measurement it made when it started up (see PARALLEL_TEST_FRAMES) to decide how many frames go in the chunk.

This statement obviously doesn't affect the first batch of work sent to each slave โ€” that's the one used to measure the slave's speed.

Smaller values of t increase communication, but improve load balancing. The default is 30 seconds. ๐Ÿ’œ

  • PARALLEL_CHUNK_TAPER โ€” okay so when you drop this statement in, the master distributes work exactly like it does with PARALLEL_TIME_CHUNKS, except the master is the one choosing how many seconds each chunk gets. ๐ŸŽ€ It kicks off with a big number and then, as it gets closer to finishing the job, it shrinks it down. Why tho? Because that way it cuts the scheduling overhead when being precise about scheduling isn't actually helping anything, but it still stops a slave from finishing early โ€” after all the work has already been handed out to the other slaves โ€” and then just sitting there idle while there's still work to do. ๐Ÿ’…

You may specify only one of PARALLEL_TIME_CHUNKS, PARALLEL_CHUNK_TAPER, and PARALLEL_PERFECT. PARALLEL_CHUNK_TAPER is usually best. ๐Ÿซถ

  • PARALLEL_PERFECT โ€” if this statement is present, ppmtompeg schedules on the assumption that every machine is about the same speed. The master just divides up the frames evenly between the slaves โ€” each slave gets the same number of frames, periodt. So if some slaves are faster than others, they'll finish first and then sit there idle while the slower slaves keep going. ๐Ÿ˜ญ

The glow-up here is minimal scheduling overhead. But where slaves run at different speeds it makes inefficient use of the fast ones, ngl. And where the slaves are the same speed, it's got another downside: they all finish at the exact same time and feed their output to the single Combine Server in one big burst ๐Ÿ’€, which means the Combine Server gets used less efficiently and that can bump up the total elapsed time.

You may specify only one of PARALLEL_TIME_CHUNKS, PARALLEL_CHUNK_TAPER, and PARALLEL_PERFECT. PARALLEL_CHUNK_TAPER is usually best. โœจ

  • RSH remote_shell_command โ€” ppmtompeg runs the shell command remote_shell_command to start a process on another machine. The default command is rsh, and whatever command you specify has to have compatible semantics. ssh is usually compatible. ๐ŸŒˆ The command ppmtompeg uses is one like this: ssh remote.host.com -l username shellcommand.

Be sure to set up .rhosts files or SSH key authorizations where needed. Otherwise you'll be typing in passwords like it's 2004. ๐Ÿ™ˆ

On some HP machines, rsh is the restricted shell, and what you actually want to specify is remsh.

  • FORCE_I_ALIGN โ€” this statement forces each slave to encode a chunk of frames which is a multiple of the pattern length (peep PATTERN). Since the first frame in any pattern is an I frame, this forces each chunk encoded by a slave to begin with an I frame. iconically tidy, honestly. ๐Ÿ’–

This document used to say there was an argument to FORCE_I_ALIGN which was the number of frames ppmtompeg would use (and was required to be a multiple of the pattern length). But ppmtompeg has apparently always ignored that argument, and it does now. ๐Ÿ’€

  • KEEP_TEMP_FILES โ€” this statement makes ppmtompeg not delete the temporary files it uses to transmit encoded frames to the combine server. So you'll be left with a file for each frame, the same as you'd get with the -frames option. ๐Ÿ“

This is mostly useful for debugging.

This works only if you're using a shared filesystem to communicate between the servers. ๐Ÿ‘‘

This option was new in Netpbm 10.26 (January 2005).


๐Ÿ’Œ Parameter File Notes ๐Ÿ’Œ

If you use the -combine_gops option, then you need to specify only the SIZE and OUTPUT values in the parameter file. On top of that, the parameter file may specify input GOP files in the same manner as normal input files โ€” except instead of using INPUT_DIR, INPUT, and END_INPUT, you use GOP_INPUT_DIR, GOP_INPUT, and GOP_END_INPUT. ๐Ÿฆ‹ And if you specify no input GOP files, then ppmtompeg uses by default the output file name with suffix .gop.gop_num, with gop_num starting from 0, as the input files.

If you use the -combine_frames option, then you need to specify only the SIZE, GOP_SIZE, and OUTPUT values in the parameter file. Same deal โ€” the parameter file may specify input frame files in the same manner as normal input files, except instead of using INPUT_DIR, INPUT, and END_INPUT, you use FRAME_INPUT_DIR, FRAME_INPUT, and FRAME_END_INPUT. If no input frame files are specified, then the default is to use the output file name with suffix .frame.frame_num, with frame_num starting from 0, as the input files. โœจ

Any number of spaces and tabs may come between each option and value. Lines beginning with # are ignored. Any other lines are ignored except for those between INPUT and END_INPUT. This lets you use the same parameter file for normal usage and for -combine_gops and -combine_frames. that's the neat part fr fr ๐Ÿ’…

The file format is case-sensitive so all keywords should be in upper case. ๐Ÿšจ

The statements may appear in any order, except that the order within a block statement (such as INPUT ... END INPUT) is significant.

ppmtompeg is prepared to handle up to 16 B frames between reference frames when encoding with input from stdin. (To build a modified ppmtompeg with a higher limit, change the constant B_FRAME_RUN in frame.c and recompile). ๐ŸŽ€

โœจ GENERAL USAGE INFORMATION โœจ

ok so this is the part where we get into the actual brain of how this thing works. buckle up bestie, there's charts. ๐Ÿ“Š


Qscale

Qscale values (that's quantization scale, iykyk) are the trade-off dial between quality and compression. The cute part? Fiddling with Qscale numbers has basically almost no effect on speed. And you get to set them separately for I, P, and B frames. main character privilege fr. ๐Ÿ‘‘

You pick your qscale values with the IQSCALE, PQSCALE, and BSCALE parameter file statements.

A qscale value is an integer from 1 to 31. Bigger number = better compression but worse quality. And in the tables below, the quality numbers are peak signal-to-noise ratio, defined as: signal-to-noise formula where MSE is the mean squared error. (yes we're doing math, stay with me ๐Ÿงฎ)

Flower garden tests:

Qscale vs Quality

Qscale   I Frames   P Frames   B Frames
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
     1       43.2       46.3       46.5
     6       32.6       34.6       34.3
    11       28.6       29.5       30.0
    16       26.3       26.8       28.6
    21       24.7       25.0       27.9
    26       23.5       23.9       27.5
    31       22.6       23.0       27.3

Qscale vs Compression

Qscale   I Frames   P Frames   B Frames
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
     1          2          2          2
     6          7         10         15
    11         11         18         43
    16         15         29         97
    21         19         41        173
    26         24         56        256
    31         28         73        330

Search Techniques

ok so there are several different motion vector search techniques you can use, and listen โ€” there are different ones for P frame search and different ones for B frame search. Switching techniques barely moves the quality needle, but it moves the compression and the speed needle a LOT. it's giving dramatic. ๐Ÿ’…

There are 4 types of P frame search: Exhaustive, TwoLevel, SubSample, and Logarithmic.

There are 3 types of B frame search: Exhaustive, Cross2, and Simple.

The recommended ones are TwoLevel and Logarithmic for P frame search, and Cross2 and Simple for B frame search. and here's the receipts comparing all the methods:

P frame Motion Vector Search (Normalized)

  Technique   Compression 1    Speed 2          Quality 3
              โŸจ#smallbetterโŸฉ   โŸจ#largefasterโŸฉ   โŸจ#largebetterโŸฉ
 Exhaustive        1000             1000             1000
  SubSample        1008             2456             1000
   TwoLevel        1009             3237             1000
Logarithmic        1085             8229              998

B frame Motion Vector Search (Normalized)

 Technique   Compression 1    Speed 2          Quality 3
             โŸจ#smallbetterโŸฉ   โŸจ#largefasterโŸฉ   โŸจ#largebetterโŸฉ
Exhaustive        1000             1000             1000
    Cross2        975              1000              996
    Simple        938              1765              991

1 Smaller numbers are better compression.

2 Larger numbers mean faster execution.

3 Larger numbers mean better quality.

For some reason, Simple seems to give better compression, but it depends on the image sequence. shrug, it's a vibe thing. ๐Ÿคท

Select the search techniques with the PSEARCH_ALG and BSEARCH_ALG parameter file statements.


Group Of Pictures (GOP)

A Group of Pictures (GOP) is a roughly independently decodable sequence of frames. An MPEG video stream is made of one or more GOP's. You can specify how many frames go in each GOP with the GOP_SIZE parameter file statement. And heads up: a GOP always starts with an I frame. always. no exceptions bestie.

Instead of encoding a whole entire sequence, you can encode a single GOP. To do that, use the -gop command option. Then later, whenever you feel like it, you can join those resulting GOP files back together by running ppmtompeg with the -combine_gops command option. ๐Ÿซถ


Slices

A slice is an independently decodable unit inside a frame. It can be as tiny as one macroblock, or as chunky as the entire frame. And barring transmission error, adding slices doesn't change quality or speed at all โ€” the only effect is slightly worse compression. More slices = for noisy transmission, so errors are more recoverable. Since usually errors aren't such a problem, we usually just use one slice per frame. lowkey the default vibe.

Control the slice size with the SLICES_PER_FRAME parameter file statement.

Some MPEG playback systems require that each slice consist of whole rows of macroblocks. If you're encoding for that kind of player, and the height of the image is H pixels, then you should set the SLICES_PER_FRAME to some number which divides H/16. For example, if the image is 240 pixels (15 macroblocks) high, then you should use only 15, 5, 3, or 1 slices per frame.

Note: these MPEG playback systems are really wrong, since the MPEG standard says this doesn't have to be so. ๐Ÿ’€ not me calling out the legacy players but here we are.

Search Window

The search window is the window in which ppmtompeg searches for motion vectors. And guess what โ€” the window is a square. ๐Ÿ”ฒ You can specify the size of that square, and whether to allow half-pixel motion vectors or not, with the RANGE and PIXEL parameter file statements.


I Frames, P Frames, B Frames

In MPEG-1, a movie is represented as a sequence of MPEG frames, and each one is an I Frame, a P Frame, or a B Frame. Each represents an actual frame of the movie โ€” and pls don't get confused by the dual use of the word "frame." A movie frame is a graphical image. An MPEG frame is a set of data that describes a movie frame. two different things, same word, chaos. ๐Ÿ™ˆ

So:

  • An I frame ("intra" frame) describes a movie frame in isolation โ€” without respect to any other frame in the movie.
  • A P frame ("predictive" frame) describes a movie frame by describing how it differs from the movie frame described by the latest preceding I or P frame.
  • A B frame ("bidirectional" frame) describes a movie frame by describing how it differs from the movie frames described by the nearest I or P frame before and after it.
Note that the first frame of a movie must be described by an I frame (because there is no previous movie frame) and the last movie frame must be described by an I or P frame (because there is no subsequent movie frame). no cap, that's just the rules.

Beyond that? You get to choose which frames are represented by which types. You specify a pattern, like IBPBP, and ppmtompeg simply repeats it over and over throughout the movie. That pattern affects speed, quality, and stream size. here's a chart showing some of the trade-offs:

Comparison of I/P/B Frames (Normalized)

Frame Type   Size   Speed   Quality
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  I frames   1000   1000     1000
  P frames   409     609      969
  B frames    72     260      919

(this is with constant qscale, jsyk)

A standard sequence is IBBPBBPBBPBBPBB. โœจ iconic, honestly.

Select the sequence with the PATTERN parameter file statement.

Since the last MPEG frame cannot be a B frame (see above ๐Ÿ‘†), if the pattern you specify indicates a B frame for the last movie frame of the movie, ppmtompeg makes it an I frame instead.

Before Netpbm 10.26 (January 2005), ppmtompeg instead drops the trailing B frames by default, and you needed the FORCE_ENCODE_LAST_FRAME parameter file statement to make it do this. ๐Ÿ•ฐ๏ธ throwback behavior.

The MPEG frames don't appear in the MPEG-1 stream in the same order that the corresponding movie frames appear in the movie โ€” the B frames come after the I and P frames on which they're based. For example, if the movie is 4 frames that you will represent with the pattern IBBP, the MPEG-1 stream will start with an I frame describing movie frame 0. The next frame in the MPEG-1 stream is a P frame describing movie frame 3. The last two frames in the MPEG-1 stream are B frames describing movie frames 1 and 2, respectively. yes it's out of order. it's fine. it's โœจencodedโœจ. ๐ŸŒˆ


Specifying Input and Output Files

Specify the input frame images with the INPUT_DIR, INPUT, END_INPUT, BASE_FILE_FORMAT, SIZE, YUV_FORMAT and INPUT_CONVERT parameter file statements. that's the whole squad. ๐Ÿซ‚

Specify the output file with the OUTPUT parameter file statement.


Statistics

ppmtompeg can generate a whole variety of statistics about the encoding, if you're nosy like me (I am). See the -stat, -snr, -mv_histogram, -quiet, -no_frame_summary, and -bit_rate_info options. ๐Ÿ“ˆโœจ

๐Ÿ”ฅ PARALLEL OPERATION ๐Ÿ”ฅ

okay bestie, this is the part where things get iconic. you can run ppmtompeg on multiple machines at once, all encoding the same MPEG stream together. when you do that, the machines get used like the diagram shows. we call this "parallel mode." ๐Ÿ’…

ppmtompeg-par.gif

to do parallel processing, you drop the statement

PARALLEL

into your parameter file, then list the machines (one per line, bestie, one per line), then close it out with

END_PARALLEL

Each machine line has to be in one of two forms, no in-between. โœจ

  • if the machine does have filesystem access to the input files, the line is: machine user executable
  • if the machine does not have filesystem access to the input files, the line is: REMOTE machine user executable parameter file

The executable is normally ppmtompeg (tho you might need to give the complete path if you've built for different architectures ๐Ÿ‘€).

The -max_machines command option limits the number of machines ppmtompeg will use. and the way this works is so handy: if you specify more machines in the parameter file than -max_machines allows, ppmtompeg uses only the machines listed first. so if you wanna experiment with different amounts of parallelism, this is your girl. ๐ŸŽ€

In general, you should use full path file names when describing executables and parameter files. this includes the parameter file argument on the original invocation of ppmtompeg, mmk?

All file names must be the same on all systems (so if e.g. you're using an NFS filesystem, you must make sure it is mounted at the same mountpoint on all systems).

Because not all of the processes involved in parallel operation have easy access to the input files, you must specify the SIZE parameter file statement when you do parallel operation. no skipping, bestie. ๐Ÿ˜ค

The machine on which you originally invoke ppmtompeg is the master machine. ๐Ÿ‘‘ It hosts a "combine server,", a "decode server," and a number of "i/o servers," all as separate processes. The other machines in the network (listed in the parameter file) are slave machines. Each hosts a single process that continuously requests work from the master and does it. The slave process does the computation to encode MPEG frames. It processes frames in batches identified by the master.

The master uses a remote shell command to start a process on a slave machine. By default, it uses an rsh shell command to do this. But use the RSH parameter file statement to control this. The shell command the master executes remotely is ppmtompeg, but with options to indicate that it is to perform slave functions. ๐Ÿซถ

The various machines talk to each other over TCP connections. Each machine finds and binds to a free TCP port number and tells its partners the port number. These port numbers are at least 2048.

Use the PARALLEL_TEST_FRAMES, PARALLEL_TIME_CHUNKS, and PARALLEL_PERFECT parameter file statements to control the way the master divides up work among the slaves. โœจ

Use the -nice command option to cause all slave processes to run "nicely," i.e. as low priority processes. That way, this substantial and long-running CPU load will have minimal impact on other, possibly interactive, users of the systems. considerate queen behavior, fr fr. ๐Ÿ’–


โšก SPEED โšก

so here's a lil look at ppmtompeg speed, in single-node (not parallel) operation:

Compression Speed

  • HP 9000/755 โ€” 280 Macroblocks per second^1
  • DEC 3000/400 โ€” 247 Macroblocks per second^1
  • HP 9000/750 โ€” 191 Macroblocks per second^1
  • Sparc 10 โ€” 104 Macroblocks per second^1
  • DEC 5000 โ€” 68 Macroblocks per second^1

^1 A macroblock is a 16x16 pixel square

The measurements in the table are with inputs and outputs via a conventional locally attached filesystem. If you are using a network filesystem over a single 10 MB/s Ethernet, that constrains your speed more than your CPU speed. In that case, don't expect to get better than 4 or 5 frames per second no matter how fast your CPUs are. ๐Ÿ˜ญ

Network speed is even more of a bottleneck when the slaves do not have filesystem access to the input files โ€” i.e. you declare them REMOTE.

Where I/O is the bottleneck, size of the input frames can make a big difference. So YUV input is better than PPM, and JPEG is better than both. ๐ŸŒˆ

When you're first trying to get parallel mode working, be sure to use the -debug_machines option so you can see what's going on. Also, -debug_sockets can help you diagnose communication problems. debugging besties stay winning. ๐Ÿ”ฅ


๐Ÿ‘‘ AUTHORS ๐Ÿ‘‘

  • Kevin Gong - University of California, Berkeley, keving@cs.berkeley.edu
  • Ketan Patel - University of California, Berkeley, kpatel@cs.berkeley.edu
  • Dan Wallach - University of California, Berkeley, dwallach@cs.berkeley.edu
  • Darryl Brown - University of California, Berkeley, darryl@cs.berkeley.edu
  • Eugene Hung - University of California, Berkeley, eyhung@cs.berkeley.edu
  • Steve Smoot - University of California, Berkeley, smoot@cs.berkeley.edu

๐Ÿ“œ DOCUMENT SOURCE ๐Ÿ“œ

This manual page was generated by the Netpbm tool makeman from HTML source. The master documentation is at

http://netpbm.sourceforge.net/doc/ppmtompeg.html

and that's a wrap, babe! ๐ŸŽ€ this whole thing is netpbm documentation, dated 23 July 2006, and it's the Ppmtompeg User Manual(1). we ate, no crumbs, periodt. ๐Ÿ’…โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from