10

I have a project that will need to be able to know the time a video file (such as .mp4, .mov, .mxf etc.) was started (e.g. when record was pressed) and when the video file was ended in seconds since epoch.

So far what I have been doing is finding the File Modified time and using that as the endpoint and then subtracting duration to find the beginning. This works pretty well in some cases but it appears that some cameras don't exactly write/modify files in a linear predictable way so sometimes the start/end times of the video files overlap when clearly you can't be recording 2 files at the same time.

Is there some other method or piece of metadata I could access using say ffprobe (or alternative) in python to accurately determine when the video was started and when it was ended?

8
  • According to: QuickTime File Format Specification, it looks like the "file created" time is not well defined.
    – Rotem
    Jul 25, 2016 at 9:33
  • 1
    Could you provide more context? like in which system this is running? or what tools are you using? The only thing I can think of at the moment is that maybe you could look at the system logs or the camera log (if it's accessible).
    – hecvd
    Jul 27, 2016 at 21:12
  • This is currently running on windows but will need to be able to run on macOS as well. system/camera logs are unavailable. We only have the video files and whatever metadata is stored in them to work with.
    – abagshaw
    Jul 27, 2016 at 21:23
  • As it stands, this is too broad. The behavior of the metadata in each file type, and available in the filesystem, will all depend on: the filesystem type, how it's mounted, the program doing the recording, the format it's saved in, etc. Solving this for a single combination of recorder-filesystem-format might be a better start. Aug 3, 2016 at 14:04
  • 2
    Namely, I think the software used to record is probably the most important piece to this puzzle. You can't get information it doesn't save in the first place. However, perhaps you could use python to control how recording works, and save the information yourself. Aug 3, 2016 at 14:05

4 Answers 4

1

Your best tools are:

ffprobe
mediainfo
exiftool

You can find many types of datestamps in them but I've never tested them for accuracy. If between those tools and filesystem stamps you can't find the proper metadata then you need better tracking at the time of filming. I'm a filmmaker as well as programmer and I can't quite figure out why you would need epoch time but I do know you need better tracking during production.

Try a digital clapboard with a clock, or use a some sort of digital recorder where you can control timestamp creation during recording.

Also, as others have mentioned this question lacks focus. What problem are you trying to solve? I can only think of sync between media sources in which case use some software such as plural eyes.

0

A quick tip is to make use of the system() command from python.

Option# 1:

   $ ffmpeg -i file.flv 2>&1 | grep "Duration"

Option# 2:

   $ mediainfo --Inform="General;%Duration%" [inputfile]
0

If you are running your code on the same system, you can use time library for determining start time and end time of a video.

If you want difference in seconds since epoch, you can use time.time() function.

import time

starttime = time.time()

You can bind this with onclick events using Tkinter

0

Using the time library should solve your problem. Try this:

import time
timer = time.time()
print(timer)

Otherwise, pygame can be very useful with time and formating. It is intended to be for developing games, but precise and effective time features as well.

import pygame, sys
pygame.init()
timer = pygame.time.Clock() " Call after video has begun playback "
timer.tick() " Call onced playback has ended "
video_time = timer.get_time() " Returns previous time amount in milleseconds. "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.