diff --git a/analyze.py b/analyze.py new file mode 100644 index 0000000..2d4528a --- /dev/null +++ b/analyze.py @@ -0,0 +1,35 @@ +"""Print the type of frames for a given video +""" + +import json +import subprocess +from pathlib import Path + + +def analyze(input_path: Path): + output = subprocess.check_output( + [ + "ffprobe", + "-v", + "quiet", + "-pretty", + "-print_format", + "json", + "-show_entries", + "format=size,bit_rate:frame=coded_picture_number,pkt_pts_time,pkt_pts,pkt_dts_time,pkt_dts,pkt_duration_time,pict_type,interlaced_frame,top_field_first,repeat_pict,width,height,sample_aspect_ratio,display_aspect_ratio,r_frame_rate,avg_frame_rate,time_base,pkt_size", + "-select_streams", + "v:0", + input_path + ], + ) + data = json.loads(output) + for frame in data["frames"]: + print(frame["coded_picture_number"], frame["pict_type"]) + + +if __name__ == "__main__": + import argparse + parser = argparse.ArgumentParser() + parser.add_argument("input_path", type=Path) + args = parser.parse_args() + analyze(args.input_path)