Skip to content

Instantly share code, notes, and snippets.

@MandarGogate
Last active November 26, 2022 08:19
Show Gist options
  • Save MandarGogate/d49d1fd871b85c9840d5df7656c10c41 to your computer and use it in GitHub Desktop.
Save MandarGogate/d49d1fd871b85c9840d5df7656c10c41 to your computer and use it in GitHub Desktop.
import tempfile
import json
import subprocess
import ffmpy
import gradio as gr
include_audio = False
def ffprobe_info(filepath):
ff = ffmpy.FFprobe(inputs={filepath: None}, global_options='-v quiet -print_format json -show_format -show_streams')
stdout, stderr = ff.run(stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return json.dumps([{stream["codec_type"]:{k: stream[k] for k in stream.keys() if k.startswith("code")}} for stream in json.loads(stdout)["streams"]], indent=4)
with gr.Blocks(title="Get video metadata") as demo:
gr.Markdown("## Get video metadata")
with gr.Row():
with gr.Column(scale=1, min_width=300):
video_upload = gr.Video(type="file", source="upload",include_audio=include_audio)
video_record = gr.Video(source="webcam", type="", mirror_webcam=False, format="mp4",
label="Get webcam info", include_audio=include_audio)
get_info = gr.Button("Get video information")
with gr.Column(scale=1, min_width=900):
video_info = gr.Markdown(label="video_info")
def get_video_info(video_upload, video_record):
if video_upload is not None:
video_props = ffprobe_info(video_upload)
elif video_record is not None:
video_props = ffprobe_info(video_record)
else:
return {video_info: gr.update(value="Please record/upload a file")}
return {video_info: gr.update(value=f"## Metadata\n```json\n{video_props}\n```")}
get_info.click(get_video_info, [video_upload, video_record], [video_info])
demo.launch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment