Skip to content

Commit 4520550

Browse files
committed
Support writing HLS using PyavOutput
There were just a couple of missing things: 1. We need to be able to pass in options such as hls_time etc. 2. Packets must correctly flag when they are keyframes. You can make a PyavOutput write HLS using, for example: options = { "hls_time": "5", "hls_list_size": "8", "hls_flags": "delete_segments+append_list+independent_segments" } output = PyavOutput("/dev/shm/cam_hls/live.m3u8", format='hls', options=options) Signed-off-by: David Plowman <[email protected]>
1 parent 7ddde14 commit 4520550

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

picamera2/outputs/pyavoutput.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class PyavOutput(Output):
1818
back in.
1919
"""
2020

21-
def __init__(self, output_name, format=None, pts=None):
21+
def __init__(self, output_name, format=None, pts=None, options=None):
2222
super().__init__(pts=pts)
2323
self._output_name = output_name
2424
self._format = format
2525
self._streams = {}
2626
self._container = None
27+
self._options = options
2728
# A user can set this to get notifications of failures.
2829
self.error_callback = None
2930

@@ -40,7 +41,7 @@ def _add_stream(self, encoder_stream, codec_name, **kwargs):
4041

4142
def start(self):
4243
"""Start the PyavOutput."""
43-
self._container = av.open(self._output_name, "w", format=self._format)
44+
self._container = av.open(self._output_name, "w", format=self._format, options=self._options)
4445
super().start()
4546

4647
def stop(self):
@@ -64,6 +65,7 @@ def outputframe(self, frame, keyframe=True, timestamp=None, packet=None, audio=F
6465
packet.dts = timestamp
6566
packet.pts = timestamp
6667
packet.time_base = Fraction(1, 1000000)
68+
packet.is_keyframe = keyframe
6769
packet.stream = self._streams["video"]
6870
else:
6971
# We can copy the packet we are given, updating the stream to be our version, and amending
@@ -75,6 +77,7 @@ def outputframe(self, frame, keyframe=True, timestamp=None, packet=None, audio=F
7577
new_packet.dts = timestamp
7678
new_packet.pts = timestamp
7779
new_packet.time_base = Fraction(1, 1000000)
80+
new_packet.is_keyframe = keyframe
7881
packet = new_packet
7982

8083
try:

0 commit comments

Comments
 (0)