mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-28 09:09:39 +01:00
#805: Docs: specify packet framing, offsets, flush and error replies
This commit is contained in:
1 parent
e495469969
commit
a2e62b438a
1 file changed
+21
-9
@@ -68,22 +68,32 @@ encode.open → encode.opened → (encode.frame → encode.packets)… → encod
|
||||
|
||||
| Request | Reply | |
|
||||
|---|---|---|
|
||||
| `{"op":"encode.open","job":1,"device":"nvenc:0","codec":"h264","width":1920,"height":1080,"rate":[30,1],"bitrate_kbps":15000,"profile":"high","keyint":60,"colour":{"primaries":1,"transfer":1,"matrix":1,"range":"limited"},"slots":[{"in":{"offset":0,"len":3110400},"out":{"offset":3110400,"len":1048576}},…],"flush_out":{"offset":…,"len":…}}` | `{"op":"encode.opened","job":1,"codec_config":"<base64 avcC>","delay":2}` | `job` is chosen by EffectCraft and is never reused. `slots` is the memory the helper may use, decided by EffectCraft. `codec_config` is the `avcC` (H.264) or `hvcC` (HEVC) record for the MP4 sample entry. `delay` is the number of frames the encoder holds back (B-frames). |
|
||||
| `{"op":"encode.open","job":1,"device":"nvenc:0","codec":"h264","width":1920,"height":1080,"rate":[30,1],"bitrate_kbps":15000,"profile":"high","keyint":60,"colour":{"primaries":1,"transfer":1,"matrix":1,"range":"limited"},"slots":[{"in":{"offset":0,"len":3110400},"out":{"offset":3110400,"len":1048576}},…]}` | `{"op":"encode.opened","job":1,"codec_config":"<base64 avcC>","delay":2}` | `job` is chosen by EffectCraft and is never reused. `slots` is the memory the helper may use, decided by EffectCraft. `codec_config` is the `avcC` (H.264) or `hvcC` (HEVC) record for the MP4 sample entry. `delay` is the number of frames the encoder holds back (B-frames). |
|
||||
| `{"op":"encode.frame","job":1,"frame":0,"slot":0}` | `{"op":"encode.packets","job":1,"frame":0,"packets":[{"offset":0,"len":41230,"pts":0,"dts":-2,"key":true}]}` | The picture is in `slots[0].in`. The reply means the slot may be reused and says where the packets are, inside `slots[0].out`. It may hold no packets (the encoder is still holding frames) or several. |
|
||||
| `{"op":"encode.flush","job":1}` | `{"op":"encode.packets","job":1,"frame":null,"packets":[…]}` then `{"op":"encode.flushed","job":1}` | The rest of the stream, inside `flush_out`. |
|
||||
| `{"op":"encode.flush","job":1,"out":{"offset":…,"len":…}}` | `{"op":"encode.packets","job":1,"frame":null,"packets":[…]}` then `{"op":"encode.flushed","job":1}` | The rest of the stream, inside `out`. EffectCraft sizes `out` for the frames the encoder still holds: at least `(delay + 1)` times the length of a slot's `out` region. A packet that still does not fit is `packet_too_large`. |
|
||||
| `{"op":"encode.close","job":1}` | none | Free everything for the job. |
|
||||
| `{"op":"cancel","job":1}` | `{"op":"cancelled","job":1}` | Stop now. EffectCraft ignores any other reply for the job after it sends `cancel`. |
|
||||
|
||||
- **Packets are MP4 samples.** Each is a sequence of length-prefixed NAL units, every length a
|
||||
4-byte big-endian number, which is what `codec_config` declares (`lengthSizeMinusOne` 3). A
|
||||
helper whose API produces Annex B converts it. EffectCraft writes the bytes into the MP4 as
|
||||
they are.
|
||||
- **Packet offsets** are counted from the start of the region the reply uses (`slots[slot].out`,
|
||||
or the `out` region of `encode.flush`). In the example the packet starts at file offset
|
||||
3110400 + 0. EffectCraft adds the region's offset and checks that `offset + len` is within the
|
||||
region's length.
|
||||
- **Timestamps** are in units of 1 / `rate[0]` seconds, so frame `i` has `pts = i × rate[1]`.
|
||||
`dts` may be earlier than `pts`.
|
||||
- **Who owns what.** EffectCraft decides every offset. The helper reads only the slot it is told
|
||||
to and writes only that slot's `out` region (or `flush_out`). EffectCraft checks every offset and
|
||||
length it gets back with checked arithmetic against the regions it gave out.
|
||||
to and writes only that slot's `out` region (or the `out` region of `encode.flush`). EffectCraft
|
||||
checks every offset and length it gets back with checked arithmetic against the regions it gave
|
||||
out.
|
||||
- **Backpressure.** At most 8 frames, and at most 256 MiB, are queued plus in flight together. When
|
||||
the budget is used up EffectCraft waits for a reply before sending the next frame, so a slow GPU
|
||||
slows the export and does not use more memory.
|
||||
- **Replies are in frame order.** A reply with an unknown `job` or `frame`, outside the regions, or
|
||||
larger than its `out` region (`packet_too_large`) is a protocol break.
|
||||
- **Replies are in frame order,** `error` replies included. A reply with an unknown `job` or
|
||||
`frame`, outside the regions, or larger than its `out` region (`packet_too_large`) is a protocol
|
||||
break.
|
||||
- **Control lines** are at most 1 MiB. Pictures and packets never go through the pipe.
|
||||
|
||||
## Timeouts and errors
|
||||
@@ -93,9 +103,11 @@ encode.open → encode.opened → (encode.frame → encode.packets)… → encod
|
||||
`EFFECTCRAFT_HELPER_VIDEO_TIMEOUT`, as `EFFECTCRAFT_HELPER_TIMEOUT` is for effects), EffectCraft
|
||||
stops the helper. A GPU that hangs without exiting ends the helper instead
|
||||
of making the export look busy. `encode.open` and `encode.flush` use the load timeout (600 s).
|
||||
- **`{"op":"error","job":1,"code":"…","message":"…"}`** is for one request; the helper carries on.
|
||||
Codes: `unsupported` (the settings are declined), `device_lost`, `out_of_memory`,
|
||||
`packet_too_large`, `encoder`.
|
||||
- **`{"op":"error","job":1,"frame":3,"code":"…","message":"…"}`** answers one request. `frame` is
|
||||
there when it answers an `encode.frame` (it ends that frame's timeout) and absent for
|
||||
`encode.open` and `encode.flush`. The helper process carries on, but the job is over:
|
||||
EffectCraft sends `encode.close`. Codes: `unsupported` (the settings are declined),
|
||||
`device_lost`, `out_of_memory`, `packet_too_large`, `encoder`.
|
||||
- **EffectCraft stops the helper** when it exits, closes stdout, sends a line that does not parse
|
||||
or does not fit, breaks the rules above, or misses a timeout. After 3 stops it is turned off and
|
||||
listed in `helper_blocklist.txt` until the user retries in Settings, as for effect helpers.
|
||||
|
||||
Reference in new issue
Block a user