Rewrite media URI

You can activate this plugin with the string manifest_edit.plugins.m3u8_main.rewrite_media_uri.

This plugin allows to modify the media URI string as appearing in EXT-X-MEDIA, EXT-X-STREAM and EXT-X-I-FRAME-STREAM-INF tags of an m3u8 Main Manifest.

The main use case for this plugin is to generate media URIs that activate media playlist use cases.

In fact, when activating a main m3u8 playlist use cases using a python_pipeline_config=m3u8_main/use_case query parameter, all media URIs will have by default the same query parameter string. If you don't need to activate media playlist use cases you can just use suppress_query_parameters to remove them (See Rewrite media URI). But if you need a way to provide players with media URIs for Manifest Edit m3u8_media use cases, this is the plugin that can do so.

Plugin configuration

The "rewrite_media_uri" plugin allows you to apply regular expression-based substitutions.

This is an example of a pipeline configuration including the rewrite_media_uri plugin.

m3u8_main:
- manifest_edit.plugins.m3u8_main.rewrite_media_uri:
  # Can be used to change URIs in EXT-X-MEDIA, EXT-X-STREAM and
  # EXT-X-I-FRAME-STREAM-INF
  # Generic expression to replace python_pipeline_config query parameter value
  # in main playlists URIs and activate the desired media playlist use case.
  - search: 'python_pipeline_config=([^&]*)'
    replace: 'python_pipeline_config=m3u8_media/default'

The above example will operate on all the strings for URI= attributes of EXT-X-MEDIA and EXT-X-I-FRAME-STREAM-INF or uri strings in the playlist's #EXT-X-STREAM-INF sections.

If a media string matches the regular expression present in search, then the substring matching it will be replaced with the expression in replace.

An example of a substitution performed by the above configuration is the following:

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-aacl-64",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2",URI="tears-of-steel-multi-lang-audio_eng=64008.m3u8?python_pipeline_config=m3u8_main/default"
#EXT-X-STREAM-INF:BANDWIDTH=494000,CODECS="mp4a.40.2,avc1.42C00D",RESOLUTION=224x100,FRAME-RATE=24,AUDIO="audio-aacl-64",SUBTITLES="textstream",CLOSED-CAPTIONS=NONE
tears-of-steel-multiple-subtitles-audio_eng=64008-video_eng=401000.m3u8?python_pipeline_config=m3u8_main/default
# keyframes
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=54000,CODECS="avc1.42C00D",RESOLUTION=224x100,URI="keyframes/tears-of-steel-multiple-subtitles-video_eng=401000.m3u8?python_pipeline_config=m3u8_main/default"

is rewritten as

#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-aacl-64",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,CHANNELS="2",URI="tears-of-steel-multi-lang-audio_eng=64008.m3u8?python_pipeline_config=m3u8_media/default"
#EXT-X-STREAM-INF:BANDWIDTH=494000,CODECS="mp4a.40.2,avc1.42C00D",RESOLUTION=224x100,FRAME-RATE=24,AUDIO="audio-aacl-64",SUBTITLES="textstream",CLOSED-CAPTIONS=NONE
tears-of-steel-multiple-subtitles-audio_eng=64008-video_eng=401000.m3u8?python_pipeline_config=m3u8_media/default
# keyframes
#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=54000,CODECS="avc1.42C00D",RESOLUTION=224x100,URI="keyframes/tears-of-steel-multiple-subtitles-video_eng=401000.m3u8?python_pipeline_config=m3u8_media/default"

Warning

Make sure you test the outcome of the substitutions in a test environment. It is very possible to break playback of a stream if the resulting media URIs are invalid.

Examples

Adding a python_pipeline_config query parameter when none is present (e.g. suppress_query_parameters is being used for the main playlist URI):

m3u8_main:
- manifest_edit.plugins.m3u8_main.rewrite_media_uri:
  # Can be used to change URIs in EXT-X-MEDIA, EXT-X-STREAM and
  # EXT-X-I-FRAME-STREAM-INF
  # This expression is suitable when suppress_query_parameter=true is used in
  # the main playlist URL.
  - search: '.m3u8$'
    replace: '.m3u8?python_pipeline_config=m3u8_media/default'