Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUDIO, VIDEO, SUBTITLES attributes support in StreamInfo object #121

Open
mbakholdina opened this issue Jul 9, 2018 · 2 comments
Open

Comments

@mbakholdina
Copy link

Is it possible to add AUDIO, VIDEO, SUBTITLES attributes support along with CLOSED-CAPTIONS in StreamInfo object when parsing #EXT-X-STREAM-INF tag? It would be more convenient to get an access to this info directly instead of going through all media objects.

@mbakholdina
Copy link
Author

mbakholdina commented Oct 11, 2018

The playlist

#EXTM3U

#EXT-X-VERSION:3

#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID="cc",NAME="English",LANGUAGE="eng",AUTOSELECT=YES,INSTREAM-ID="CC1"
#EXT-X-MEDIA:TYPE=CLOSED-CAPTIONS,GROUP-ID="cc",NAME="German",LANGUAGE="ger",AUTOSELECT=YES,INSTREAM-ID="CC2"

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub",NAME="English",LANGUAGE="eng",AUTOSELECT=YES,URI="http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/subtitle_0_eng/subtitle_0_eng.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="sub",NAME="German",LANGUAGE="ger",AUTOSELECT=YES,URI="http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/subtitle_1_ger/subtitle_1_ger.m3u8"

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud",NAME="English",LANGUAGE="eng",DEFAULT=NO,AUTOSELECT=YES,URI="http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/audio_1_eng/audio_1_eng.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aud",NAME="English",LANGUAGE="eng",DEFAULT=NO,AUTOSELECT=YES,URI="http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/audio_0_eng/audio_0_eng.m3u8"

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=445460,CODECS="avc1.420015,mp4a.40.2",RESOLUTION=320x180,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud"
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_5/video_5.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=766243,CODECS="avc1.4d001f,mp4a.40.2",RESOLUTION=480x270,CLOSED-CAPTIONS="cc",SUBTITLES="sub",AUDIO="aud"
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_4/video_4.m3u8

The code

import m3u8

def foo(path):

    try:
        m3u8_obj = m3u8.load(path)  
    except FileNotFoundError as e:
        print("FileNotFoundError while parsing m3u8 playlist:", e.filename, "({:})".format(e.strerror))
        raise e

    # Current playlist is master and contains variants
    assert(m3u8_obj.is_variant)
    stream_inf_tags = m3u8_obj.playlists
    assert (len(stream_inf_tags) != 0)

    for i, stream in enumerate(stream_inf_tags):
        print ('\nVariant', i)
        print(stream.uri)
        print(stream.stream_info.bandwidth)
        print(stream.stream_info.resolution)
        print(stream.stream_info.codecs)
        # For CLOSED-CAPTIONS attribute in EXT-X-STREAM-INF tag
        print(stream.stream_info.closed_captions) 
       
        # For AUDIO, VIDEO, SUBTITLES attributes in EXT-X-STREAM-INF tag
        for media in stream.media:
            print(media.type)
            print(media.group_id)

    

if __name__ == '__main__':

    path = 'playlist.m3u8'
    foo(path)

Current result

Variant 0
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_5/video_5.m3u8
445460
(320, 180)
avc1.420015,mp4a.40.2
"cc"
AUDIO
aud
AUDIO
aud
SUBTITLES
sub
SUBTITLES
sub

Variant 1
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_4/video_4.m3u8
766243
(480, 270)
avc1.4d001f,mp4a.40.2
"cc"
AUDIO
aud
AUDIO
aud
SUBTITLES
sub
SUBTITLES
sub

Expected result

Variant 0
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_5/video_5.m3u8
445460
(320, 180)
avc1.420015,mp4a.40.2
CLOSED-CAPTIONS
cc
AUDIO
aud
SUBTITLES
sub

