Jul-20-2018, 06:37 PM
(Jul-20-2018, 03:53 PM)malonn Wrote: what would you all use for scripts that need to access metadata from a video file? I'm looking for video dimensions.Would use FFmpeg or more specialized tools for metadata like MediaInfo, ExifTool.
There are some wrapper for this tools if search PyPi,
but last time a looked at this i think 1-2 ago many of this tool is outdated or Python 2 only.
It easy to use say FFmpeg to get video dimensions.
ffmpeg -i your.mkv -hide_banner # Or Mediainfo here get all metadata mediainfo --Full your.mkvEg output FFmpeg:
Output:λ ffmpeg -i planet.mkv -hide_banner
Input #0, matroska,webm, from 'planet.mkv':
Metadata:
ENCODER : Lavf57.75.100
Duration: 00:49:48.09, start: 0.000000, bitrate: 2418 kb/s
Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
Metadata:
VARIANT_BITRATE : 0
DURATION : 00:49:48.085000000
Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:
VARIANT_BITRATE : 0
ENCODER : Lavc57.100.103 ac3
DURATION : 00:49:47.968000000
So can write quick wrapper example with subprocess.from subprocess import Popen, PIPE import re video_file = 'planet.mkv' res = Popen(['ffmpeg', '-i', video_file, '-hide_banner'],stdout=PIPE,stderr=PIPE) none,meta = res.communicate() meta_out = meta.decode() #---| Take out info duration = re.search(r'Duration:.*', meta_out) print(duration.group()) size = re.search(r'\d{3,4}x\d{2,3}', meta_out) print(size.group())
Output:Duration: 00:49:48.09, start: 0.000000, bitrate: 2418 kb/s
1280x720