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

  • Home
  • SEARCH
  • 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 5992517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:32:35+00:00 2026-05-22T23:32:35+00:00

While i try to get length of a flv video file i get 0

  • 0

While i try to get length of a flv video file i get 0 second where as it only happens with some videos, else my function works fine.

below is my code.

<?php
function mbmGetFLVDuration($file){
    // read file
  if (file_exists($file)){
    $handle = fopen($file, "r");
    $contents = fread($handle, filesize($file));
    fclose($handle);
    //
    if (strlen($contents) > 3){
      if (substr($contents,0,3) == "FLV"){
        $taglen = hexdec(bin2hex(substr($contents,strlen($contents)-3)));
        if (strlen($contents) > $taglen){
          $duration = hexdec(bin2hex(substr($contents,strlen($contents)-$taglen,3)))  ;
          return $duration;
        }
      }
    }
  }
}
// not working video file
$result = ceil(mbmGetFLVDuration('not_working_copy.flv')/1000);
// working video file
//$result = ceil(mbmGetFLVDuration('working_copy.flv')/1000);
echo date('H:i:s',mktime(0,0,$result))
?>

i have attached both working and not working flv video in link below:

working video:
http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/working_copy.flv

not working video:
http://blog.developeronhire.com/wp-content/uploads/downloads/2011/06/not_working_copy.flv

any idea will be appreciated.

Thank you

  • 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-22T23:32:36+00:00Added an answer on May 22, 2026 at 11:32 pm

    This type of problem occurs when the meta information of a video is partially or fully corrputed. In order to resolve this problem, use FFMPEG commnad line tool, to repair such corrupted file while uploading. below is a code snippet that extracts the video duration using FFMPEG.

    <?php
         ob_start();
         passthru("ffmpeg -i working_copy.flv  2>&1");
         $duration = ob_get_contents();
         $full = ob_get_contents();
         ob_end_clean();
         $search = "/duration.*?([0-9]{1,})/";
         print_r($duration);
         $duration = preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
         print_r('<pre>');
     print_r($matches[1][0]);
     print_r($full);
    ?>
    

    to download FFMPEG go to http://www.ffmpeg.org

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a delegate function that can 'wrap' some while/try/catch code around
try { if (myBoolean) { while (true) ; } else { System.exit(1); } }
Whenever I try to upload a sound file IO get the error The connection
I get Length of the data to decrypt is invalid. exception when i try
Here is my class where I try to get into a JSONArray some data
For some reason, when I try to run this code, all I get is
Eclipse always gives me this compilation error when I try to get the length
trying to get length of file which from local storage. File exists 100% (because
I have some trouble while try using broadcast receiver. Target: I have three app
Anytime I try to serialize a file I get the error: FileNotFound. Not sure

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.