Skip to content

Deep dive · Inside a job

How a job works inside

What happens between pressing Start Processing and a finished video appearing next to the original, and why each step is built the way it is.

You don't need this page to use AnimeUp. It's for when you want to understand a step on a progress line, a warning in a plan, or why stopping at one moment costs nothing and at another costs a few minutes.

The whole path at a glance

From source file to finished AnimeUp video A vertical flow from INPUT through analysis, planning, checks, extraction in phase 1 of 3, deduplication, the GPU and CPU chunk loop in phase 2 of 3, final encoding and assembly in phase 3 of 3, verification, and a finished MKV in OUTPUT. On success, a job report is saved and the job folder is removed. IN SOURCE FILE INPUT/episode.mkv 01 Analysis Inspect streams, timestamps and frame rate 02 Plan Size, model, scale, chunks and estimate No media processing yet 03 Preflight checks Free space, writable OUTPUT/, job lock 04 PHASE 1/3 Extraction Decode every frame into a PNG One sequential pass 05 Deduplication Identify repeated frames to skip 06 PHASE 2/3 Chunk loop GPU upscale each chunk → restore repeats CPU encode completed segments Final segment is encoded in phase 3 07 PHASE 3/3 Assembly Encode last chunk; join segments Copy audio, subtitles, fonts and chapters 08 Verification Check frame count, size and audio Finished MKV in OUTPUT/ On success: report saved · JOBS/ removed

