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


Python ffmpeg.probe方法代码示例

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


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

示例1: __init__

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.buffer = Queue(maxsize=self.buffer_size)

        # Initialise stream
        self.stream = (
            ffmpeg
            .input(self.url.geturl(), **self.input_opts)
            .output('pipe:', **self.output_opts)
            .global_args('-y', '-loglevel', 'panic')
            .run_async(pipe_stdout=True)
        )

        # Probe stream information
        self._stream_info = next(
            s for s
            in ffmpeg.probe(self.url.geturl())['streams']
            if s['codec_type'] == 'video')

        # Initialise capture thread
        self._capture_thread = threading.Thread(target=self._run)
        self._capture_thread.daemon = True
        self._capture_thread.start() 
开发者ID:dstl,项目名称:Stone-Soup,代码行数:26,代码来源:video.py

示例2: check_video_rotation

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def check_video_rotation(filename):
    # thanks to
    # https://stackoverflow.com/questions/53097092/frame-from-video-is-upside-down-after-extracting/55747773#55747773

    # this returns meta-data of the video file in form of a dictionary
    meta_dict = ffmpeg.probe(filename)

    # from the dictionary, meta_dict['streams'][0]['tags']['rotate'] is the key
    # we are looking for
    rotation_code = None
    try:
        if int(meta_dict['streams'][0]['tags']['rotate']) == 90:
            rotation_code = cv2.ROTATE_90_CLOCKWISE
        elif int(meta_dict['streams'][0]['tags']['rotate']) == 180:
            rotation_code = cv2.ROTATE_180
        elif int(meta_dict['streams'][0]['tags']['rotate']) == 270:
            rotation_code = cv2.ROTATE_90_COUNTERCLOCKWISE
        else:
            raise ValueError
    except KeyError:
        pass

    return rotation_code 
开发者ID:stefanopini,项目名称:simple-HRNet,代码行数:25,代码来源:visualization.py

示例3: get_video_size

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def get_video_size(filename):
    logger.info('Getting video size for {!r}'.format(filename))
    probe = ffmpeg.probe(filename)
    video_info = next(s for s in probe['streams'] if s['codec_type'] == 'video')
    width = int(video_info['width'])
    height = int(video_info['height'])
    return width, height 
开发者ID:kkroening,项目名称:ffmpeg-python,代码行数:9,代码来源:tensorflow_stream.py

示例4: test_save

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def test_save(adapter, audio_data):
    """ Test audio saving. """
    with TemporaryDirectory() as directory:
        path = join(directory, 'ffmpeg-save.mp3')
        adapter.save(
            path,
            audio_data[0],
            audio_data[1])
        probe = ffmpeg.probe(TEST_AUDIO_DESCRIPTOR)
        assert len(probe['streams']) == 1
        stream = probe['streams'][0]
        assert stream['codec_type'] == 'audio'
        assert stream['channels'] == 2
        assert stream['duration'] == '10.919184' 
开发者ID:deezer,项目名称:spleeter,代码行数:16,代码来源:test_ffmpeg_adapter.py

示例5: has_soundtrack

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def has_soundtrack(file_path):
    audio = ffmpeg.probe(file_path, select_streams='a')
    return audio["streams"] 
开发者ID:cgwire,项目名称:zou,代码行数:5,代码来源:movie_utils.py

示例6: test__probe

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def test__probe():
    data = ffmpeg.probe(TEST_INPUT_FILE1)
    assert set(data.keys()) == {'format', 'streams'}
    assert data['format']['duration'] == '7.036000' 
开发者ID:kkroening,项目名称:ffmpeg-python,代码行数:6,代码来源:test_ffmpeg.py

示例7: test__probe_timeout

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def test__probe_timeout():
    with pytest.raises(subprocess.TimeoutExpired) as excinfo:
        data = ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
    assert 'timed out after 0 seconds' in str(excinfo.value) 
开发者ID:kkroening,项目名称:ffmpeg-python,代码行数:6,代码来源:test_ffmpeg.py

示例8: test__probe__exception

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def test__probe__exception():
    with pytest.raises(ffmpeg.Error) as excinfo:
        ffmpeg.probe(BOGUS_INPUT_FILE)
    assert str(excinfo.value) == 'ffprobe error (see stderr output for detail)'
    assert 'No such file or directory'.encode() in excinfo.value.stderr 
开发者ID:kkroening,项目名称:ffmpeg-python,代码行数:7,代码来源:test_ffmpeg.py

示例9: test__probe__extra_args

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def test__probe__extra_args():
    data = ffmpeg.probe(TEST_INPUT_FILE1, show_frames=None)
    assert set(data.keys()) == {'format', 'streams', 'frames'} 
开发者ID:kkroening,项目名称:ffmpeg-python,代码行数:5,代码来源:test_ffmpeg.py

