Skip to content

Commit

Permalink
Merge pull request #885 from xavierlaffargue/master
Browse files Browse the repository at this point in the history
Add support characteristic for HLS
  • Loading branch information
barbibulle authored Aug 9, 2023
2 parents 19c6839 + 57aacc7 commit 2e2dc01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions Documents/MkDocs/src/developers/dash/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Setting stream properties via input specifiers allows invoking `mp4dash` with ex
`hls_group_match` | `<hls-group-match>` | (only with `--hls`) |
`hls_default` | `YES` or `NO` | (only with `--hls`) |
`hls_autoselect` | `YES` or `NO` | (only with `--hls`) |
`hls_characteristic`| `<hls-characteristic>` (string) | (only with `--hls`) |

### Multi-language

Expand Down
27 changes: 20 additions & 7 deletions Source/Python/utils/mp4-dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,22 @@ def OutputHls(options, set_attributes, audio_sets, video_sets, subtitles_sets, s
default = not default_selected
if default:
default_selected = True
master_playlist_file.write('#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="{}",LANGUAGE="{}",NAME="{}",AUTOSELECT={},DEFAULT={},CHANNELS="{}",URI="{}"\n'.format(

master_playlist_file.write('#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="{}",LANGUAGE="{}",NAME="{}",AUTOSELECT={},DEFAULT={},CHANNELS="{}",URI="{}"'.format(
audio_group_name,
audio_track.language,
media_name,
'YES' if audio_track.hls_autoselect else 'NO',
'YES' if default else 'NO',
audio_track.channels,
media_playlist_path))

hls_characteristic = audio_track.hls_characteristic
if hls_characteristic != None:
master_playlist_file.write(',CHARACTERISTIC="{}"'.format(hls_characteristic))

master_playlist_file.write("\n")

OutputHlsTrack(options, audio_track, all_audio_tracks + all_video_tracks, media_subdir, media_playlist_name, media_file_name)

# Add an audio stream entry for audio-only presentations or if the track specifiers include a '-' entry
Expand Down Expand Up @@ -987,7 +995,7 @@ def OutputHls(options, set_attributes, audio_sets, video_sets, subtitles_sets, s
if '*' not in video_track.hls_group_match and audio_group_name not in video_track.hls_group_match:
continue
audio_codecs = ','.join(audio_groups[audio_group_name]['codecs'])
master_playlist_file.write('#EXT-X-STREAM-INF:{}AUDIO="{}",AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},FRAME-RATE={:.3f}\n'.format(
master_playlist_file.write('#EXT-X-STREAM-INF:{}AUDIO="{}",AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},FRAME-RATE={:.3f}'.format(
subtitles_group,
audio_group_name,
video_track.average_segment_bitrate + audio_groups[audio_group_name]['average_segment_bitrate'],
Expand All @@ -998,11 +1006,12 @@ def OutputHls(options, set_attributes, audio_sets, video_sets, subtitles_sets, s
video_track.height,
video_track.frame_rate))
if supplemental_codec_string != '':
master_playlist_file.write(',SUPPLEMENTAL-CODECS="{}"\n'.format(supplemental_codec_string))
master_playlist_file.write(',SUPPLEMENTAL-CODECS="{}"'.format(supplemental_codec_string))
master_playlist_file.write('\n')
master_playlist_file.write(media_playlist_path+'\n')
else:
# no audio
master_playlist_file.write('#EXT-X-STREAM-INF:{}AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},FRAME-RATE={:.3f}\n'.format(
master_playlist_file.write('#EXT-X-STREAM-INF:{}AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},FRAME-RATE={:.3f}'.format(
subtitles_group,
video_track.average_segment_bitrate,
video_track.max_segment_bitrate,
Expand All @@ -1012,23 +1021,26 @@ def OutputHls(options, set_attributes, audio_sets, video_sets, subtitles_sets, s
video_track.height,
video_track.frame_rate))
if supplemental_codec_string != '':
master_playlist_file.write(',SUPPLEMENTAL-CODECS="{}"\n'.format(supplemental_codec_string))
master_playlist_file.write(',SUPPLEMENTAL-CODECS="{}"'.format(supplemental_codec_string))
master_playlist_file.write('\n')
master_playlist_file.write(media_playlist_path+'\n')

OutputHlsTrack(options, video_track, all_audio_tracks + all_video_tracks, media_subdir, media_playlist_name, media_file_name)
iframe_average_segment_bitrate,iframe_max_bitrate = OutputHlsIframeIndex(options, video_track, all_audio_tracks + all_video_tracks, media_subdir, iframes_playlist_name, media_file_name)

# this will be written later
iframe_playlist_lines.append('#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},URI="{}"\n'.format(
iframe_playlist_lines.append('#EXT-X-I-FRAME-STREAM-INF:AVERAGE-BANDWIDTH={:.0f},BANDWIDTH={:.0f},VIDEO-RANGE={},CODECS="{}",RESOLUTION={:.0f}x{:.0f},URI="{}"'.format(
iframe_average_segment_bitrate,
iframe_max_bitrate,
video_track.video_range,
video_track.codec,
video_track.width,
video_track.height,
iframes_playlist_path))

if supplemental_codec_string != '':
iframe_playlist_lines.append(',SUPPLEMENTAL-CODECS="{}"\n'.format(supplemental_codec_string))
iframe_playlist_lines.append(',SUPPLEMENTAL-CODECS="{}"'.format(supplemental_codec_string))
iframe_playlist_lines.append('\n')

master_playlist_file.write('\n# I-Frame Playlists\n')
master_playlist_file.write(''.join(iframe_playlist_lines))
Expand Down Expand Up @@ -1415,6 +1427,7 @@ def SelectTracks(options, media_sources):
track.hls_autoselect = BooleanFromString(media_source.spec.get('+hls_autoselect', 'YES'))
track.hls_group = media_source.spec.get('+hls_group')
track.hls_group_match = media_source.spec.get('+hls_group_match', '*').split('&')
track.hls_characteristic = media_source.spec.get('+hls_characteristic')

# update label indexes (so that we can use numbers instead of strings for labels)
for track in tracks:
Expand Down

0 comments on commit 2e2dc01

Please sign in to comment.