Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4550766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:32:30+00:00 2026-05-21T16:32:30+00:00

Hi I am trying to get a video duration and insert in into the

  • 0

Hi
I am trying to get a video duration and insert in into the database with the video.
But now I am working with extracting video duration using ffmpeg.
I am working on this for past 1 week.
I am able to make this work in linux.
But in windows its just not able to print the duration.
Here is the code.

use strict;
use warnings;
use IPC::Open3;

my @list = glob('*.mp3 *.mp4 *.mpg *.aac *.midi *m3u *.mpa *.dat *.avi');

foreach my $song (@list){

print "$song \n";

my $filename = $song;

my %videoInfo = videoInfo($filename);
print "duration: " . $videoInfo{'duration'}. "\n";
print "durationsecs: " . $videoInfo{'durationsecs'}. "\n\n";

}

sub videoInfo {

# ffmpeg command

my $ffmpeg = 'C:\ffmpeg.exe';



my %finfo = (

              'duration'     => "00:00:00.00",
              'durationsecs'  => "0"
);

my $file = shift;



# escaping characters

$file =~ s/(\W)/$1/g;



open3( "nul", "nul", \*ERPH, "$ffmpeg -i $file" ) or die "can't run $ffmpeg\n";

my @res = <ERPH>;

foreach (@res) {



     #duration

    if (m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])!) {

        $finfo{'duration'} = $1;

    }

 }


my $tenths  = substr( $finfo{'duration'}, 9, 2 );


my $seconds = substr( $finfo{'duration'}, 6, 2 );

my $minutes = substr( $finfo{'duration'}, 3, 2 );

my $hours   = substr( $finfo{'duration'}, 0, 2 );

$finfo{'durationsecs'} = ( $tenths * .01 ) + $seconds + ( $minutes * 60 ) + ( $hours * 360 );

return %finfo;
}

I installed ffmpeg in C:\ and given the path.

ffmpeg is working fine and is displaying bitrate, codec etc etc ( Here I have removed it since I only need Duration) But its jus not printing any duration, Its just printing 00:00:00.00.

I suspect its the search problem in the array.

Please help me in getting through this..

Here is the ouput when I run ffmpeg from command prompt

C:\>ffmpeg.exe -i cisco1.flv
FFmpeg version Sherpya-r10707, Copyright (c) 2000-2007 Fabrice Bellard, et al.
libavutil version: 49.5.0
libavcodec version: 51.45.0
libavformat version: 51.14.0
built on Oct 11 2007 06:25:25, gcc: 4.2.1 [Sherpya]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cisco1.flv':
Duration: 00:08:37.0, start: 0.000000, bitrate: 421 kb/s
Stream #0.0(und): Audio: mpeg4aac, 44100 Hz, stereo
Stream #0.1(und): Video: h264, yuv420p, 960x720, 29.97 fps(r)
Must supply at least one output file

Here you can see the duration is fine.

If I add a

print;

Statement in the above code below line

foreach (@res) {

It will display the same ffmpeg output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:32:31+00:00Added an answer on May 21, 2026 at 4:32 pm

    You match with:

    if (m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])!) {
    

    But the output is:

    Duration: 00:08:37.0, start: 0.000000, bitrate: 421 kb/s
    

    Notice that there is only one digit after the ..

    Try:

    if (m!Duration:\s+([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9]?)!) {
    

    It will match if there is one or two digits after the . (and you should escape . in the regular expression, otherwise it matches any single character).

    $ cat input
    FFmpeg version Sherpya-r10707, Copyright (c) 2000-2007 Fabrice Bellard, et al.
    libavutil version: 49.5.0
    libavcodec version: 51.45.0
    libavformat version: 51.14.0
    built on Oct 11 2007 06:25:25, gcc: 4.2.1 [Sherpya]
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'cisco1.flv':
    Duration: 00:08:37.0, start: 0.000000, bitrate: 421 kb/s
    Stream #0.0(und): Audio: mpeg4aac, 44100 Hz, stereo
    Stream #0.1(und): Video: h264, yuv420p, 960x720, 29.97 fps(r)
    Must supply at least one output file
    $ cat input | perl -ne 'if (m!Duration:\s+([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9][0-9]?)!) { print $1, "\n"; }'
    00:08:37.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the comment count for a video entry but this
I'm trying to get some blocks of colour overlayed/burnt into video with ffmpeg. A
I am trying to get an HTML 5 video to play using WebView, but
I'm trying to get ffmpeg to encode several individual JPEG images into a video
I'm trying to get video thumbnails from Vimeo, but for some reason, I cannot
I'm working with PyQt and trying to get video from a webcam to play
I'm trying to get the video data from this youtube playlist feed and add
I'm trying to get the percentage of each video I have in my database
I'm trying to get a video list w/ thumbnails working with Fancybox - the
I'm trying to get the RTSP video stream play in my Android App using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.