Python Forum
MPEG DASH Package implementation similar to M3U8 package
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MPEG DASH Package implementation similar to M3U8 package
#1
I'm currently using the following package for working with .m3u8 (HLS) playlist files

m3u8 Package

I'm attempting to find a similar implementation for .mpd(MPEG-DASH) manifest files but all I found were simple parsers.Here are the 2 functions which have been implemented for .m3u8 playlist files. My purpose is to do the same for .mpd manifest files as well.

import logging
from datetime import timedelta
from os.path import basename

from furl import furl
from m3u8 import M3U8, Media, Playlist, Segment
from m3u8 import load as load_m3u8

def make_master_manifest(request, stream):
    if stream.info:
        bandwidth = int(stream.info["bw_out"])
        width = stream.info["meta"]["video"]["width"]
        height = stream.info["meta"]["video"]["height"]
        stream_info = {
            "bandwidth": bandwidth,
            "resolution": f"{width}x{height}",
            "codecs": "avc1.640028,mp4a.40.2",
        }
    else:
        stream_info = {"bandwidth": 1000}

    p = Playlist(basename(stream.index_manifest_url), stream_info, None, None)
    m = M3U8()
    m.add_playlist(p)

    for feed in stream.feeds.all():
        media = Media(
            type="SUBTITLES",
            group_id="feeds",
            name=f"feed-{feed.uuid}",
            language="en",
            default="YES",
            autoselect="YES",
            uri=furl(feed.manifest_url).set({"stream": stream.uuid}).url,
        )
        p.media.append(media)
        m.add_media(media)

    return m.dumps()

def make_feed_manifest(request, stream, feed):
    url = request.build_absolute_uri(stream.index_manifest_url)
    p = load_m3u8(url)
    m = M3U8()
    m.version = p.version
    m.target_duration = p.target_duration
    m.media_sequence = p.media_sequence
    for s in p.segments:
        if not m.program_date_time:
            m.program_date_time = s.current_program_date_time

        vtt_url = furl(basename(feed.webvtt_url)).set({"stream": stream.uuid})
        if s.current_program_date_time:
            vtt_url.args.update(
                {
                    "start": s.current_program_date_time.isoformat(),
                    "end": (
                        s.current_program_date_time + timedelta(seconds=s.duration)
                    ).isoformat(),
                    "epoch": stream.started_at.isoformat(),
                }
            )
        v = Segment(
            base_uri=vtt_url.url,
            uri=vtt_url.url,
            duration=s.duration,
            discontinuity=s.discontinuity,
            program_date_time=s.current_program_date_time,
        )
        m.add_segment(v)

    return m.dumps()
Spent quite a few hours attempting to find the same. Any guidance in the right direction would be great.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NEED HELP WITH REQUEST PACKAGE Ishan69 1 397 Mar-05-2025, 06:55 PM
Last Post: noisefloor
  qpython package error Creepy 5 2,992 Apr-19-2024, 10:35 AM
Last Post: masonsbore
  problem install somewhere package akbarza 1 1,534 Dec-27-2023, 01:25 PM
Last Post: Gribouillis
  How to run utilities from a Python package? LugosisGhost 1 1,198 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Not able to install package caldwellpy and requirement txt file Samta282006 1 1,653 Dec-07-2023, 11:59 PM
Last Post: Larz60+
  imdby package problem lunacy90 8 3,011 Sep-04-2023, 07:13 PM
Last Post: deanhystad
  when package built, requirements not installed sabuzaki 1 1,245 Apr-07-2023, 09:01 AM
Last Post: sabuzaki
  Confused over Conda Package manager vs PIP JanOlvegg 3 4,737 Mar-09-2023, 02:09 PM
Last Post: JanOlvegg
  Python package not seen in VSCode fmccabe80 6 6,799 Mar-06-2023, 10:01 PM
Last Post: fmccabe80
  package script cant find sibling script when executed from outside Bock 3 1,796 Mar-03-2023, 04:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020