Stream fixes (#22238)
* fix issues with out of order packets, and empty first packet on some IP camera models * do not skip the first packetpull/20830/head^2
parent
77635d40e2
commit
07dc23a0e3
|
@ -63,21 +63,29 @@ def stream_worker(hass, stream, quit_event):
|
||||||
first_packet = True
|
first_packet = True
|
||||||
sequence = 1
|
sequence = 1
|
||||||
audio_packets = {}
|
audio_packets = {}
|
||||||
|
last_dts = None
|
||||||
|
|
||||||
while not quit_event.is_set():
|
while not quit_event.is_set():
|
||||||
try:
|
try:
|
||||||
packet = next(container.demux(video_stream))
|
packet = next(container.demux(video_stream))
|
||||||
if packet.dts is None:
|
if packet.dts is None:
|
||||||
|
if first_packet:
|
||||||
|
continue
|
||||||
# If we get a "flushing" packet, the stream is done
|
# If we get a "flushing" packet, the stream is done
|
||||||
raise StopIteration
|
raise StopIteration("No dts in packet")
|
||||||
except (av.AVError, StopIteration) as ex:
|
except (av.AVError, StopIteration) as ex:
|
||||||
# End of stream, clear listeners and stop thread
|
# End of stream, clear listeners and stop thread
|
||||||
for fmt, _ in outputs.items():
|
for fmt, _ in outputs.items():
|
||||||
hass.loop.call_soon_threadsafe(
|
hass.loop.call_soon_threadsafe(
|
||||||
stream.outputs[fmt].put, None)
|
stream.outputs[fmt].put, None)
|
||||||
_LOGGER.error("Error demuxing stream: %s", ex)
|
_LOGGER.error("Error demuxing stream: %s", str(ex))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# Skip non monotonically increasing dts in feed
|
||||||
|
if not first_packet and last_dts >= packet.dts:
|
||||||
|
continue
|
||||||
|
last_dts = packet.dts
|
||||||
|
|
||||||
# Reset segment on every keyframe
|
# Reset segment on every keyframe
|
||||||
if packet.is_keyframe:
|
if packet.is_keyframe:
|
||||||
# Save segment to outputs
|
# Save segment to outputs
|
||||||
|
|
Loading…
Reference in New Issue