Transfer functions related to Matroska codec private data into a dedicated module.
This commit is contained in:
@@ -30,8 +30,6 @@ from tscut.h264.parameters import (
|
||||
PPS,
|
||||
)
|
||||
|
||||
from tscut.matroska.ebml import get_ebml_length
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -305,30 +303,3 @@ def get_avc_config_from_h264(input_file: IO[bytes]) -> AVCDecoderConfiguration:
|
||||
avcconfig.pps[pps.pic_parameter_set_id] = pps
|
||||
|
||||
return avcconfig
|
||||
|
||||
# Unused ?
|
||||
# @typechecked
|
||||
# def get_codec_private_data_from_h264(input_file: IO[bytes]) -> AVCDecoderConfiguration:
|
||||
# avcconfig = get_avc_config_from_h264(input_file)
|
||||
# res = dump_codec_private_data(avcconfig)
|
||||
#
|
||||
# return res
|
||||
|
||||
@typechecked
|
||||
def dump_codec_private_data(avc_decoder_configuration: AVCDecoderConfiguration) -> bytearray | None:
|
||||
# Rebuild a Matroska Codec Private Element
|
||||
res = bytearray()
|
||||
# Code private element
|
||||
res.extend(b'\x63\xA2')
|
||||
buf = avc_decoder_configuration.to_bytes()
|
||||
logger.debug('AVC configuration bitstream: %s (length: %d))', hexdump.dump(buf, sep=':'),
|
||||
len(buf))
|
||||
|
||||
embl_length = get_ebml_length(len(buf))
|
||||
if embl_length is None:
|
||||
return None
|
||||
logger.debug('EMBL encoded length: %s', hexdump.dump(embl_length, sep=':'))
|
||||
res.extend(embl_length)
|
||||
res.extend(buf)
|
||||
|
||||
return res
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#
|
||||
# Copyright (C) 2026 Frédéric Tronel
|
||||
|
||||
|
||||
import logging
|
||||
from typing import IO
|
||||
|
||||
from typeguard import typechecked
|
||||
import hexdump
|
||||
|
||||
from tscut.matroska.ebml import get_ebml_length
|
||||
from tscut.h264.avc import (
|
||||
AVCDecoderConfiguration,
|
||||
get_avc_config_from_h264
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@typechecked
|
||||
def dump_codec_private_data(avc_decoder_configuration: AVCDecoderConfiguration) -> bytearray | None:
|
||||
# Rebuild a Matroska Codec Private Element
|
||||
res = bytearray()
|
||||
# Code private element
|
||||
res.extend(b'\x63\xA2')
|
||||
buf = avc_decoder_configuration.to_bytes()
|
||||
logger.debug('AVC configuration bitstream: %s (length: %d))', hexdump.dump(buf, sep=':'),
|
||||
len(buf))
|
||||
|
||||
embl_length = get_ebml_length(len(buf))
|
||||
if embl_length is None:
|
||||
return None
|
||||
logger.debug('EMBL encoded length: %s', hexdump.dump(embl_length, sep=':'))
|
||||
res.extend(embl_length)
|
||||
res.extend(buf)
|
||||
|
||||
return res
|
||||
|
||||
@typechecked
|
||||
def get_codec_private_data_from_h264(input_file: IO[bytes]) -> AVCDecoderConfiguration:
|
||||
avcconfig = get_avc_config_from_h264(input_file)
|
||||
res = dump_codec_private_data(avcconfig)
|
||||
|
||||
return res
|
||||
+5
-3
@@ -32,10 +32,12 @@ from iso639.exceptions import InvalidLanguageValue
|
||||
from tqdm import tqdm
|
||||
from typeguard import typechecked
|
||||
|
||||
from tscut.h264.avc import (dump_codec_private_data,
|
||||
get_avc_config_from_h264,
|
||||
parse_codec_private)
|
||||
from tscut.h264.avc import (
|
||||
get_avc_config_from_h264,
|
||||
parse_codec_private
|
||||
)
|
||||
from tscut.matroska.ebml import change_ebml_element_size
|
||||
from tscut.matroska.codec import dump_codec_private_data
|
||||
from tscut.tools.ffprobe import (
|
||||
get_format,
|
||||
get_frame_rate,
|
||||
|
||||
Reference in New Issue
Block a user