当前位置: 首页>>代码示例>>Python>>正文


Python BitReader.get_position方法代码示例

本文整理汇总了Python中mutagen._util.BitReader.get_position方法的典型用法代码示例。如果您正苦于以下问题:Python BitReader.get_position方法的具体用法?Python BitReader.get_position怎么用?Python BitReader.get_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen._util.BitReader的用法示例。


在下文中一共展示了BitReader.get_position方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_position

# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
 def test_get_position(self):
     r = BitReader(cBytesIO(b"\xAB\xCD"))
     self.assertEqual(r.get_position(), 0)
     r.bits(3)
     self.assertEqual(r.get_position(), 3)
     r.skip(9)
     self.assertEqual(r.get_position(), 3 + 9)
     r.align()
     self.assertEqual(r.get_position(), 16)
开发者ID:akerbis,项目名称:mutagen,代码行数:11,代码来源:test__util.py

示例2: __init__

# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
    def __init__(self, fileobj, length):
        """Raises DescriptorError"""

        r = BitReader(fileobj)

        try:
            self.objectTypeIndication = r.bits(8)
            self.streamType = r.bits(6)
            self.upStream = r.bits(1)
            self.reserved = r.bits(1)
            self.bufferSizeDB = r.bits(24)
            self.maxBitrate = r.bits(32)
            self.avgBitrate = r.bits(32)

            if (self.objectTypeIndication, self.streamType) != (0x40, 0x5):
                return

            # all from here is optional
            if length * 8 == r.get_position():
                return

            tag = r.bits(8)
        except BitReaderError as e:
            raise DescriptorError(e)

        if tag == DecoderSpecificInfo.TAG:
            assert r.is_aligned()
            self.decSpecificInfo = DecoderSpecificInfo.parse(fileobj)
开发者ID:dcramer,项目名称:sickbeard_mp4_automator,代码行数:30,代码来源:_as_entry.py

示例3: find_stream

# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
    def find_stream(cls, fileobj, max_bytes):
        """Returns a possibly valid _ADTSStream or None.

        Args:
            max_bytes (int): maximum bytes to read
        """

        r = BitReader(fileobj)
        stream = cls(r)
        if stream.sync(max_bytes):
            stream.offset = (r.get_position() - 12) // 8
            return stream
开发者ID:dcramer,项目名称:sickbeard_mp4_automator,代码行数:14,代码来源:aac.py

示例4: test_align

# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
 def test_align(self):
     r = BitReader(cBytesIO(b"\xAB\xCD\xEF"))
     r.skip(3)
     self.assertEqual(r.align(), 5)
     self.assertEqual(r.get_position(), 8)
开发者ID:akerbis,项目名称:mutagen,代码行数:7,代码来源:test__util.py

示例5: __init__

# 需要导入模块: from mutagen._util import BitReader [as 别名]
# 或者: from mutagen._util.BitReader import get_position [as 别名]
    def __init__(self, fileobj):
        """Raises HeaderNotFoundError"""

        self.frame_offset = fileobj.tell()

        r = BitReader(fileobj)
        try:
            if r.bits(11) != 0x7ff:
                raise HeaderNotFoundError("invalid sync")
            version = r.bits(2)
            layer = r.bits(2)
            protection = r.bits(1)
            bitrate = r.bits(4)
            sample_rate = r.bits(2)
            padding = r.bits(1)
            r.skip(1)  # private
            self.mode = r.bits(2)
            r.skip(6)
        except BitReaderError:
            raise HeaderNotFoundError("truncated header")

        assert r.get_position() == 32 and r.is_aligned()

        # try to be strict here to redice the chance of a false positive
        if version == 1 or layer == 0 or sample_rate == 0x3 or \
                bitrate == 0xf or bitrate == 0:
            raise HeaderNotFoundError("invalid header")

        self.channels = 1 if self.mode == MONO else 2

        self.version = [2.5, None, 2, 1][version]
        self.layer = 4 - layer
        self.protected = not protection
        self.padding = bool(padding)

        self.bitrate = self.__BITRATE[(self.version, self.layer)][bitrate]
        self.bitrate *= 1000
        self.sample_rate = self.__RATES[self.version][sample_rate]

        if self.layer == 1:
            frame_size = 384
            slot = 4
        elif self.version >= 2 and self.layer == 3:
            frame_size = 576
            slot = 1
        else:
            frame_size = 1152
            slot = 1

        frame_length = (
            ((frame_size // 8 * self.bitrate) // self.sample_rate) +
            padding) * slot

        self.sketchy = True

        # Try to find/parse the Xing header, which trumps the above length
        # and bitrate calculation.
        if self.layer == 3:
            self._parse_vbr_header(fileobj, self.frame_offset, frame_size,
                                   frame_length)

        fileobj.seek(self.frame_offset + frame_length, 0)
开发者ID:2216288075,项目名称:meiduo_project,代码行数:64,代码来源:__init__.py


注:本文中的mutagen._util.BitReader.get_position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。