diff --git a/ffmpegcv/video_info.py b/ffmpegcv/video_info.py index baf007d..5d3c14f 100644 --- a/ffmpegcv/video_info.py +++ b/ffmpegcv/video_info.py @@ -14,12 +14,21 @@ def get_info(video:str): do_scan_the_whole = video.split('.')[-1] in scan_the_whole - use_count_packets = '-count_packets' if do_scan_the_whole else '' - cmd = 'ffprobe -v quiet -print_format xml -select_streams v:0 {} -show_format -show_streams "{}"'.format(use_count_packets, video) - output = subprocess.check_output(cmd, shell=True) - root = ET.fromstring(output) - assert (root[0].tag, root[0][0].tag) == ("streams", "stream") - vinfo = root[0][0].attrib + + def ffprobe_info_(do_scan_the_whole): + use_count_packets = '-count_packets' if do_scan_the_whole else '' + cmd = 'ffprobe -v quiet -print_format xml -select_streams v:0 {} -show_format -show_streams "{}"'.format(use_count_packets, video) + output = subprocess.check_output(cmd, shell=True) + root = ET.fromstring(output) + assert (root[0].tag, root[0][0].tag) == ("streams", "stream") + vinfo = root[0][0].attrib + return vinfo + + vinfo = ffprobe_info_(do_scan_the_whole) + + if 'nb_frames' not in vinfo: + do_scan_the_whole = True + vinfo = ffprobe_info_(do_scan_the_whole) VideoInfo = namedtuple( "VideoInfo", ["width", "height", "fps", "count", "codec", "duration"] diff --git a/setup.py b/setup.py index 248756e..1b7ade6 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='ffmpegcv', # 应用名 - version='0.3.7', # 版本号 + version='0.3.8', # 版本号 packages=find_packages(include=['ffmpegcv*']), # 包括在安装包内的 Python 包 author='chenxf', author_email='cxf529125853@163.com',