nudl3s Posted February 6, 2017 Share Posted February 6, 2017 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; Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/ Share on other sites More sharing options...
requinix Posted February 6, 2017 Share Posted February 6, 2017 Do var_dump($matches);to see what $matches actually looks like. Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542369 Share on other sites More sharing options...
nudl3s Posted February 6, 2017 Author Share Posted February 6, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542371 Share on other sites More sharing options...
requinix Posted February 6, 2017 Share Posted February 6, 2017 Apparently your regex didn't match. Do you think that maybe your next step should be to see what's in $duration? (The first value it gets, to be specific.) Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542373 Share on other sites More sharing options...
Jacques1 Posted February 6, 2017 Share Posted February 6, 2017 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'); Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542375 Share on other sites More sharing options...
nudl3s Posted February 7, 2017 Author Share Posted February 7, 2017 OMG little mistake here passthru("ffmpeg -i $tmp 2>&1"); replace ffmpeg with $ffmpeg (my path to ffmpeg) .... Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542399 Share on other sites More sharing options...
Jacques1 Posted February 7, 2017 Share Posted February 7, 2017 You are aware of shell injections, yes? Quote Link to comment https://forums.phpfreaks.com/topic/303113-issue-with-offset/#findComment-1542405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.