mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-03 06:25:10 +00:00
fix(tracks): mark AC-4 Atmos from the HLS ATMOS channels identifier and carry atmos without JOC through signature, export and remote
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
"""Atmos on an AC-4 track comes only from a manifest signal that a Dolby or ETSI document defines as Atmos."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.export_name import audio_token
|
||||
from unshackle.core.manifests.dash import DASH
|
||||
from unshackle.core.manifests.hls import HLS
|
||||
from unshackle.core.tracks import Audio, Tracks
|
||||
from unshackle.core.wire import deserialize_audio, serialize_audio_track, track_from_dict, track_to_dict
|
||||
|
||||
VIRTUALIZED = '<SupplementalProperty schemeIdUri="tag:dolby.com,2016:dash:virtualized_content:2016" value="1"/>'
|
||||
|
||||
|
||||
def hls_audio(channels: str, codecs: str = "ac-4") -> Audio:
|
||||
text = (
|
||||
"#EXTM3U\n"
|
||||
f'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="a",NAME="English",LANGUAGE="en",CHANNELS="{channels}",URI="ac4.m3u8"\n'
|
||||
f'#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1920x1080,CODECS="avc1.640028,{codecs}",AUDIO="a"\n'
|
||||
"video.m3u8\n"
|
||||
)
|
||||
(audio,) = HLS.from_text(text, "https://cdn.example/master.m3u8").to_tracks(language="en").audio
|
||||
return audio
|
||||
|
||||
|
||||
def dash_audio(codecs: str, channels: str, extra: str = "") -> Audio:
|
||||
text = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT3M">
|
||||
<Period id="0">
|
||||
<AdaptationSet id="1" contentType="audio" lang="en">
|
||||
<Representation id="1" codecs="{codecs}" audioSamplingRate="48000" bandwidth="259908" mimeType="audio/mp4">
|
||||
<AudioChannelConfiguration schemeIdUri="urn:mpeg:mpegB:cicp:ChannelConfiguration" value="{channels}"/>
|
||||
{extra}
|
||||
<BaseURL>audio.mp4</BaseURL>
|
||||
<SegmentBase indexRange="0-100"/>
|
||||
</Representation>
|
||||
</AdaptationSet>
|
||||
</Period>
|
||||
</MPD>"""
|
||||
(audio,) = DASH.from_text(text, "https://cdn.example/manifest.mpd").to_tracks(language="en").audio
|
||||
return audio
|
||||
|
||||
|
||||
def test_an_hls_ac4_rendition_with_the_atmos_identifier_is_atmos_without_a_joc_count() -> None:
|
||||
audio = hls_audio("2/IMSA,ATMOS")
|
||||
|
||||
assert audio.codec == Audio.Codec.AC4
|
||||
assert audio.atmos
|
||||
assert audio.channels == 2.0
|
||||
assert not audio.joc
|
||||
assert "2.0, Atmos |" in str(audio)
|
||||
assert "JOC" not in str(audio)
|
||||
|
||||
|
||||
def test_an_hls_immersive_stereo_rendition_without_the_atmos_identifier_is_not_atmos() -> None:
|
||||
audio = hls_audio("2/IMSA")
|
||||
|
||||
assert not audio.atmos
|
||||
assert audio.channels == 2.0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("channels", ["2", "6"])
|
||||
def test_a_plain_hls_ac4_rendition_is_not_atmos(channels: str) -> None:
|
||||
assert not hls_audio(channels, codecs="ac-4.02.01.00").atmos
|
||||
|
||||
|
||||
def test_an_hls_joc_rendition_keeps_its_joc_count() -> None:
|
||||
audio = hls_audio("16/JOC", codecs="ec-3")
|
||||
|
||||
assert audio.atmos
|
||||
assert audio.joc == 16
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("codecs", "channels", "extra"),
|
||||
[
|
||||
("ac-4.02.01.00", "6", ""),
|
||||
("ac-4.02.01.00", "2", ""),
|
||||
("ac-4.02.02.00", "2", VIRTUALIZED),
|
||||
],
|
||||
ids=["plain-5.1", "plain-2.0", "immersive-stereo"],
|
||||
)
|
||||
def test_a_dash_ac4_representation_without_a_cited_atmos_signal_is_not_atmos(
|
||||
codecs: str, channels: str, extra: str
|
||||
) -> None:
|
||||
"""Neither presentation_version 2 nor virtualized_content proves Atmos: an IMS presentation may carry any content."""
|
||||
audio = dash_audio(codecs, channels, extra)
|
||||
|
||||
assert audio.codec == Audio.Codec.AC4
|
||||
assert not audio.atmos
|
||||
|
||||
|
||||
def test_the_export_name_reads_atmos_without_a_joc_count() -> None:
|
||||
assert audio_token(hls_audio("2/IMSA,ATMOS")).endswith("2.0atmos")
|
||||
|
||||
|
||||
def test_atmos_without_a_joc_count_is_part_of_the_track_signature() -> None:
|
||||
assert Tracks.signature(hls_audio("2/IMSA,ATMOS")) != Tracks.signature(hls_audio("2/IMSA"))
|
||||
|
||||
|
||||
def test_atmos_without_a_joc_count_survives_the_export_track_dict() -> None:
|
||||
audio = track_from_dict(track_to_dict(hls_audio("2/IMSA,ATMOS")))
|
||||
|
||||
assert audio.atmos
|
||||
assert not audio.joc
|
||||
|
||||
|
||||
def test_hls_atmos_without_a_joc_count_survives_the_remote_round_trip() -> None:
|
||||
audio = deserialize_audio(serialize_audio_track(hls_audio("2/IMSA,ATMOS")))
|
||||
|
||||
assert audio.atmos
|
||||
assert not audio.joc
|
||||
@@ -504,6 +504,20 @@ def test_a_3d_video_stays_3d_through_export_and_import(tmp_path: Path) -> None:
|
||||
assert svc.get_tracks(movie).videos[0].stereo
|
||||
|
||||
|
||||
def test_atmos_without_a_joc_count_stays_atmos_through_export_and_import(tmp_path: Path) -> None:
|
||||
writer = make_writer(tmp_path)
|
||||
title = make_title()
|
||||
title.tracks.audio[0].joc = 0
|
||||
title.tracks.audio[0].extra = {"atmos": True}
|
||||
for track in [*title.tracks.videos, *title.tracks.audio]:
|
||||
writer.record(title, track)
|
||||
export = written(writer)
|
||||
assert [row.get("atmos") for row in entry(export)["tracks"] if row["type"] == "audio"] == [True]
|
||||
svc = ImportService(import_ctx(), "EXAMPLE", "movie-1", str(export))
|
||||
movie = next(iter(svc.get_titles()))
|
||||
assert svc.get_tracks(movie).audio[0].atmos
|
||||
|
||||
|
||||
class ProviderService:
|
||||
ANIME = True
|
||||
METADATA_PROVIDER = "tmdb"
|
||||
|
||||
@@ -567,6 +567,7 @@ EXPORT_AUDIO = {
|
||||
"bitrate": 640000,
|
||||
"channels": 5.1,
|
||||
"joc": 16,
|
||||
"atmos": True,
|
||||
"descriptive": True,
|
||||
"bit_depth": 24,
|
||||
"sample_rate": 48000,
|
||||
|
||||
Reference in New Issue
Block a user