Date, time, and duration from a video file

question

#1

I need to get the original date and time as well as duration from video files. It looks like the only option to accomplish this right now is via external tools (see here).

But can anyone here point me to the right direction (if at all possible) for how to accomplish this with VideoIO.jl?

Thanks!


#2

Hello Yakir,

Sorry I didn’t answer you in your issue at VideoIO.jl.

I need to get the original date and time as well as duration from video files

It is actually possible, although not that pretty. But here goes…

When you open a file, you get back an AVInput object. This contains a pointer to an AVFormatContext (stored in an array to mimic the original C struct). The AVFormatContext struct contains a duration field (see here) and a start_time_realtime field (see here).

Duration is stored in terms of 1 / AV_TIME_BASE, so you have to divide by AV_TIME_BASE to get the time in seconds.

start_time_realtime is stored in “microseconds since the Unix epoch (00:00 1st January 1970)” (from the documentation) which is pretty standard. If this isn’t stored in the video, start_time_realtime has the value AV_NOPTS_VALUE.

In code, this would look something like this:

v = VideoIO.testvideo("annie_oakley")
fc = unsafe_load(v.apFormatContext[1])
duration = fc.duration / VideoIO.AV_TIME_BASE
start_time_realtime = fc.start_time_realtime
no_start_time = (start_time_realtime == VideoIO.AV_NOPTS_VALUE)

println("Duration: $duration seconds")
if no_start_time
    println("Start time not available")
else
    println("start_time_realtime: $start_time_realtime")
end

Output:

Duration: 24.2242 seconds
Start time not available

If you wanted to provide a better interface for this in VideoIO.jl, a PR would be very welcome!

(Also note that VideoIO.jl is broken for actually reading videos for ffmpeg versions after 3.1, although I finally figured out a fix yesterday.)

Best,
Kevin