Skip to content

Commit

Permalink
fix a issue when read video number frames
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxinfeng committed Nov 25, 2023
1 parent bf7ea0f commit 2db4e84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions ffmpegcv/video_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
Expand Down

0 comments on commit 2db4e84

Please sign in to comment.