edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBba75450Tahinli5 days ago3985 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Wrap raw planar yuv420p frames into a minimal y4m (for vpxenc). |
| 3 | |
| 4 | ffmpeg ... -f rawvideo - | raw_to_y4m.py W H FPS out.y4m DEPTH |
| 5 | |
| 6 | DEPTH (8, 10 or 12) is REQUIRED and is the number of BYTES per sample in the |
| 7 | raw stream on stdin, not the stream's bit depth: ffmpeg's rawvideo muxer |
| 8 | never packs to the bit depth, it uses 1 byte for `yuv420p` and 2 bytes for |
| 9 | `yuv420p10le` / `yuv420p12le`. This script has no parser and no way to learn |
| 10 | it, so the depth is an ASSERTED argument: it is checked against the stdin |
| 11 | length, and a mismatch is a hard error naming the depth, the byte count it |
| 12 | implied, and the misframed y4m it would have produced. The old version |
| 13 | computed `w*h*3//2` unconditionally, so a 10-bit stream (2 bytes per sample) |
| 14 | was cut into frames at half length, the chroma planes of frame N+1 were read |
| 15 | as the tail of frame N, and the last partial frame was dropped silently -- |
| 16 | a y4m that vpxenc accepts and encodes, with no error anywhere. |
| 17 | |
| 18 | The y4m header's `C` tag follows the same argument, so the wrapped stream |
| 19 | carries the depth it actually has. |
| 20 | |
| 21 | LIMIT, stated because it cannot be fixed here: raw planar video carries NO |
| 22 | depth of its own, so the length check below can only catch a stream whose |
| 23 | byte count is not a whole number of frames at the claimed depth. A 10-bit |
| 24 | stream of N frames is exactly 2N 8-bit frames, and no length test can tell |
| 25 | those apart -- that case is caught only by the caller asserting the right |
| 26 | DEPTH, which is why DEPTH is required and not defaulted. |
| 27 | """ |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | , , , , = |
| 38 | |
| 39 | = |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | = 1 |
| 48 | = * * 3 // 2 * |
| 49 | = |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | = |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 |