-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
problems
- sometime -rtsp_transport tcp would block the thread because it is not supported
- sometime cost too much time to get info make generate reader block more than 5 seconds
a fast way to solve all problems above
- make udp or tcp as function param option
- using
-analyzeduration
to reduce the time cost to analysis meta -analyzeduration
worked on ffprobe version N-118248-g252fc2e047-20250107 ,old ver maybe 'max_analyze_duration', i am not sure
def get_info(src, timeout=None, rtspTcp=False, durationMs: int = 100):
resp_spec = '' if not src.startswith('rtsp://') else (
' -rtsp_transport tcp' if rtspTcp else ' -rtsp_transport udp')
analyze_duration = f' -analyzeduration {durationMs * 1000}'
ffprobe_2_json = 'ffprobe -v quiet -print_format json=compact=1' + resp_spec + analyze_duration
cmd = '{} -select_streams v:0 -show_streams -i {}'.format(ffprobe_2_json, src)
print(cmd)
timeout = None if timeout is None or timeout< 0 else timeout
output = subprocess.check_output(shlex.split(cmd), shell=False, timeout=timeout)
data: dict = json.loads(output)
stream0: dict = data['streams'][0]
fps = float(stream0.get('r_frame_rate', "1/1").split("/")[0])
codec = stream0.get('codec_name', '')
width = stream0.get('width', 0)
height = stream0.get('height', 0)
duration = stream0.get('duration', 0)
frame_count = stream0.get('nb_frames', 0)
vtype = "file" if not src.__contains__("://") else "stream"
return {
'fps': fps, 'codec': codec, 'width': width, 'height': height,
'duration': duration, 'frame_count': frame_count, "src": src, "vtype": vtype,
}
other duration options
Metadata
Metadata
Assignees
Labels
No labels