Skip to content

Commit eb1767c

Browse files
authored
Drop audio at encoder until video is received. (#412)
1 parent 60bb58e commit eb1767c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

runner/app/live/trickle/encoder.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def custom_io_open(url: str, flags: int, options: dict):
6565
# Now read packets from the input, decode, then re-encode, and mux.
6666
start = datetime.datetime.now()
6767
last_kf = None
68+
video_received = False
6869
while True:
6970
avframe = input_queue()
7071
if avframe is None:
@@ -84,12 +85,19 @@ def custom_io_open(url: str, flags: int, options: dict):
8485
encoded_packets = output_video_stream.encode(frame)
8586
for ep in encoded_packets:
8687
output_container.mux(ep)
88+
video_received = True
8789
continue
8890

8991
if isinstance(avframe, AudioOutput):
9092
if not output_audio_stream:
9193
# received audio but no audio output, so drop
9294
continue
95+
if output_video_stream and not video_received:
96+
# Wait until we receive video to start sending audio
97+
# because video could be extremely delayed and we don't
98+
# want to send out audio-only segments since that confuses
99+
# downstream tools
100+
continue
93101
for af in avframe.frames:
94102
frame = av.audio.frame.AudioFrame.from_ndarray(af.samples, format=af.format, layout=af.layout)
95103
frame.sample_rate = af.rate

0 commit comments

Comments
 (0)