diff --git a/PyScripts/gstreamerAutotest.py b/PyScripts/gstreamerAutotest.py new file mode 100644 index 0000000..f9355bc --- /dev/null +++ b/PyScripts/gstreamerAutotest.py @@ -0,0 +1,92 @@ +#!/usr/bin/python +from itertools import product + +options = { + "x264enc": { + "bitrate" : ["10000", "20000", "5000"], + "speed-preset" : ["ultrafast", "fast", "medium"], + "tune": ["zerolatency"], + "slices-threads": ["true", "false"], + "b-adapt": ["true", "false"], + "rc-lookahead": ["40", "0"], + "ref": ["3", "0"] + + }, + "nvh264enc" : { + "bitrate" : ["10000", "20000", "5000"], + "preset" : ["4", "5", "1"], + "rc-lookahead" : ["0"], + "rc-mode" : ["2", "0", "5"], + "zerolatency": ["true", "false"], + + }, + "nvv4l2h264enc": { + "bitrate" : ["10000000", "20000000", "5000000"], + "profile": ["0", "1", "2"], + "preset-id": ["1", "2", "3"], + "control-id": ["1", "2"], + "tuning-info-id": ["4", "2"] + } +} + +videos = [""] + +testsource = "videotestsrc pattern=smpte" +videosrc = ["filesrc location=", "! qtdemux ! h264parse ! avdec_h264"] + +psnr_check = { + "x264enc": "-pixel_format yuv420p -color_range pc", + "nvh264enc": "-pixel_format nv12 -color_range tv", + "nvv4l2h264enc": "-pixel_format yuv420p -color_range tv" +} + +formats = { + "x264enc" : "I420", + "nvh264enc" : "NV12", + "nvv4l2h264enc": "I420" +} + +profiles = ["baseline", "main"] + +def makeVideoSrc(idx): + return videosrc[0] + videos[idx] + videosrc[1] + +def generateEncoderStrings(): + global options + result = dict() + for encoder, value in options.items(): + result[encoder] = generate_combinations(value) + return result + +def generate_combinations(config_dict): + """ + Generate all combinations of values from a configuration dictionary. + + Args: + config_dict (dict): Dictionary with parameter names as keys and lists of values as values + + Returns: + list: List of strings containing all parameter combinations + """ + combinations = [] + + # Get the keys and values in consistent order + keys = list(config_dict.keys()) + value_lists = [config_dict[key] for key in keys] + + # Generate all combinations using itertools.product + for combo in product(*value_lists): + # Create a list of key=value strings + param_strings = [] + for key, value in zip(keys, combo): + param_strings.append(f"{key}={value}") + + # Join all parameter strings with space separator + combinations.append(" ".join(param_strings)) + + return combinations + +def generateRecordString(options, ): + pass + +print(len(generateEncoderStrings()[""])) \ No newline at end of file diff --git a/PyScripts/latencyParse.py b/PyScripts/latencyParse.py new file mode 100644 index 0000000..0db57e5 --- /dev/null +++ b/PyScripts/latencyParse.py @@ -0,0 +1,85 @@ +#!/usr/bin/python3 +import pandas as pd +import numpy as np +# Idea is next: +# on set of experiments we are calculating all latency information -> each element avg, std, max numbers, total is not calculated, because it requires +# additional parsing for parallel branches (from tee) +# Ideally we would write data to table + +idxCache = dict() + +def findWord(words, wordToSearch): + global idxCache + if wordToSearch in idxCache: + for idx in idxCache[wordToSearch]: + if words[idx].startswith(wordToSearch): + return words[idx] + for word in words: + if word.startswith(wordToSearch): + idx = words.index(word) + if not wordToSearch in idxCache: + idxCache[wordToSearch] = [] + idxCache[wordToSearch].append(idx) + return words[idx] + return "" + +# taken with love from GStreamerLatencyPlotter implementation +def readAndParse(filename): + result = dict() + + with open(filename, "r") as latencyFile: + lines = latencyFile.readlines() + for line in lines: + if line.find("new format string") != -1: + continue + words = line.split() + if not words[len(words) - 1].startswith("ts="): + continue + + def findAndRemove(wordToSearch): + res = findWord(words, wordToSearch) + res = res[res.find(")") + 1:len(res) - 1] + return res + + name = findWord(words, "element=(string)") + if name == "": + name = findWord(words, "src-element=(string)") + if name == "": + continue + src = findAndRemove("src=(string)") + name = name[name.find(")") + 1:len(name) - 1] + if name not in result: + result[name] = {"latency":[], "ts":[]} + + timeWord = findWord(words, "time=(guint64)") + tsWord = findWord(words, "ts=(guint64)") + result[name]["latency"].append(int(timeWord[14:len(timeWord) - 1])/1e6) # time=(guint64)=14 + result[name]["ts"].append(int(tsWord[12:len(tsWord) - 1])/1e9) # ts=(guint64)=12 + return result + + +def getLatencyTable(filename): + parsed = readAndParse(filename) + df = pd.DataFrame(parsed) + print(df) + latency_row = df.loc['latency'] + ts_list = df.loc['ts'] + + avg_latency = latency_row.apply(np.mean) + median_latency = latency_row.apply(np.median) + max_latency = latency_row.apply(np.max) + std_latency = latency_row.apply(np.std) + dt_max_latency = dict() + min_timestamp = ts_list.apply(np.min) + + for column in df.columns: + max_index = np.argmax(latency_row[column]) + dt = ts_list[column][max_index] - min_timestamp.min() + dt_max_latency[column] = dt + + df_dt_max = pd.Series(dt_max_latency) + resultDf = pd.concat([df_dt_max, max_latency, avg_latency, median_latency, std_latency], axis=1) + resultDf.columns = ['dTmax', 'max', 'avg', 'median', 'std'] + print(resultDf) + +getLatencyTable("latency_traces-x264enc-big-pr-main.log") \ No newline at end of file