The four steps on a Queue row map onto it: Extraction, Repeated frames (deduplication), Upscale (the chunk loop, each chunk upscaled and then encoded) and Assemble (joining the chunks and the original's tracks). Verification follows assembly.

1. Analysis

Before anything is planned, AnimeUp works out what the file really contains, with ffprobe and a pass over its timestamps. This is the analysis you see in the Queue's Source tab. A few principles drive it:

  • Timing is measured in whole timebase ticks, never in seconds. MKV stores timestamps to the millisecond, so a 23.976 fps file alternates between 41 and 42 ms per frame. Measured in seconds, every constant-frame-rate file would look variable.
  • The frame rate comes from the average over the whole file, and is snapped to a standard value (23.976, 24, 25, 29.97…) only when the difference is negligible.
  • Variable frame rate, missing frames and telecine are told apart, because each needs a different treatment.
  • The source is never re-encoded to "fix" its timing.

Interlaced or telecined sources are detected and flagged, not treated. Detection can't reliably tell hard telecine from true interlacing, and applying the wrong cure destroys the original progressive frames. Prepare such a source with a dedicated tool first.

The result is saved with AnimeUp's own data and reused until the file changes, so the list opens instantly next time.

Deep analysis (on by default, see Settings) adds one more measurement: how many frames deduplication will be able to skip. It decodes six 4-second windows spread across the file, in a single pass, and applies the same rule the real deduplication uses. Validated against real jobs, it was off by 1.3 percentage points on average. The guess it replaced, based on files of a similar length, was off by 26.9.

2. The plan

The plan turns "what the file is" into "what will be done", without running anything. That's why Compare and the Queue can show sizes, models and estimates instantly.

Output size. The height is your Output height. The width comes from the source's real display aspect ratio, with square pixels, rounded to an even number. Two limits apply:

Rule Value What happens
Maximum enlargement 4× the source height The target is lowered, with a warning ("Target lowered from 1080p to 960p…")
Minimum gain 1.25× The file is refused ("upscale too small") unless Allow small enlargements is on

Model and scale. If you haven't chosen a model, AnimeUp proposes one from the source height. The model upscales by a whole factor (2, 3 or 4), and AnimeUp picks the factor that brings the final resize closest to an exact 2:1 reduction. If no factor of the chosen model reaches the target, the plan is refused, because the gap would be filled by plain interpolation. All of this is in The models and when to use them.

Encoding. x265, 10-bit 4:2:0, your CRF and preset, plus fixed settings tuned for animation: negative deblocking and SAO off to keep lines sharp, aq-mode=3 against banding in flat areas, psy-rd to keep texture. Colour space tags are copied from the source. A source that doesn't declare them gets the usual convention (BT.709 from 720 lines up, BT.601 below).

Chunks and disk space. See Why chunks below.

Estimate. See How the time estimate is built.

3. Before starting: three checks

  1. Disk space. The plan's peak disk use, minus frames already extracted by an earlier run, is compared with the free space, also subtracting what other running jobs have claimed. If it doesn't fit, the job is refused before a single frame is written: "about N GB needed, M GB free". A full disk halfway through wouldn't just ruin this file. It would stall the system and could corrupt other jobs' state.
  2. The output folder is writable. A missing permission used to be discovered at assembly, after hours of GPU work. Now AnimeUp writes a test file into the finished videos' folder first.
  3. The lock. AnimeUp creates running.lock in the job folder, holding its process ID. If another live process holds it, the job refuses to start. A lock left behind by a crashed process is recognised as dead (zombie processes included) and taken over. If the previous owner was killed hard, AnimeUp also kills its orphaned upscaler before starting, so two processes never write the same frames.

4. Extraction

Every frame of the source is decoded once, from start to finish, with no seeking and written to frames/ as an 8-bit RGB PNG.

  • No seeking, because on encodes with many reference frames a fast seek produces reconstructed, approximate frames.
  • 8-bit, because the models work in 8-bit internally and return 8-bit (16-bit input measured 49.7 dB away from 8-bit, i.e. no difference) and 16-bit would quadruple the disk space. 10-bit sources are reduced with dithering here, which is better than the hard truncation the model loader would do.
  • A constant frame grid at the file's frame rate: missing frames are repeated and extra ones dropped, so extraction and the deduplication scan see exactly the same set of frames.
  • Denoise, if you turned it on with the command line's --denoise, is applied here (hqdn3d=1.5:1.5:6:6), before the model sees the frame. The app doesn't offer it: Real-CUGAN light denoise does a better job.

Extraction is the one step that isn't split into chunks: all source frames stay on disk for the whole job. That's why they dominate the disk-space budget.

5. Deduplication

With Skip repeated frames on, AnimeUp measures the difference between each frame and the last frame it kept, and marks a frame as a repeat only if:

no single pixel, on any of the three colour channels, differs by more than 16/255.

This isn't a similarity score. It's an upper bound on the error. If a mouth moves, those pixels change a lot and the frame is kept, however small the moving area. Comparing with the last kept frame, not the previous one, stops a slow fade from being frozen by adding up tiny differences. At most 5 consecutive frames can be skipped, which limits the reach of any mistake to a fraction of a second.

The map is then audited by an independent check on the structure actually used to copy frames. If a frame is found to have been wrongly marked as a repeat, only that frame is put back into the work (a warning says how many). If the map itself is malformed, deduplication is dropped for the file: it costs time, not correctness. The map is saved as dedup.json.

How much it saves depends entirely on the material. On real files it skipped 11% to 57% of frames.

6. Why chunks

The upscaled frames of one episode would need hundreds of gigabytes as PNG. So after extraction the frames are processed in chunks, one after another. Each chunk goes through:

  1. Gather. The frames this chunk needs, minus repeats, are linked (not copied) into chunkNNNN-in/. If a run of repeats crosses the chunk boundary, its reference frame is included.
  2. Upscale. realesrgan-ncnn-vulkan or realcugan-ncnn-vulkan runs on the GPU and writes chunkNNNN-up/. If no new frame appears for 15 minutes the upscaler is declared stuck and the job fails rather than hanging forever. (The slowest frame measured takes under two seconds.)
  3. Restore repeats. The full sequence is rebuilt in chunkNNNN-full/ with hard links: each repeated frame points at its upscaled original, costing no disk space.
  4. Encode. FFmpeg resizes to the exact target with lanczos and encodes with x265 in the same pass, so there's one compression and no intermediate generation. The result is a segment in segments/. This step uses the CPU. On the Queue row it shows as "Encoding chunk 2 of 3 · 40% encoded".
  5. Clean up. The three chunk folders are deleted and the segment is recorded in state.json.

How big a chunk is depends on the Space per file while processing setting, spent in a fixed order:

  1. First the parts that can't be split: all extracted source frames, plus the encoded segments and the final file (both are on disk at the moment of assembly).
  2. What's left goes to the chunk being upscaled.

On top of that, four rules:

Rule Value Why
At least 3 chunks A chunk is atomic: if it's interrupted it restarts. With three chunks a power cut costs at most a third of the work.
At most 20 chunks Each chunk has a fixed cost of about a minute (measured at 1.16 min); beyond 20 that outweighs the savings
Chunk never bigger than 40 GB of upscaled frames Even on a huge disk, one chunk shouldn't hold most of the work an accident could take away. Relaxed if keeping to it would need more than 20 chunks and there's room.
Chunk never smaller than 800 frames Below that the fixed minute weighs more than the work inside

The disk never gets filled beyond 85% of its free space, whatever you set.

Where it's cheapest to stop

Work is secured one chunk at a time. If you stop in the middle of a chunk, that chunk restarts from its first frame on resume. That's why the Queue row also says something like "Upscaling chunk 1 of 3 · 10,900 of 11,350 frames upscaled": it counts down to the next point where a Stop costs nothing. See The Queue.

7. Assembly and remux

When every chunk is encoded, the segments are joined in order and the rest of the source is copied in from the original file:

  • all audio tracks, copied untouched;
  • all subtitle tracks, copied (only the text formats MKV can't hold, mostly mov_text, are converted to SRT);
  • attachments, including fansub fonts;
  • chapters.

Tracks are interleaved strictly by timestamp. Without that, a source with sparse subtitles and fonts once produced a file with all its audio bunched at the start, which players then treated as silent.

The file is written under a temporary name and renamed to its real name only when complete. The rename is atomic, so a truncated file never sits next to the original under a good name.

8. Verification and the job report

The finished file is checked:

Check If it fails
Number of frames equals the number extracted Defect
Width × height equal the target Defect
Audio can be read after seeking into the middle Defect
The frame count couldn't be read at all Warning only

A file with any defect is renamed ….DEFECTIVE.mkv and its job folder is kept for inspection (see Files and folders). Otherwise:

  • a line is added to the history of finished files (records/history.jsonl in AnimeUp's data): real duration (paused time excluded, earlier interrupted runs included), measured deduplication, warnings, model, output name. This is what makes the row say "done", and what future estimates learn from;
  • the job folder is deleted (unless Settings say to keep everything); the log stays.

Warnings (as opposed to defects) don't keep the job folder. A note isn't worth the 31 GB that the extracted frames of a 24-minute 720p episode take.

Pausing

Pause in the Queue doesn't stop anything. It freezes the upscaler or encoder process exactly where it is (a SIGSTOP signal), and Resume wakes it up (SIGCONT). Both programs write one file at a time and hold nothing open between files, so nothing is lost. This was verified byte for byte on the PNGs and with a full decode of the video. The time spent paused is subtracted from the file's recorded duration, so a three-hour pause doesn't distort future estimates.

Resuming: what is kept and what is redone

A job can be interrupted by Stop, Stop All, a crash, a power cut or closing the Mac's lid. Everything needed to resume is in its job folder. When the job starts again, AnimeUp compares two signatures saved in state.json with the current plan:

Signature Made of If it changes
Extraction Source file name and size, denoise filter, frame-rate grid The extracted frames are thrown away and extraction starts again
Job The extraction signature, plus frame count, model, scale, output width and height, codec, pixel format, preset, x265 settings (CRF included), deduplication on/off, frame rate Encoded segments are thrown away. Extracted frames are kept if the extraction signature still matches. The deduplication map is also kept, since it only depends on the frames.

So changing the CRF or the model costs you the encoded chunks but not the hours of extraction. Changing denoise costs everything. Some things are deliberately not in the signature:

  • Disk space and chunk size. These depend on the free space at the moment of planning. When there are segments to protect, a resumed job adopts the chunk layout it started with, so segments already encoded stay valid even if free space or the slider have changed.
  • The source's modification date. It changes with a backup restore or rsync without a single bit of content changing. Only the size counts.

More safeguards on resume:

  • Each saved segment is checked with ffprobe for the exact number of frames it should hold. A truncated segment left by a power cut is redone instead of producing a short video.
  • Segments are recorded by the frame range they cover, not by their number, so a different chunk layout can never stitch the wrong frames together.
  • If extraction produced a different number of frames than when the segments were made (which happens between FFmpeg builds, i.e. between Macs), the segments are discarded rather than reused one frame out of step.

Resume in the app goes one step further: it restarts with the parameters saved in parameters.json when the job first started, whatever Settings say now. That's why resuming from the app can never throw work away. The command line has no such file to go on: running ./animeup run again on the same file uses whatever parameters you give it, and the signatures decide what can be kept.

How the time estimate is built

The estimate on each row is the sum of steps that run one after another:

  • GPU time: frames left after deduplication × source megapixels ÷ the model's speed in megapixels per second at that scale;
  • extraction and the deduplication scan, scaled by the source's pixel count;
  • encoding, scaled by the output's pixel count.

Where those speeds come from:

  1. Factory values, measured on one specific Mac, until you calibrate.
  2. Calibration (records/calibration.json) replaces them with this Mac's real speeds. See Calibrate your Mac.
  3. History (records/history.jsonl): as soon as you've finished some files, the expected deduplication and a correction factor for "work the model doesn't count" (assembly, final checks, idle time) are learned from what similar files actually did.

The estimate is shown as a range. Its lower end assumes the best case already seen, its upper end the worst. Without any history, the upper end adds a 25% safety margin and the lower end assumes deduplication saves up to 60% (the most observed was 57%). Once a job has run for a few minutes, the deduplication actually measured on that file replaces the guess, and the range narrows.

The numbers behind all of this, and what happens if each is wrong, are in TUNING.md.

Before you move on

Check

  • You know the four steps on a Queue row: extraction, repeated frames, upscale in chunks, assembly
  • You know work is secured one chunk at a time
  • You know changing CRF or model on an interrupted job keeps the extracted frames, while changing denoise doesn't
  • You know where the estimate's numbers come from: factory, calibration, history