hai friends
I have uploaded the video file to server .we need to get the total time of playing file duration and store the values to database. how can i get the total time for uploaded video file?

Please any one send me any idea.

Thanks
__________________
Thanks
Vssp

Dani AI

Generated

Short answer: you need either an external metadata tool or a PHP media parser. was correct that plain PHP does not reliably parse multimedia containers; two practical choices are (a) call the FFmpeg toolset (use ffprobe for metadata) or (b) use a pure-PHP library such as getID3. Both are widely used in production and are easy to store to your DB once you have the duration. (ffprobe docs, getID3). (ffmpeg.org)

If you can run binaries on the server, ffprobe is the cleanest: it prints the duration in seconds so you can cast to float and save. This is usually more robust than scraping ffmpeg -i output (which some replies in this thread do). From PHP call ffprobe with a properly escaped filename, capture the output, trim and convert to numeric, then insert to the DB. Make sure the binary is reachable (use full path) and that exec/shell_exec are allowed on your host; use escapeshellarg to avoid injection. (ffprobe docs, escapeshellarg, php.ini disable_functions). (ffmpeg.org)

If you cannot execute external programs (shared hosting), use getID3 — a pure-PHP parser that returns playtime_seconds / playtime_string after analyzing a local file. It parses many common formats without calling an external binary and is convenient for uploads. MediaInfo is another CLI/library alternative if you prefer its output format. (getID3 demo, MediaInfo CLI). (getid3.org)

Troubleshooting notes based on common thread issues: if duration is missing or zero the file may be incomplete or lack container metadata (e.g., MP4’s moov atom at the end). In that case remuxing or running ffmpeg with -movflags +faststart (or repairing the file) fixes metadata so duration can be read. Also check file permissions, PHP timeouts, and that you parse the returned string to a float before storing. (ffmpeg/faststart notes). (stackoverflow.com)

Recommended Answers

All 4 Replies

Any one replay my issue

You can't do that with php alone without any external software, for example ffmpeg.

Hello VSSP.
I have solution to your problem.
Get
Now Extract it to your folder.
The Following Code will show you how you can get duration of Video file.
That one worked for me.

$file= "127808825101 Track 1.wma";
ob_start();

passthru("ffmpeg.exe -i \"{$file}\" 2>&1");  //path to your ffmpeg.exe
$duration = ob_get_contents();
ob_end_clean();

//the full output:
//echo $duration."<br/>";

$search='/Duration: (.*?)[.]/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
$duration = $matches[1][0];

//i suppose that our video hasn't duration of a day+ :
list($hours, $mins, $secs) = split('[:]', $duration);

echo "Hours: ".$hours." Minutes: ".$mins." Seconds: ".$secs;

hai friends
I have uploaded the video file to server .we need to get the total time of playing file duration and store the values to database. how can i get the total time for uploaded video file?

Please any one send me any idea.

Thanks
__________________
Thanks
Vssp


View your answer to your post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.