PPMTOMPEG(1)
๐ 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 ๐ญ
-statstat_file โ this option causesppmtompegto 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.-quietnum_seconds โ causesppmtompegnot 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 tellsppmtompegnot to report at all.0is 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โ causesppmtompegto run silently, with the only screen output being errors. particularly useful when reading input from stdin. this is the equivalent of the-quietcommon option of most other Netpbm programs. shhh ๐คซ-no_frame_summaryโ this option preventsppmtompegfrom printing a summary line for each frame. no play-by-play, just vibes.-float_dctโ forcesppmtompegto use a more accurate, yet more computationally expensive version of the DCT. accuracy is expensive bestie, main character energy costs ๐ธ-gopgop_num โ causesppmtompegto encode only the numbered GOP (first GOP is0). 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.ppmtompegdoes not output any sequence information.-combine_gopsโ causesppmtompegsimply to combine some GOP files into a single MPEG output stream.ppmtompeginserts 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 ๐ฆ๐ฆ
-framesfirst_frame last_frame โ this option causesppmtompegto 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 causesppmtompegsimply to combine some individual MPEG frames (such as you might have created with an earlier run ofppmtompeg -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 causesppmtompegto run any remote processes "nicely," i.e. at low priority. (this is relevant only if you are runningppmtompegin parallel mode. otherwise, there are no remote processes). seeman nice. ๐ง-max_machinesnum_machines โ this option causesppmtompegto use no more than num_machines machines as slaves for use in parallel encoding. build your lil squad ๐-snrโ this option causesppmtompegto 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 as10*log(variance of original/variance of error). peak SNR is defined as20*log(255/RMSE). note thatppmtompegruns a little slower when you use this option. worth it tho ๐๐-mseโ this option causesppmtompegto report the mean squared error per block. it also automatically reports the quality of the images, so there is no need to specify-snrthen. it's giving two for one ๐-bit_rate_inforate_file โ this option makesppmtompegwrite 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 causesppmtompegto 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 causesppmtompegto print to Standard Output messages that narrate the communication between the machines when you runppmtompegin parallel mode. gossip mode, but for machines ๐ฌ-debug_machinesโ this option causesppmtompegto print to Standard Output messages that narrate the progress of the conversion on the various machines when you runppmtompegin 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 ๐
PATTERNpattern โ this statement specifies the pattern (sequence) of I frames, P frames, and B frames. pattern is just a sequence of the lettersI,P, andBwith 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 ๐)
OUTPUToutput file โ this names the file where the output MPEG stream goes. ๐ผINPUT_DIRdirectory โ 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 lineEND_INPUT.
There are three types of lines between INPUT and END_INPUT:
- a line may simply be the name of an input file. ๐
- 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 linetennis*.ppm [12-15]refers to the filestennis12.ppm,tennis13.ppm,tennis14.ppm,tennis15.ppm. cute ๐พ - 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 linefootball.*.ppm [001-130+4]refers to the filesfootball.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.ppmtompegliterally cannot start doing anything until every single input file has been converted into ONE of these formats:PNM,YUV,JPEG(v4), orJMOVIE. (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:PPMis actually just a subset ofPNM, and the reason you can writePPMseparately is purely for backward compatibility. In new applications, usePNM, notPPM. 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โwidthandheightare 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 ofSIZE. She's giving legacy, we don't use her anymore ๐.YUV_FORMAT {ABEKAS | PHILLIPS | UCB | EYUV | pattern}โ this one only means anything whenBASE_FILE_FORMATsaysYUVformat, and in that case it's required. It specifies the sub-format of theYUVclass.GOP_SIZE nโnis the number of frames in a Group of Pictures. Except โ plot twist โ because a GOP has to start with an I frame,ppmtompegmakes a GOP as much longer thannas 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โnis 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 bySLICES_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 ofnpixels in each of the four directions from a subject pixel. (So the search window is a square,n*2pixels on a side).PSEARCH_ALG {EXHAUSTIVE | TWOLEVEL | SUBSAMPLE | LOGARITHMIC}โ this statement tellsppmtompegwhat kind of search technique (algorithm) to use for P frames. You pick your desired combo of speed and compression:EXHAUSTIVEgives the best compression.LOGARITHMICis the fastest.TWOLEVELis an exhaustive full-pixel search, followed by a local half-pixel search around the best full-pixel vector (thePIXELoption is ignored for this search technique).
BSEARCH_ALG {SIMPLE | CROSS2 | EXHAUSTIVE}โ same energy, but this one tellsppmtompegwhat kind of search technique (algorithm) to use for B frames:SIMPLEmeans find the best forward and backward vectors, then interpolate.CROSS2means find those two vectors, then see what backward vector best matches the best forward vector, and vice versa.EXHAUSTIVEdoes an n-squared search and is extremely slow in relation to the others (CROSS2is about half as fast asSIMPLE). ๐
IQSCALE nโ usenas the qscale for I frames. See Qscale.PQSCALE nโ usenas the qscale for P frames. See Qscale.BQSCALE nโ usenas the qscale for B frames. See Qscale.REFERENCE_FRAME {ORIGINAL | DECODED}โ this statement decides whetherppmtompeguses 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,ppmtompeguses 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 toNIQTABLE, but for the intra quantization table.ASPECT_RATIO ratioโ this statement specifies the aspect ratio forppmtompegto 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 forppmtompegto 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 valueppmtompegis 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_UNDERFLOWWARN_VBV_OVERFLOWโ seeBUFFER_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 withEND PARALLEL, is the thing that makesppmtompegoperate in parallel mode. See Parallel Operation.END PARALLELโ this goes withPARALLEL.PARALLEL_TEST_FRAMES nโ the master starts off by measuring each slave's speed. She does this by handing each slavenframes 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 taketseconds to process. It uses the speed measurement it made when it started up (seePARALLEL_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 withPARALLEL_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,ppmtompegschedules 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. โจ
RSHremote_shell_command โppmtompegruns the shell command remote_shell_command to start a process on another machine. The default command isrsh, and whatever command you specify has to have compatible semantics.sshis usually compatible. ๐ The commandppmtompeguses 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 (peepPATTERN). 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 makesppmtompegnot 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-framesoption. ๐
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 โ
280Macroblocks per second^1 - DEC 3000/400 โ
247Macroblocks per second^1 - HP 9000/750 โ
191Macroblocks per second^1 - Sparc 10 โ
104Macroblocks per second^1 - DEC 5000 โ
68Macroblocks 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
- debian bookworm: netpbm 2:11.01.00-2 ยท MIT
- debian trixie: netpbm 2:11.10.02-1 ยท MIT
- ubuntu noble: netpbm 2:11.05.02-1.1build1 ยท MIT
- ubuntu resolute: netpbm 2:11.10.02-1build1 ยท MIT
- ubuntu stonking: netpbm 2:11.13.03+ds-2 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms