Skip to content

Instantly share code, notes, and snippets.

@JupyterJones
Last active December 20, 2018 01:42
Show Gist options
  • Save JupyterJones/cd6fe6a171c0261e8948cd07fcc17a44 to your computer and use it in GitHub Desktop.
Save JupyterJones/cd6fe6a171c0261e8948cd07fcc17a44 to your computer and use it in GitHub Desktop.
Retrieve and print video info using skvideo . SEE Comment: This code may be indexed to parse a video file for specific information.
from skvideo.io import *
import json
INFO = ffprobe("VID/videos/out.mp4")
print(json.dumps(INFO, indent=4))
"""
results in:
{
"video": {
"@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": "1/60",
"@codec_tag_string": "avc1",
"@codec_tag": "0x31637661",
"@width": "640",
"@height": "640",
"@coded_width": "640",
"@coded_height": "640",
"@has_b_frames": "2",
"@sample_aspect_ratio": "1:1",
"@display_aspect_ratio": "1:1",
"@pix_fmt": "yuv420p",
"@level": "31",
"@chroma_location": "left",
"@refs": "1",
"@is_avc": "true",
"@nal_length_size": "4",
"@r_frame_rate": "30/1",
"@avg_frame_rate": "30/1",
"@time_base": "1/15360",
"@start_pts": "0",
"@start_time": "0.000000",
"@duration_ts": "921600",
"@duration": "60.000000",
"@bit_rate": "462855",
"@bits_per_raw_sample": "8",
"@nb_frames": "1800",
"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"
},
"tag": [
{
"@key": "language",
"@value": "und"
},
{
"@key": "handler_name",
"@value": "VideoHandler"
}
]
}
}
"""
@JupyterJones
Copy link
Author

This code may be indexed to parse a video file for specific information.

from skvideo.io import *
import json
INFO = ffprobe("VID/videos/out.mp4")
TEXT = (json.dumps(INFO, indent=4))
TEXT = str(TEXT)
text = TEXT.split(",")
print text[1]
print text[2]
print "----------------"
print text[8],text[9]

Results:
    "@codec_name": "h264"
    "@codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"
    ----------------
    "@width": "640"  
    "@height": "640"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment