ffprobe-python
ffprobe-python copied to clipboard
AttributeError: 'NoneType' object has no attribute 'groups'
Hey folks,
this lib seems exactly what im looking for but Im unable to properly parse all information using the following snipped:
#!/usr/bin/env python
from ffprobe import FFProbe
# Local file
metadata=FFProbe('/home/mike/Desktop/2 Wie werde ich ein Hase.m4v')
for stream in metadata.streams:
if stream.is_video():
print('Stream contains {} frames.'.format(stream.frames()))
I always get back the following error:
File "/home/mike/Documents/PyCharm/Strics.io/strics_app/strics_app/meta_scrape.py", line 6, in <module>
metadata=FFProbe('/home/mike/Desktop/2 Wie werde ich ein Hase.m4v')
File "/home/claris/Documents/PyCharm/Strics.io/strics_app/venv/lib/python3.9/site-packages/ffprobe/ffprobe.py", line 75, in __init__
self.metadata[m.groups()[0]] = m.groups()[1].strip()
AttributeError: 'NoneType' object has no attribute 'groups'
can smb help ?
And why does this lib even exists if I can do:
ffprobe -print_format json -show_streams -show_format -loglevel quiet -hide_banner
It looks like the issue is a regex problem. My exception was raised on this line
' Chapter #0:0: start 0.000000, end 485.902000\n'
In particular, on the string
end 485.902000\n
The regex being used to piece this apart
m = re.search(r'(\w+)\s*:\s*(.*)$', s)
Wont return anything as the string above doesn't match the regex listed. I am not quite sure the best way to go about parsing that out, though to @venomone 's point, this entire script could be redone to simply wrap and ingest the output of -print_format json -show_format
Also probably worth using that -hide_banner flag to ignore parsing out (and ignoring) the banner text displayed by ffprobe.
Both these options appear to be quite old in ffprobe, so they should be safe to use here. https://github.com/FFmpeg/FFmpeg/blame/master/fftools/ffprobe.c If I have more time I might look into doing that. For now though I am going to have to abandon this project and inject the output json myself
If anyone's looking for a longer-term solution, I've implemented the above
ffprobe -print_format json -show_streams -show_format
command-line, plus a bunch of other bug-fixes, features, and improvements, in a fork:
https://github.com/jboy/ffprobe3-python3
(Python3 only, sorry.)