Skip to content

Instantly share code, notes, and snippets.

@ConAlgorithm
Forked from sscarbal/find_video_metadata.py
Created June 10, 2022 15:07
Show Gist options
  • Save ConAlgorithm/ef0c21818b9a6ac0b7137b0210621aae to your computer and use it in GitHub Desktop.
Save ConAlgorithm/ef0c21818b9a6ac0b7137b0210621aae to your computer and use it in GitHub Desktop.
Python function to retrieve the timestamps of a input video file using ffmpeg.
import subprocess
import shlex
import json
# function to retrieve the timestamps of the input video file
def findVideoMetadata(pathToInputVideo):
cmd = "ffprobe -v quiet -print_format json -show_entries packet=pts_time"
args = shlex.split(cmd)
args.append(pathToInputVideo)
# run the ffprobe process, decode stdout into utf-8 & convert to JSON
ffprobeOutput = subprocess.check_output(args).decode('utf-8')
ffprobeOutput = json.loads(ffprobeOutput)
pts_time= []
for i in range(len(ffprobeOutput['packets'])):
pts_time.append(ffprobeOutput['packets'][i])
return pts_time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment