Extract timestamps without creating a file

Is it possible to print the timestamps instead of creating a file?

Currently, I extract the timestamps like this:

mkvextract input.mkv timestamps_v2 1:ts-track1.txt

I would like extract the timestamps like this or any other way that would print the result

mkvextract input.mkv timestamps_v2 1:stdout

Welcome!

mkvextract doesn’t have a specifier for stdout for timestamps and other things for which there are potentially multiples to extract simultaneously (tracks, attachments).

If you’re on Linux there’s a workaround, though: you can use the pseudo-file /dev/stdout:

[0 mosu@sweet-chili ~/prog/video/data] mkvextract v.mkv timestamps_v2 0:/dev/stdout
# timestamp format v2
0
42
83
125
167
209
250
292
334
…

This might work on other Unix-like OS, too.

Note that you’ll still get the progress output on stdout.

The best way to go about things is likely not to use mkvextract but mkvinfo with its summary mode. It’s turned on with the option -s and outputs one line per frame found. This line includes the timestamp as well as the track number, which is a distinctive advantage over mkvextract’s timestamps if you want to process multiple tracks simultaneously. mkvinfo writes to stdout by default.

[0 mosu@sweet-chili ~/prog/video/data] mkvinfo -s v.mkv | head
Track 1: video, codec ID: V_MPEG4/ISO/AVC (H.264 profile: Main @L5.1), mkvmerge/mkvextract track ID: 0, language: und, language (IETF BCP 47): und, pixel width: 640, pixel height: 352, display width: 640, display height: 352, default duration: 41.708ms (23.976 frames/fields per second for a video track)
Track 2: audio, codec ID: A_AAC, mkvmerge/mkvextract track ID: 1, language: und, default duration: 21.333ms (46.875 frames/fields per second for a video track), language (IETF BCP 47): und, sampling freq: 48000, channels: 2
I frame, track 1, timestamp 00:00:00.000000000, size 12973, adler 0xc59f1503
I frame, track 2, timestamp 00:00:00.000000000, size 502, adler 0x379d04bd
I frame, track 2, timestamp 00:00:00.000000000, size 450, adler 0x2ebbd8e2
I frame, track 2, timestamp 00:00:00.000000000, size 399, adler 0x73f3b7c3
I frame, track 2, timestamp 00:00:00.000000000, size 410, adler 0x8695b75c
I frame, track 2, timestamp 00:00:00.000000000, size 453, adler 0x5c84cf25
I frame, track 2, timestamp 00:00:00.000000000, size 399, adler 0xaf13ba6a
I frame, track 2, timestamp 00:00:00.000000000, size 435, adler 0xd7b8d001
…

I need a solution that is cross-platform. I invoke mkvextract from a python script.

I will think about it, but it is not possible to print the result in json or xml. Because of that, I need to create a parser which seems a bit overkill for my needs.

Given current capabilities, the easiest, most cross-platform method is to let mkvextract write into a temporary file, then.

1 Like