Fix published paths for transcoded media
This commit is contained in:
parent
3f33994cdc
commit
89d462e280
9 changed files with 956 additions and 114 deletions
|
|
@ -33,25 +33,21 @@ class VideoSettings(MediaSettings):
|
|||
ffmpeg_video_params: Dict[str, str]
|
||||
|
||||
|
||||
class AudioMeta(TypedDict):
|
||||
format_name: str
|
||||
format_long_name: str
|
||||
class AudioMeta(TypedDict, total=False):
|
||||
duration: str
|
||||
bit_rate: float
|
||||
size: str
|
||||
fileSize: str
|
||||
bitrate: int
|
||||
samplingrate: int
|
||||
channels: int
|
||||
|
||||
|
||||
class VideoMeta(TypedDict):
|
||||
class VideoMeta(TypedDict, total=False):
|
||||
duration: str
|
||||
size: str
|
||||
format_name: str
|
||||
format_long_name: str
|
||||
fileSize: str
|
||||
width: int
|
||||
height: int
|
||||
codec_name: str
|
||||
display_aspect_ratio: str
|
||||
duration_ts: float
|
||||
bit_rate: float
|
||||
bitrate: int
|
||||
framerate: str
|
||||
|
||||
|
||||
def _decode_ffmpeg_output(output: Any) -> str:
|
||||
|
|
@ -157,32 +153,51 @@ def get_acodec_info(probe) -> Tuple[Optional[str], Optional[int]]:
|
|||
return None, None
|
||||
|
||||
|
||||
def _int_value(value: Any) -> Optional[int]:
|
||||
try:
|
||||
if value in (None, ""):
|
||||
return None
|
||||
return int(str(value))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
def _frame_rate(stream: Dict[str, Any]) -> Optional[str]:
|
||||
for key in ("avg_frame_rate", "r_frame_rate"):
|
||||
value = stream.get(key)
|
||||
if value not in (None, "", "0/0"):
|
||||
return str(value)
|
||||
return None
|
||||
|
||||
|
||||
def audio_meta(probe: Dict[str, Any]) -> Optional[AudioMeta]:
|
||||
return AudioMeta(
|
||||
duration=probe["format"].get("duration", ""),
|
||||
size=probe["format"].get("size", ""),
|
||||
format_name=probe["format"].get("format_name", ""),
|
||||
format_long_name=probe["format"].get("format_long_name", ""),
|
||||
bit_rate=float(probe["format"].get("bit_rate", 0.0)),
|
||||
stream = primary_audio_stream(probe)
|
||||
if not stream:
|
||||
return None
|
||||
meta = AudioMeta(
|
||||
duration=str(probe["format"].get("duration", "")),
|
||||
fileSize=str(probe["format"].get("size", "")),
|
||||
bitrate=_int_value(probe["format"].get("bit_rate")) or 0,
|
||||
samplingrate=_int_value(stream.get("sample_rate")) or 0,
|
||||
channels=_int_value(stream.get("channels")) or 0,
|
||||
)
|
||||
return {key: value for key, value in meta.items() if value not in ("", 0)}
|
||||
|
||||
|
||||
def video_meta(probe: Dict[str, Any]) -> Optional[VideoMeta]:
|
||||
stream = primary_video_stream(probe)
|
||||
if not stream:
|
||||
return None
|
||||
return VideoMeta(
|
||||
duration=probe["format"].get("duration", ""),
|
||||
size=probe["format"].get("size", ""),
|
||||
format_name=probe["format"].get("format_name", ""),
|
||||
format_long_name=probe["format"].get("format_long_name", ""),
|
||||
width=int(stream.get("width", 0)),
|
||||
height=int(stream.get("height", 0)),
|
||||
codec_name=stream.get("codec_name", ""),
|
||||
display_aspect_ratio=stream.get("display_aspect_ratio", ""),
|
||||
duration_ts=float(stream.get("duration_ts", 0.0)),
|
||||
bit_rate=float(stream.get("bit_rate", 0.0)),
|
||||
meta = VideoMeta(
|
||||
duration=str(probe["format"].get("duration", "")),
|
||||
fileSize=str(probe["format"].get("size", "")),
|
||||
width=_int_value(stream.get("width")) or 0,
|
||||
height=_int_value(stream.get("height")) or 0,
|
||||
bitrate=_int_value(stream.get("bit_rate") or probe["format"].get("bit_rate"))
|
||||
or 0,
|
||||
framerate=_frame_rate(stream) or "",
|
||||
)
|
||||
return {key: value for key, value in meta.items() if value not in ("", 0)}
|
||||
|
||||
|
||||
def audio_transcode_params(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue