Repository navigation
Description
Describe the bug
nvjpegdec stops its stream on a JPEG that fails to decode, whatever max-errors is set to. With max-errors=-1 ("never fail") the element should drop the bad picture and decode the next one. The stock jpegdec does that on the same file.
Steps/Code to reproduce bug
Save the script below as repro_nvjpegdec_max_errors.py and run it in the stock image. The pipeline is appsrc ! jpegparse ! <decoder> max-errors=<N> ! fakesink. The script makes its own JPEGs and pushes a good one, one with a bad Huffman table, and the good one again.
docker run --rm --gpus all -v "$PWD":/repro --entrypoint bash ghcr.io/nvidia/deepstream:9.2-triton-multiarch -c \
"apt-get update -qq && apt-get install -y -qq python3-gi >/dev/null && \
python3 /repro/repro_nvjpegdec_max_errors.py nvjpegdec -1"3 runs per row, all the same:
| decoder | max-errors | frames at the sink (2 expected) | bus |
|---|---|---|---|
| nvjpegdec | -1, 0 or 1 | 1 | ERROR from appsrc: "streaming stopped, reason error (-5)" |
| jpegdec | -1, 0 or 1 | 2 | clean |
Both decoders log _gst_video_decoder_error: Decode error #9: Bogus Huffman table definition. Only with nvjpegdec the source then stops (gst_base_src_loop:<src> pausing after gst_pad_push() = error). The decoder posts no ERROR of its own, so the base class did not fail; the element seems to return GST_FLOW_ERROR after GST_VIDEO_DECODER_ERROR whatever the macro decided.
repro_nvjpegdec_max_errors.py
r"""A JPEG with a bad Huffman table stops a decoder's stream although max-errors=-1 ("never fail") is set.
The pipeline is `appsrc ! jpegparse ! <decoder> max-errors=<N> ! fakesink`. The script makes a good JPEG in process
(videotestsrc ! jpegenc) and a bad one from it: the 16 code counts of the first DHT segment claim more than 256 codes.
It pushes good, bad, good (one buffer each, TIME format, with timestamps), then EOS. It prints the flow return of each
push, the frames that reached fakesink after each step, and every bus WARNING and ERROR.
repro_nvjpegdec_max_errors.py nvjpegdec -1 the DeepStream GPU decoder
repro_nvjpegdec_max_errors.py jpegdec -1 control: the stock GStreamer CPU decoder
Run in the stock image. It has the GStreamer typelibs but no python3-gi, so that comes first:
docker run --rm --gpus all -v "$PWD":/repro --entrypoint bash ghcr.io/nvidia/deepstream:9.2-triton-multiarch -c \
"apt-get update -qq && apt-get install -y -qq python3-gi >/dev/null && \
python3 /repro/repro_nvjpegdec_max_errors.py nvjpegdec -1"
Expected with -1: "frames at sink: 2", no bus ERROR; the bad JPEG is dropped and the second good one is decoded.
Actual with nvjpegdec, at -1, 0 and 1 alike: "frames at sink: 1 of 2". The log has the base class line
"Decode error #9: Bogus Huffman table definition", then "BUS ERROR from src: Internal data stream error ...
streaming stopped, reason error (-5)". No ERROR comes from the decoder itself, and the second good JPEG is lost.
Actual with jpegdec, at -1, 0 and 1: "frames at sink: 2 of 2", no bus ERROR or WARNING, same "Decode error #9" line.
"""
import sys
import time
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst # noqa: E402
FRAME_NS = 40_000_000
STEP_WAIT_SEC = 3.0
def good_jpeg() -> bytes:
pipe = Gst.parse_launch(
"videotestsrc num-buffers=1 ! video/x-raw,width=640,height=360 ! jpegenc ! appsink name=out sync=false",
)
pipe.set_state(Gst.State.PLAYING)
sample = pipe.get_by_name("out").emit("pull-sample")
data = sample.get_buffer().extract_dup(0, sample.get_buffer().get_size())
pipe.set_state(Gst.State.NULL)
return data
def bad_huffman(jpeg: bytes) -> bytes:
"""The first DHT segment's code counts become 255, 255, 0, ... (510 codes > 256)."""
dht = jpeg.index(b"\xff\xc4")
bad = bytearray(jpeg)
for i in range(16):
bad[dht + 5 + i] = 0xFF if i < 2 else 0
return bytes(bad)
def drain_bus(bus: Gst.Bus, seconds: float, sink_count: list[int], target: int) -> bool:
"""Prints bus warnings and errors until `target` frames reached the sink or the time is up. True on EOS/ERROR."""
deadline = time.monotonic() + seconds
kinds = Gst.MessageType.ERROR | Gst.MessageType.WARNING | Gst.MessageType.EOS
while time.monotonic() < deadline and sink_count[0] < target:
msg = bus.timed_pop_filtered(50 * Gst.MSECOND, kinds)
if msg is None:
continue
if msg.type == Gst.MessageType.EOS:
print("BUS EOS", flush=True)
return True
err, dbg = msg.parse_error() if msg.type == Gst.MessageType.ERROR else msg.parse_warning()
print(f"BUS {msg.type.first_value_nick.upper()} from {msg.src.get_name()}: {err.message} | {dbg}", flush=True)
if msg.type == Gst.MessageType.ERROR:
return True
return False
def main(decoder: str, max_errors: int) -> None:
Gst.init(None)
good = good_jpeg()
pipe = Gst.parse_launch(
f"appsrc name=src format=time caps=image/jpeg ! jpegparse ! {decoder} name=dec max-errors={max_errors} "
"! fakesink name=sink sync=false",
)
sink_count = [0]
def on_buffer(_pad: Gst.Pad, _info: Gst.PadProbeInfo) -> Gst.PadProbeReturn:
sink_count[0] += 1
return Gst.PadProbeReturn.OK
pipe.get_by_name("sink").get_static_pad("sink").add_probe(Gst.PadProbeType.BUFFER, on_buffer)
src, bus = pipe.get_by_name("src"), pipe.get_bus()
print(f"{decoder} max-errors={pipe.get_by_name('dec').get_property('max-errors')}", flush=True)
pipe.set_state(Gst.State.PLAYING)
expected = 0
for i, (name, data) in enumerate((("good", good), ("bad-huffman", bad_huffman(good)), ("good", good))):
buf = Gst.Buffer.new_wrapped(data)
buf.pts, buf.duration = i * FRAME_NS, FRAME_NS
flow = src.emit("push-buffer", buf)
expected += name == "good"
# After the bad JPEG wait the full time, so its bus messages print in its own step.
drain_bus(bus, STEP_WAIT_SEC, sink_count, expected if name == "good" else expected + 1)
print(f"STEP push {name}: flow={flow.value_nick} frames at sink={sink_count[0]}", flush=True)
print(f"STEP end-of-stream: flow={src.emit('end-of-stream').value_nick}", flush=True)
drain_bus(bus, STEP_WAIT_SEC, sink_count, 99)
pipe.set_state(Gst.State.NULL)
print(f"RESULT {decoder} max-errors={max_errors}: frames at sink: {sink_count[0]} of 2", flush=True)
if __name__ == "__main__":
if len(sys.argv) != 3 or sys.argv[1] not in ("nvjpegdec", "jpegdec"):
sys.exit("usage: repro_nvjpegdec_max_errors.py nvjpegdec|jpegdec <max-errors>")
main(sys.argv[1], int(sys.argv[2]))Expected behavior
With max-errors=-1, nvjpegdec drops the bad JPEG and decodes the next one, as jpegdec does.
Environment details
- Docker on bare metal (Ubuntu 26.04.1 LTS host, RTX A4000 Laptop GPU, driver 615.71.09)
ghcr.io/nvidia/deepstream:9.2-triton-multiarch(digestsha256:94a49674eb475f0416ce49742430cfbd644258b4e6512b09c76ddd90164c6dc7)
Additional context
A long-lived pipeline that decodes many independent JPEGs through one appsrc loses the whole stream on one bad file. Our workaround is to decode every file on the CPU before the push.
Activity
nvqiezi commentedon Nov 23, 2026
Thanks for the reporting! This issue can be reproduced on my side. Please refer to this topic. Since nvjpegdec is opensource in public_sources.tbz2, you can fix the issue by this patch.
workaround_nvjpegdec.diff.txt