Skip to content

Commit

Permalink
utils: timestamp: Check multiple timestamp keys in container files
Browse files Browse the repository at this point in the history
Not all containers use "pts_time" as a timestamp key.  Add the ability
to read one of multiple timestamp keys to use instead.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Aug 14, 2023
1 parent 1c1d1c1 commit 75cc93a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions utils/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2021, Raspberry Pi Ltd.
#
import argparse
import json
import subprocess

try:
Expand All @@ -21,12 +22,19 @@ def read_times_pts(file):


def read_times_container(file):
cmd = ['ffprobe', file, '-hide_banner', '-select_streams', 'v', '-show_entries', 'frame=pts_time', '-of', 'csv=p=0']
cmd = ['ffprobe', file, '-hide_banner', '-select_streams', 'v', '-show_entries', 'frame', '-of', 'json']
r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
if r.returncode:
raise RuntimeError(f'ffprobe failed to run with command:\n{" ".join(cmd)}')

ts_list = [float(ts) * 1000 for ts in r.stdout.split('\n')[1:-1] if ts != '']
frame_data = json.loads(r.stdout)['frames']
keys = ['pkt_pts_time', 'pts_time', 'pkt_dts_time', 'dts_time']
key = [k for k in keys if k in frame_data[0].keys()]

if len(key) == 0:
raise RuntimeError(f'Timestamp keys not found in {file}')

ts_list = [float(f[key[0]]) * 1000 for f in frame_data]
return ts_list


Expand Down

0 comments on commit 75cc93a

Please sign in to comment.