Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Video Metadata Question
#3
(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.mkv
Eg 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
Reply


Messages In This Thread
Video Metadata Question - by malonn - Jul-20-2018, 03:53 PM
RE: Video Metadata Question - by DeaD_EyE - Jul-20-2018, 04:54 PM
RE: Video Metadata Question - by snippsat - Jul-20-2018, 06:37 PM
RE: Video Metadata Question - by malonn - Jul-20-2018, 08:35 PM
RE: Video Metadata Question - by snippsat - Jul-20-2018, 09:51 PM
RE: Video Metadata Question - by malonn - Jul-20-2018, 11:23 PM
RE: Video Metadata Question - by snippsat - Jul-21-2018, 12:41 AM
RE: Video Metadata Question - by malonn - Jul-21-2018, 01:26 AM
RE: Video Metadata Question - by malonn - Jul-21-2018, 05:17 PM
RE: Video Metadata Question - by malonn - Jul-21-2018, 08:26 PM
RE: Video Metadata Question - by malonn - Jul-23-2018, 04:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question image manipulation (cropping and MetaData) SpongeB0B 4 1,304 Jul-03-2023, 06:35 PM
Last Post: SpongeB0B
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,923 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  Adding Language metadata to a PDF programmatically bhargavi22 0 2,000 Aug-17-2020, 12:53 PM
Last Post: bhargavi22
  METADATA Errors millpond 0 1,995 Jul-21-2020, 08:22 AM
Last Post: millpond
  How to sort image files according to a metadata file? Brahmslove 1 3,215 Dec-05-2019, 11:25 PM
Last Post: scidam
  Parse the data in XML metadata field klllmmm 2 3,400 Jun-19-2019, 04:24 PM
Last Post: klllmmm
  Tiff metadata sudecki 1 25,149 Aug-10-2018, 07:08 AM
Last Post: sudecki
  I have a question from a YouTube video I saw: nelsonkane 9 5,409 Dec-27-2017, 11:17 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020