示例10: aureadmeta

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def aureadmeta(fn):
    if not os.path.exists(fn):
        raise FileNotFoundError
    probe = ffmpeg.probe(fn)
    for stream in probe['streams']:
        if stream['codec_type'] == 'audio':
            meta = {
                'channels': stream['channels'],
                'sample_rate': int(stream['sample_rate']),
                'duration': float(probe['format']['duration'])
            }
            return meta
    return None

# auread should be combined with aureadmeta to not force the samplerate or input type if they are None 
开发者ID:kylemcdonald,项目名称:python-utils,代码行数:17,代码来源:ffmpeg.py

示例11: vidreadmeta

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def vidreadmeta(fn):
    if not os.path.exists(fn):
        raise FileNotFoundError
    probe = ffmpeg.probe(fn)
    for stream in probe['streams']:
        if stream['codec_type'] == 'video':
            meta = {
                'width': int(stream['width']),
                'height': int(stream['height']),
                'duration': float(probe['format']['duration'])
            }
            return meta
    return None 
开发者ID:kylemcdonald,项目名称:python-utils,代码行数:15,代码来源:ffmpeg.py

示例12: vidread

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def vidread(fn, samples=None, rate=None, hwaccel=None):
    if not os.path.exists(fn):
        raise FileNotFoundError
    probe = ffmpeg.probe(fn)
    out_params = {}
    for stream in probe['streams']:
        if stream['codec_type'] == 'video':
            width, height = stream['width'], stream['height']
            if samples is not None:
                duration = float(stream['duration'])
                interval = duration / samples
                out_params['r'] = 1 / interval
                out_params['ss'] = interval / 2
            elif rate is not None:
                out_params['r'] = rate
                out_params['ss'] = 1 / (2 * rate)
    in_params = {}
    if hwaccel is not None:
        in_params['hwaccel'] = hwaccel
    proc = (
        ffmpeg
        .input(fn, **in_params)
        .output('pipe:', format='rawvideo', pix_fmt='rgb24', **out_params)
        .run_async(pipe_stdout=True)
    )
    channels = 3
    frame_number = -1
    while True:
        in_bytes = proc.stdout.read(width*height*channels)
        frame_number += 1
        if not in_bytes:
            break
        in_frame = (
            np
            .frombuffer(in_bytes, np.uint8)
            .reshape([height, width, channels])
        )
        yield in_frame
    proc.wait() 
开发者ID:kylemcdonald,项目名称:python-utils,代码行数:41,代码来源:ffmpeg.py

示例13: _get_video_dim

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def _get_video_dim(self, video_path):
        probe = ffmpeg.probe(video_path)
        video_stream = next((stream for stream in probe['streams']
                             if stream['codec_type'] == 'video'), None)
        width = int(video_stream['width'])
        height = int(video_stream['height'])
        return height, width 
开发者ID:antoine77340,项目名称:video_feature_extractor,代码行数:9,代码来源:video_loader.py

示例14: load

# 需要导入模块: import ffmpeg [as 别名]
# 或者: from ffmpeg import probe [as 别名]
def load(
            self, path, offset=None, duration=None,
            sample_rate=None, dtype=np.float32):
        """ Loads the audio file denoted by the given path
        and returns it data as a waveform.

        :param path: Path of the audio file to load data from.
        :param offset: (Optional) Start offset to load from in seconds.
        :param duration: (Optional) Duration to load in seconds.
        :param sample_rate: (Optional) Sample rate to load audio with.
        :param dtype: (Optional) Numpy data type to use, default to float32.
        :returns: Loaded data a (waveform, sample_rate) tuple.
        :raise SpleeterError: If any error occurs while loading audio.
        """
        _check_ffmpeg_install()
        if not isinstance(path, str):
            path = path.decode()
        try:
            probe = ffmpeg.probe(path)
        except ffmpeg._run.Error as e:
            raise SpleeterError(
                'An error occurs with ffprobe (see ffprobe output below)\n\n{}'
                .format(e.stderr.decode()))
        if 'streams' not in probe or len(probe['streams']) == 0:
            raise SpleeterError('No stream was found with ffprobe')
        metadata = next(
            stream
            for stream in probe['streams']
            if stream['codec_type'] == 'audio')
        n_channels = metadata['channels']
        if sample_rate is None:
            sample_rate = metadata['sample_rate']
        output_kwargs = {'format': 'f32le', 'ar': sample_rate}
        if duration is not None:
            output_kwargs['t'] = _to_ffmpeg_time(duration)
        if offset is not None:
            output_kwargs['ss'] = _to_ffmpeg_time(offset)
        process = (
            ffmpeg
            .input(path)
            .output('pipe:', **output_kwargs)
            .run_async(pipe_stdout=True, pipe_stderr=True))
        buffer, _ = process.communicate()
        waveform = np.frombuffer(buffer, dtype='<f4').reshape(-1, n_channels)
        if not waveform.dtype == np.dtype(dtype):
            waveform = waveform.astype(dtype)
        return (waveform, sample_rate) 
开发者ID:deezer,项目名称:spleeter,代码行数:49,代码来源:ffmpeg.py


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