Skip to content

Instantly share code, notes, and snippets.

@mat127
Last active November 24, 2023 09:41
Show Gist options
  • Save mat127/40537494a67dbe5b23260afd83a3eb7d to your computer and use it in GitHub Desktop.
Save mat127/40537494a67dbe5b23260afd83a3eb7d to your computer and use it in GitHub Desktop.
Timestamp SEI (MISB ST 604) parser
#!/bin/awk -f
#
# Parses the ffmpeg trace_headers output and displays timestamp SEI (MISB ST 0604)
# contents in a readable format:
#
# ${ts.identifier}: ${datetime.of.timestamp}: ${timestamp.value}
# cf848278-ee23-306c-9265-e8fef22fb8b8: Fri Nov 24 09:40:48 UTC 2023 : 1700818848602427904
#
# Expects the H.265 SEI i.e. nano precision timestamps. For the H.264 (microseconds precision)
# update the timestamp dividing and identifier dump.
#
# Example:
#
# ffmpeg -i udp://127.0.0.1:5050 -c:v copy -bsf:v trace_headers -f null - 2>&1 | ./sei.awk
#
function timestamp_to_date(timestamp) {
command = "date -d @" timestamp;
command | getline date_string;
close(command);
return date_string;
}
BEGIN {
user_data_line = 64
}
user_data_line < 64 {
user_data_line++
}
$4 == "User" && $5 == "Data" && $6 == "Unregistered" {
user_data_line = 0
identifier = ""
timestamp = "0x"
}
user_data_line > 0 && user_data_line < 17 {
char = sprintf("%02x", $8)
identifier = identifier char
if (user_data_line == 4 || user_data_line == 6 || user_data_line == 8 || user_data_line == 10) {
identifier = identifier "-"
}
}
user_data_line > 17 && user_data_line < 29 && user_data_line != 20 && user_data_line != 23 && user_data_line != 26 {
char = sprintf("%02x", $8)
timestamp = timestamp char
}
user_data_line == 28 {
timestamp = strtonum(timestamp)
ts = int(timestamp / 1000000000)
print identifier ": " timestamp_to_date(ts) " : " timestamp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment