Jump to content

issue with offset


nudl3s

Recommended Posts

Hello all, I dont know why I'm getting this error with calculating the duration for the video, everything works fine with uploading, file is going in my database and folder, the duration of my video is ok.

 

http://prnt.sc/e59i4f

 

here is my code:

 // video duration
            ob_start();

            passthru("ffmpeg -i $tmp 2>&1");
            $duration = ob_get_contents();
            ob_end_clean();

            $search='/Duration: (.*?)[.]/';
            $duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
//error is on this line botom
            $duration = $matches[1][0];

​//error is on this line botom
            list($hours, $mins, $secs) = split('[:]', $duration);

            //echo "Hours: ".$hours." Minutes: ".$mins." Seconds: ".$secs;
            $duration=$hours.':'.$mins.':'.$secs;
            
            
Link to comment
Share on other sites

Do

var_dump($matches);
to see what $matches actually looks like.

 

It returns me : "array(0) { } "

 

 I worked on that before weeks and It was working fine, I have some videos I added then and they have duration time. But now when I try to add some file it returns me duration 00:00:00.

Link to comment
Share on other sites

You should consider using a proper FFmpeg API (like this one) instead of scraping the data from the shell:

$ffprobe = FFMpeg\FFProbe::create();
$duration = $ffprobe
    ->format('/path/to/video/mp4') // extracts file informations
    ->get('duration');             // returns the duration property

(taken from the documentation)

 

If you absolutely must use the shell, use the right function. It doesn't make sense to echo the output, catch it and then write it to a variable when you can just write it to a variable:

$duration = shell_exec('ffmpeg -i '.escapeshellarg($tmp).' 2>&1');
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.