gbstack / ffprobe-python Goto Github PK
View Code? Open in Web Editor NEWA wrapper of ffprobe command to extract metadata from media files.
License: Other
A wrapper of ffprobe command to extract metadata from media files.
License: Other
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 ?
Traceback (most recent call last):
File "U:/git/Documents/ts_download/test4.py", line 5, in get_video_info
metadata = FFProbe(file)
not enough values to unpack (expected at least 2, got 1)
File "C:\Python\Python38-32\lib\site-packages\ffprobe\ffprobe.py", line 54, in __init__
self.streams.append(FFStream(data_lines))
False
File "C:\Python\Python38-32\lib\site-packages\ffprobe\ffprobe.py", line 114, in __init__
self.__dict__.update({key: value for key, value, *_ in [line.strip().split('=')]})
File "C:\Python\Python38-32\lib\site-packages\ffprobe\ffprobe.py", line 114, in <dictcomp>
self.__dict__.update({key: value for key, value, *_ in [line.strip().split('=')]})
ValueError: not enough values to unpack (expected at least 2, got 1)
ffprobe -v error -show_streams -print_format json media\demo\The.Elephant.Queen.2019.1080p_de.mp4
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "6211676/297862611",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 1920,
"height": 1038,
"coded_width": 1920,
"coded_height": 1040,
"has_b_frames": 1,
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "320:173",
"pix_fmt": "yuv420p",
"level": 40,
"color_range": "tv",
"color_space": "bt709",
"color_transfer": "bt709",
"color_primaries": "bt709",
"chroma_location": "topleft",
"refs": 1,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "24000/1001",
"avg_frame_rate": "2139968000/89254491",
"time_base": "1/16000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 89212256,
"duration": "5575.766000",
"bit_rate": "9878894",
"bits_per_raw_sample": "8",
"nb_frames": "133748",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "eng",
"handler_name": "VideoHandler"
}
},
{
"index": 1,
"codec_name": "ac3",
"codec_long_name": "ATSC A/52A (AC-3)",
"codec_type": "audio",
"codec_time_base": "1/48000",
"codec_tag_string": "ac-3",
"codec_tag": "0x332d6361",
"sample_fmt": "fltp",
"sample_rate": "48000",
"channels": 6,
"channel_layout": "5.1(side)",
"bits_per_sample": 0,
"dmix_mode": "-1",
"ltrt_cmixlev": "-1.000000",
"ltrt_surmixlev": "-1.000000",
"loro_cmixlev": "-1.000000",
"loro_surmixlev": "-1.000000",
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/48000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 267638784,
"duration": "5575.808000",
"bit_rate": "384000",
"nb_frames": "174326",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "eng",
"handler_name": "SoundHandler"
},
"side_data_list": [
{
"side_data_type": "Audio Service Type"
}
]
}
]
}
I would like FFProbe to tell me the duration in milliseconds. I created a workaround as follows, but would like native support:
mp4_data = FFProbe(mp4_file)
duration_s = mp4_data.__dict__['metadata']['Duration']
# convert to duration by pretending it's a time since 00:00:00.00
zero = datetime.datetime.strptime('00:00:00.00', '%H:%M:%S.%f')
duration = datetime.datetime.strptime(duration_s, '%H:%M:%S.%f') - zero
total_duration += duration.seconds * 1000 + duration.microseconds / 1000
Hi,
When I have installed python package setuptools 59.x.y version (latest), I am unable to build this ffprobe package. This has to do with that you read a readme file for description: https://github.com/gbstack/ffprobe-python/blob/master/setup.py#L7
And apparently, it is not allowed to have new lines in there with setup tools 59.x.y version.
pip install git+https://github.com/gbstack/ffprobe-python
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting git+https://github.com/gbstack/ffprobe-python
Cloning https://github.com/gbstack/ffprobe-python to /tmp/pip-req-build-ot7_lcsu
Running command git clone --filter=blob:none -q https://github.com/gbstack/ffprobe-python /tmp/pip-req-build-ot7_lcsu
Resolved https://github.com/gbstack/ffprobe-python to commit 6b499f63e3db0293ae58f99c1726cd0aabe2bd12
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/pi/TerrariumPI/venv/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-ot7_lcsu/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-ot7_lcsu/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-xj02ahpt
cwd: /tmp/pip-req-build-ot7_lcsu/
Complete output (26 lines):
running egg_info
creating /tmp/pip-pip-egg-info-xj02ahpt/ffprobe_python.egg-info
writing /tmp/pip-pip-egg-info-xj02ahpt/ffprobe_python.egg-info/PKG-INFO
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-ot7_lcsu/setup.py", line 38, in <module>
'Topic :: Software Development :: Libraries'
File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 292, in run
writer(self, ep.name, os.path.join(self.egg_info, ep.name))
File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/setuptools/command/egg_info.py", line 656, in write_pkg_info
metadata.write_pkg_info(cmd.egg_info)
File "/usr/lib/python3.7/distutils/dist.py", line 1117, in write_pkg_info
self.write_pkg_file(pkg_info)
File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/setuptools/dist.py", line 167, in write_pkg_file
write_field('Summary', single_line(self.get_description()))
File "/home/pi/TerrariumPI/venv/lib/python3.7/site-packages/setuptools/dist.py", line 151, in single_line
raise ValueError('Newlines are not allowed')
ValueError: Newlines are not allowed
----------------------------------------
WARNING: Discarding git+https://github.com/gbstack/ffprobe-python. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Where you see the Value Error: Newlines are not allowed
When I downgrade to setup tools 58.x.y version, I can build this package. So it looks like the setup tools is changing their behavior about description fields. Could you have a look into this?
Thanks
Tried using ffprobe-python to check SRT stream.
Unfortunately because of: if os.path.isfile(self.path_to_video) or self.path_to_video.startswith('http’):
it didn't work.
It seems, probing wav files (or other files that don't have a video stream) seems to not work. I tried the same with a mov file and it worked like a charm.
File "C:\Users\MYUSER\AppData\Local\pypoetry\Cache\virtualenvs\MYPROJECT-R5fSZ7UV-py3.8\lib\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'
Error:
(python-v-env) hcruz@Hugos-MacBook-Pro personal-file-processor % python3 demo.py
Traceback (most recent call last):
File "demo.py", line 38, in
video_creation_datetime("/Users/hcruz/Documents/development/python/personal-file-processor/IMG_0119.MOV")
File "demo.py", line 22, in video_creation_datetime
metadata=FFProbe(filepath)
File "/Users/hcruz/Documents/development/python/python-v-env/lib/python3.8/site-packages/ffprobe/ffprobe.py", line 54, in init
self.streams.append(FFStream(data_lines))
File "/Users/hcruz/Documents/development/python/python-v-env/lib/python3.8/site-packages/ffprobe/ffprobe.py", line 114, in init
self.dict.update({key: value for key, value, *_ in [line.strip().split('=')]})
File "/Users/hcruz/Documents/development/python/python-v-env/lib/python3.8/site-packages/ffprobe/ffprobe.py", line 114, in
self.dict.update({key: value for key, value, *_ in [line.strip().split('=')]})
ValueError: not enough values to unpack (expected at least 2, got 1)
FFPROBE OUTPUT
(python-v-env) hcruz@Hugos-MacBook-Pro personal-file-processor % ffprobe IMG_0119.MOV
ffprobe version 4.3.1 Copyright (c) 2007-2020 the FFmpeg developers
built with Apple clang version 12.0.0 (clang-1200.0.32.28)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_9 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_0119.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2021-01-11T09:59:47.000000Z
com.apple.quicktime.location.ISO6709: +10.7792+106.7464+000.499/
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 6
com.apple.quicktime.software: 12.5
com.apple.quicktime.creationdate: 2021-01-11T16:59:47+0700
Duration: 00:00:02.37, start: 0.000000, bitrate: 11021 kb/s
Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 10880 kb/s, 30.02 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 180
creation_time : 2021-01-11T09:59:47.000000Z
handler_name : Core Media Video
encoder : H.264
Side data:
displaymatrix: rotation of -180.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 90 kb/s (default)
Metadata:
creation_time : 2021-01-11T09:59:47.000000Z
handler_name : Core Media Audio
Stream #0:2(und): Data: none (mebx / 0x7862656D), 23 kb/s (default)
Metadata:
creation_time : 2021-01-11T09:59:47.000000Z
handler_name : Core Media Metadata
Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2021-01-11T09:59:47.000000Z
handler_name : Core Media Metadata
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3
Just found this recently and I think it would be best to use -print_format json
instead of parsing the normal output. I also noticed that it checks whether the file existed or not. This unfortunately prevents it from working with HTTP and FTP.
I have an issue - The below code works fine when run locally on a Compute Instance (NC6 GPU Series Compute).
#!/usr/bin/env python
from ffprobe import FFProbe
from pydub import AudioSegment
mp4a_version = AudioSegment.from_file("format_test.m4a", "m4a")
dst_name = "test.wav"
exprt_file = mp4a_version.export(dst_name, format='wav')**
When run on a AML pipeline on a Compute Cluster (NC6 series GPU series Compute), it throws an error stating -
ImportError: cannot import name 'FFProbe' from partially initialized module 'ffprobe' (most likely due to a circular import) (/opt/conda/envs/ptca/lib/python3.8/site-packages/ffprobe/init.py)
Please note that the pipeline runs on a curated environment with the following configuration -
FROM mcr.microsoft.com/azureml/curated/acpt-pytorch-1.13-cuda11.7:latest
COPY requirements.txt .
RUN pip install -r requirements.txt --no-cache-dir
azureml-core
matplotlib
ffmpeg-python
pydub
The curated environment builds fine without errors, BUT, the pipeline still fails with - ImportError: cannot import name 'FFProbe' from partially initialized module 'ffprobe'
How to FIX this?
Any specific version of ffprobe we should PIN with this image "mcr.microsoft.com/azureml/curated/acpt-pytorch-1.13-cuda11.7:latest" ?
Any ideas?
Hello, I am trying to use this plugin but when I use it I get this error:
Traceback (most recent call last):
File "/home/john/Projects/autotranscoder/./transcoder.py", line 12, in
FFProbe(file)
File "/home/john/.local/lib/python3.9/site-packages/ffprobe/ffprobe.py", line 54, in init
self.streams.append(FFStream(data_lines))
File "/home/john/.local/lib/python3.9/site-packages/ffprobe/ffprobe.py", line 114, in init
self.dict.update({key: value for key, value, *_ in [line.strip().split('=')]})
File "/home/john/.local/lib/python3.9/site-packages/ffprobe/ffprobe.py", line 114, in
self.dict.update({key: value for key, value, *_ in [line.strip().split('=')]})
ValueError: not enough values to unpack (expected at least 2, got 1)
This is my code
#!/usr/bin/env python
from ffprobe import FFProbe
import os
path = "/home/videos/"
for files in os.listdir(path):
file = os.path.join(path, files)
if os.path.isfile(file):
FFProbe(file)
print(metadata)
I am 100% sure that directory exists and for loop generates valid paths to video files.
How can I fix it ?
Hi! I just installed your ffprobe wrapper directly from PyPi, but when I tried to use it (as per the example), I get the following error:
>>> from ffprobe import FFProbe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\sgraaf\AppData\Roaming\Python\Python39\site-packages\ffprobe\__init__.py", line 1, in <module>
from ffprobe import FFProbe
ImportError: cannot import name 'FFProbe' from partially initialized module 'ffprobe' (most likely due to a circular import) (C:\Users\sgraaf\AppData\Roaming\Python\Python39\site-packages\ffprobe\__init__.py)
I am using ffprobe 0.5 w/ Python 3.9.0 on Windows 10 X64.
ffprobe
supports probing remote files over HTTP. It would be great if this library could too.
Right now, if you try and load a remote file you get an OS Error because the file doesn't exist on disk.
>>> from ffprobe import FFProbe
>>> metadata = FFProbe("https://example.com/movie.mp4")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/example-user/virtual-env/lib/python3.6/site-packages/ffprobe/ffprobe.py", line 101, in __init__
raise IOError('No such media file ' + self.path_to_video)
OSError: No such media file https://example.com/movie.mp4
When I try to run against a MKV with chapters I get a error from line 75: AttributeError: 'NoneType' object has no attribute 'groups'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.