Is there any way I can get the playing time of a movie file?


#1

The filesystem function stat() does not provide the length of a movie file in terms of playing time. Is there any other function that provides that information?

Thanks


#2

AFAIK Julia does not have support for that. There has to be program that would parse the headers of the movie file to get that information. The program of choice that does that on a command in is ffmpeg or ffprobe. The following snippet would allow you to do that in Julia by invoking an external program call. You need to have ffmpeg installed on your system for this work

function getDuration(vid_filename)
       p=Pipe()
       run(pipeline(`ffprobe -i  $vid_filename`,stderr=p))
       close(p.in)
        duration=matchall(r"(\d{2}:\d{2}:\d{2}.\d{2})"
                            ,readstring(pipeline(p,`grep Duration`)))[1]
end

Date, time, and duration from a video file
#3

Thank you so much for the code. I was trying it on my Windows 7 machine but could not make it work.


#4

This one works.

function getDuration(vid_filename)
   return matchall(r"(\d{2}:\d{2}:\d{2}.\d{2})",readstring(pipeline(`ffprobe -i  $vid_filename`,stderr=`grep Duration`)))[1]
end

#5

Very nice and succinct. Didn’t know it is possible to do it in a one liner.