Last active
June 10, 2022 15:07
-
-
Save sscarbal/e3c493d8e3f622bcf6c4153dbe1c6a28 to your computer and use it in GitHub Desktop.
Python function to retrieve the timestamps of a input video file using ffmpeg.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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