Debian Codegraph @

tools/ffmpeg/timeline.py

raw symbols SCIP
1 """
2 Usage
3
4 timeline.py sample [output_format]
5
6 Renders the media player's debug info to a format more suitable to postprocess
7 in a spreadsheets or other software, particularly to get a data visualization.
8
9 See output details in the manual.
10
11 Arguments
12 sample: sample to report
13 output_format : one of { "csv", "pkl"}, by default saves as .pkl (pickle)
14
15 The output will be written to session's output dir under
16 reports/sample.timeline.[.pkl or .csv]
17
18 Example
19
20 timeline.py small.mp4
21
22 will write the output to report/small.mp4.timeline.pkl
23
24 NOTE: .csv sample is currently not implemented
25 """
26
27 import sys
28
29 from pyglet.media import instrumentation as ins
30 import fs
31 import mpexceptions
32
33
34 def usage():
35 print(__doc__)
36 sys.exit(1)
37
38
39 def main(sample, output_format):
40 try:
41 pathserv = fs.get_path_info_for_active_session()
42 except mpexceptions.ExceptionUndefinedSamplesDir:
43 print("The env var 'pyglet_mp_samples_dir' is not defined.")
44 return 1
45 except mpexceptions.ExceptionNoSessionIsActive:
46 print("*** Error, no session active.")
47 return 1
48
49 try:
50 save_timeline(pathserv, sample, output_format)
51 except mpexceptions.ExceptionUnknownOutputFormat as ex:
52 print("*** Error, unknown output_format: %s" % output_format)
53 return 0
54
55
56 def save_timeline(pathserv, sample, output_format):
57 dbg_file = pathserv.dbg_filename(sample)
58 recorded_events = fs.pickle_load(dbg_file)
59 tm = ins.TimelineBuilder(recorded_events, events_definition=ins.mp_events)
60 timeline = tm.get_timeline()
61 v = ins.timeline_postprocessing(timeline)
62 if output_format == ".pkl":
63 outfile = pathserv.report_filename(sample, "timeline.pkl", False)
64 fs.pickle_save(v, outfile)
65 elif output_format == ".csv":
66 outfile = pathserv.report_filename(sample, "timeline.csv", False)
67 #? todo: investigate packing multiple tables
68 raise NotImplemented
69 else:
70 raise mpexceptions.ExceptionUnknownOutputFormat(output_format)
71
72
73 def sysargs_to_mainargs():
74 """builds main args from sys.argv"""
75 if len(sys.argv) < 2:
76 usage()
77 if sys.argv[1].startswith("--"):
78 a = sys.argv.pop(1)
79 if a.startswith("--help"):
80 usage()
81 else:
82 print("Error unknown option:", a)
83 usage()
84
85 if len(sys.argv) < 2:
86 print("*** Error, missing argument.\n")
87 usage()
88 sample = sys.argv.pop(1)
89
90 output_format = ".pkl"
91 if len(sys.argv) > 1:
92 output_format = sys.argv.pop(1)
93
94 return sample, output_format
95
96 if __name__ == '__main__':
97 sample, output_format = sysargs_to_mainargs()
98 main(sample, output_format)