Skip to content

Commit

Permalink
Merge pull request #14 from thrkll/stream-desynchronization-fix
Browse files Browse the repository at this point in the history
Changes to HLS stream mapping
  • Loading branch information
thrkll authored Oct 14, 2024
2 parents 1c84ac7 + b5461e9 commit 7481cd4
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions ruv-dl/ruv-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,37 @@ def progress(seconds_done, eta):
# Defines process
output_title = attributes['title'] + attributes['file_format']
output_link = attributes['filepath'] + output_title
cmd = ['ffmpeg',
'-y',
'-loglevel',
'error',
'-stats',
'-i',
f'{attributes["content_url"]}',
'-c',
'copy',
f'{output_link}']

# Appends setting for correct stream if applicable
if attributes['content_url'].endswith('.m3u8'):
cmd.extend(['-map', f'p:{attributes["resolution"]}'])
is_hls = attributes['content_url'].endswith('.m3u8')

if is_hls:
# HLS content: map the correct video and audio streams based on resolution
# Calculate stream indices based on desired resolution
video_stream_index = 2 * (attributes['resolution'] + 1)
audio_stream_index = video_stream_index + 1
cmd = [
'ffmpeg',
'-y',
'-loglevel', 'error',
'-stats',
'-i', f'{attributes["content_url"]}',
'-map', f'0:{video_stream_index}',
'-map', f'0:{audio_stream_index}',
'-c:v', 'copy',
'-c:a', 'copy',
'-async', '1',
f'{output_link}'
]
else:
# Non-HLS content (radio): no stream mapping needed
cmd = [
'ffmpeg',
'-y',
'-loglevel', 'error',
'-stats',
'-i', f'{attributes["content_url"]}',
'-c', 'copy',
f'{output_link}'
]

process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
Expand Down

0 comments on commit 7481cd4

Please sign in to comment.