Variant 1
http://10.129.128.128:8080/output/test_class_hls/preset_1/dump/video_4/video_4.m3u8
766243
(480, 270)
avc1.4d001f,mp4a.40.2
CLOSED-CAPTIONS
cc
AUDIO
aud
SUBTITLES
sub

Problems:
Problem 1: m3u8_obj.playlists[i].stream_info.closed_captions returns "cc" instead of cc without quotation marks. There is a separate ticket for this.
Problem 2: CLOSED-CAPTIONS attribute and AUDIO, VIDEO, SUBTITLES attributes are parsed at a different levels. CLOSED-CAPTIONS attribute is available via m3u8_obj.playlists[i].stream_info.closed_captions while other attributes via m3u8_obj.playlists[i].media
Problem 3: m3u8_obj.playlists[i].media returns the list of (type, group_id) as many times as declared in EXT-X-MEDIA tags if a rendition group is declared in EXT-X-STREAM-INF tag in one of the attributes: AUDIO, VIDEO, SUBTITLES, or CLOSED-CAPTIONS. As a result, we have twice (AUDIO, aud) and twice (SUBTITLES, sub) instead of listing them only once.

@audetto
Copy link
Contributor

audetto commented Mar 5, 2019

Not sure this is the same question, but I can see to extract all audio information from this playlist

Is this supported?
I only get the Italian audio track at the bottom, but not the English one.

#EXTM3U
#EXT-X-VERSION:4

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Italian",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="ita",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="https://mediapolisvod.rai.it/relinker/relinkerServlet.htm?cont=10177458&output=57&forceUserAgent=get_my_direct_url"

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=NO,AUTOSELECT=NO,LANGUAGE="eng",CHARACTERISTICS="public.accessibility.transcribes-spoken-dialog, public.accessibility.describes-music-and-sound",URI="https://mediapolisvod.rai.it/relinker/relinkerServlet.htm?cont=10177450&output=57&forceUserAgent=get_my_direct_url"

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Italian",LANGUAGE="ita",DEFAULT=YES,AUTOSELECT=YES,URI="https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(255997)/Manifest(audio_ita,format=m3u8-aapl,filter=medium_1200-2400)"

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="English",LANGUAGE="eng",AUTOSELECT=YES,URI="https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(255997)/Manifest(audio_eng,format=m3u8-aapl,filter=medium_1200-2400)"

#EXT-X-STREAM-INF:BANDWIDTH=1532553,RESOLUTION=736x414,CODECS="avc1.4d401f,mp4a.40.2",AUDIO="audio",SUBTITLES="subs"
https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(1227598)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400)

#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=1532553,RESOLUTION=736x414,CODECS="avc1.4d401f",URI="https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(1227598)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400,type=keyframes)"

#EXT-X-STREAM-INF:BANDWIDTH=2158421,RESOLUTION=1024x576,CODECS="avc1.4d401f,mp4a.40.2",AUDIO="audio",SUBTITLES="subs"
https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(1839994)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400)

#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=2158421,RESOLUTION=1024x576,CODECS="avc1.4d401f",URI="https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(1839994)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400,type=keyframes)"

#EXT-X-STREAM-INF:BANDWIDTH=2765361,RESOLUTION=1280x720,CODECS="avc1.4d4028,mp4a.40.2",AUDIO="audio",SUBTITLES="subs"
https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(2433868)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400)

#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=2765361,RESOLUTION=1280x720,CODECS="avc1.4d4028",URI="https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(2433868)/Manifest(video,format=m3u8-aapl,filter=medium_1200-2400,type=keyframes)"

#EXT-X-STREAM-INF:BANDWIDTH=269788,CODECS="mp4a.40.2",AUDIO="audio",SUBTITLES="subs"
https://hlsaz-dc-euwe.akamaized.net/99fa284a-91d3-47d8-ba4b-ad31b8424448/20190304184113_10176232.ism/QualityLevels(255997)/Manifest(audio_ita,format=m3u8-aapl,filter=medium_1200-2400)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants