Quantcast

how to get video duration?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to get video duration?

Engine-3
   
            Hi ,

I am making a program using ffmpeg.exe in vb.net....
I need to get durations of video files .... in the forum i was directed to use "-i videopath"
and find the duration within the text but it didn't work most of the time ...

is there a command that gives duration directly?



     
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get video duration?

Stefano Sabatini
On date Tuesday 2010-01-05 16:01:44 -0800, Engine encoded:
>    
>             Hi ,
>
> I am making a program using ffmpeg.exe in vb.net....
> I need to get durations of video files .... in the forum i was directed to use "-i videopath"
> and find the duration within the text but it didn't work most of the time ...
>
> is there a command that gives duration directly?

You can try with ffprobe -read_frames, but I cannot guarantee on the
accuracy of the result (I'm working on ffprobe integration in FFmpeg,
hopefully many of the current features may improve, patches are
welcome as always).

Regards.
--
ffmpeg-user random tip #19
X11 session recording with ffmpeg:
ffmpeg -f oss -i /dev/audio -f x11grab -s $WIDTHx$HEIGHT -r 5 -i :0.0 \
    x11-session.avi
Use xdpyinfo to get WIDTH and HEIGHT values.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get video duration?

Jan Stary
In reply to this post by Engine-3
On Jan 05 16:01:44, Engine wrote:
>    
>             Hi ,
>
> I am making a program using ffmpeg.exe in vb.net....
> I need to get durations of video files .... in the forum i was directed to use "-i videopath"
> and find the duration within the text but it didn't work most of the time ...

$ ffmpeg -i file.avi 2>&1 | grep Duration
  Duration: 02:05:03.33, start: 0.000000, bitrate: 1118 kb/s

Give me an example where this "doesn't work"
(whatevere that means).


> is there a command that gives duration directly?

Is "02:05:03.33" direct enough?

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get video duration?

Phil Rhodes
>$ ffmpeg -i file.avi 2>&1 | grep Duration
>  Duration: 02:05:03.33, start: 0.000000, bitrate: 1118 kb/s

The problem with all this stuff is that you can end up scanning over the
whole file in order to get its precise duration (especially if you want a
frame count). In theory, AVI does have a "duration in frames" header, but
this is frequently not correctly set.

P

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get video duration?

Jan Stary
On Jan 06 08:37:16, Phil Rhodes wrote:
>> $ ffmpeg -i file.avi 2>&1 | grep Duration
>>  Duration: 02:05:03.33, start: 0.000000, bitrate: 1118 kb/s
>
> The problem with all this stuff is that you can end up scanning over the  
> whole file in order to get its precise duration (especially if you want a
> frame count).

"ffmpeg -i file.avi" does of course not read the whole file,
ot just looks at the header. Try it with a 00:00:05 video,
then try it with a 02:30:00 video.

On a relevant note: I am using "ffmpeg -i file.ext" quite
often and it disturbes me a little bit that I am doing something
that from the application's point of view is an error (namely,
not specifying an output file).

How much of an intrusion would it be to change ffmpeg's
behaviour to simply report what "ffmpeg -i" does _without_
considering it an error if an output file is not specified?


> In theory, AVI does have a "duration in frames" header, but
> this is frequently not correctly set.

From a corrupted header you cannot get anything, of course.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to get video duration?

Artur Bodera
In reply to this post by Phil Rhodes
On Wed, Jan 6, 2010 at 9:37 AM, Phil Rhodes <[hidden email]> wrote:
> The problem with all this stuff is that you can end up scanning over the
> whole file in order to get its precise duration (especially if you want a
> frame count). In theory, AVI does have a "duration in frames" header, but
> this is frequently not correctly set.

Just add water :-)

# ffmpeg -y -i VIDEO -vcodec copy -acodec copy -f rawvideo /dev/null

You'll get something like:
frame= 2668 fps=  0 q=-1.0 Lsize=       0kB time=111.24 bitrate=   0.0kbits/s
video:2784kB audio:794kB global headers:0kB muxing overhead -99.999973%

You can use it to extract real (found) frame count and time.
Disclaimer: for really damaged files it could still be inaccurate, but
it's better than headers. For example the header might say the video
is 120s, but the video stream might end before audio stream at 110s.
In such case, you will see that the above method will stop the time=
counter at 110s.

Another option is to decode the video, so you will get the total
number of _DECODABLE_ frames and time:
# ffmpeg -y -i VIDEO -vcodec rawvideo -an -f rawvideo /dev/null

Of course it is much more expensive.


Hope this helps! :)

Arthur.

--

      __
     /.)\   +48 695 600 936
     \(./   [hidden email]
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Loading...