Getting flv duration with php

I have a flv file uploaded to a server. I would like to show its duration in the following format of minutes: seconds. Can someone help me with this?

thank

+3
source share
5 answers

Here is my code to capture a frame and generate an image from a video ...

// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
   $total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
   $second = rand(1, ($total - 1));
}
exec($cmd);

// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");

$ The second variable is a random number from 0 to the total duration. and the second exec () is to create an image file from the selected frame.

$ imageOutput is the absolute location of the path to the generated image. for example: /home/ariawan/image-generated.jpg

+4
source

PHP FFMPEG, .. apt-get install php5-ffmpeg

$movie = new ffmepg_movie("path/to/movie.flv");
$duration_in_seconds = $movie->getDuration();

. , FLV ..

+7

getID3 PHP library, PHP - .

.flv , minute:seconds. v. 1.7.9 ( getid3):

<?php

// getId3 library uses deprecated eregi_* functions 
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL ^ E_DEPRECATED);

// just for debugging/sample
header('Content-Type: text/plain');

// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');

// path to your .flv file
$filename = './sample.flv';

$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);

// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds']; 

print chr(10);

// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
+3

php ffmpeg .

    $cmd = "ffmpeg -i " . $videoPath . " 2>&1";
    if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
        $total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
    }
    exec($cmd);

print_r() $time . , ffmpeg . , .

+2

. FLV . , . , , - .

$cmd = "ffmpeg -i /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.flv -f image2 -vframes 1 -ss 00:00:01 -y -s 100x100 /home/web1/wpmu.site.com/htdocs/wp-content/blogs.dir/7/files/2010/10/4973_3.png";

exec($cmd, $output, $return);

I included it in the test.php page. Should it work just refreshing the page correctly? I added the path to the png file. What could be wrong with this?

thank

+1
source

Source: https://habr.com/ru/post/1771426/


All Articles