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

**URL:** https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894
**Category:** General Usage
**Created:** [March 27, 2017, 4:16am UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894 "2017-03-27T04:16:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)
#### Post date: [March 27, 2017, 4:16am UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894/1 "2017-03-27T04:16:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mbeltagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbeltagy/32/130_2.png) [@mbeltagy](https://discourse.julialang.org/u/mbeltagy)
#### Post date: [March 27, 2017, 3:31pm UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894/2 "2017-03-27T15:31:55Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

### Author: ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)
#### Post date: [March 28, 2017, 2:35pm UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894/3 "2017-03-28T14:35:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mwsohn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwsohn/32/2696_2.png) [@mwsohn](https://discourse.julialang.org/u/mwsohn)
#### Post date: [April 19, 2017, 2:00am UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894/4 "2017-04-19T02:00:16Z")

</div>

This one works.

```julia
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

```

---

<div class="post-metadata">

### Author: ![mbeltagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbeltagy/32/130_2.png) [@mbeltagy](https://discourse.julialang.org/u/mbeltagy)
#### Post date: [April 20, 2017, 2:05pm UTC](https://discourse.julialang.org/t/is-there-any-way-i-can-get-the-playing-time-of-a-movie-file/2894/5 "2017-04-20T14:05:35Z")

</div>

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