Hướng dẫn get video duration ffmpeg php - lấy thời lượng video ffmpeg php

Khi tôi cố gắng có được thời lượng của một video bằng cách sử dụng trình bao bọc PHP-FFMPEG và FFProbe, tôi nhận được một đối tượng lớn thay vì chỉ thời lượng.

$ffprobe = FFMpeg\FFProbe::create();
    $ffprobe->format($this->videoFile)
            ->get('duration'); 

$ this-> videofile là /home/admin/lem

Vì vậy, nó trỏ đến tệp bên phải và thời lượng được liệt kê trong đối tượng khổng lồ xuống

[[-show_format-/home/admin/web/admin.simplewebevents.com/public_html/cron/649652027.mp4][1]] => Array
                    (
                        [0] => FFMpeg\FFProbe\DataMapping\Format Object
                            (
                                [properties:FFMpeg\FFProbe\DataMapping\AbstractData:private] => Array
                                    (
                                        [filename] => /home/admin/web/admin.simplewebevents.com/public_html/cron/649652027.mp4
                                        [nb_streams] => 2
                                        [nb_programs] => 0
                                        [format_name] => mov,mp4,m4a,3gp,3g2,mj2
                                        [format_long_name] => QuickTime / MOV
                                        [start_time] => 0.000000
                                        [duration] => 5736.833333
                                        [size] => 668381267
                                        [bit_rate] => 932056
                                        [probe_score] => 100
                                        [tags] => Array
                                            (
                                                [major_brand] => mp42
                                                [minor_version] => 0
                                                [compatible_brands] => mp42mp41isomavc1
                                                [creation_time] => 2016-12-04 18:25:58
                                            )

                                    )

                            )

                        [1] => 
                    )

            )

Nhưng rõ ràng -> get ('thời lượng') không trả về thời lượng.

Tôi cũng đã thử với

$ffprobe
->streams($this->videoFile) // extracts streams informations
->videos()                      // filters video streams
->first()                       // returns the first video stream
->get('duration');

Tệp này chứa văn bản unicode hai chiều có thể được giải thích hoặc biên dịch khác với những gì xuất hiện dưới đây. Để xem xét, hãy mở tệp trong một trình soạn thảo cho thấy các ký tự Unicode ẩn. Tìm hiểu thêm về các ký tự unicode hai chiều

$ file = 'trunkmonkey_rescue.mov';file = 'TrunkMonkey_Rescue.mov';
$ result = shell_exec ('ffmpeg -i'. escapeshellcmd ($ file). '2> & 1');result = shell_exec('ffmpeg -i ' . escapeshellcmd($file) . ' 2>&1');
preg_match('/(?'/(?<=Duration: )(\d{2}:\d{2}:\d{2})\.\d{2}/', $result, $match);
print_r ($ match);$match);
/*
Mảng
.
[0] => 00: 00: 30,23
)
*/
$ Time = Explode (':', $ Match [1]) + mảng (00,00,00);time = explode(':', $match[1]) + array(00,00,00);
print_r ($ thời gian);$time);
$ một nửa = sàn (tham gia ($ thời gian) / 2);half = floor(join($time) / 2);
$ một nửa = tham gia (':', str_split (str_pad ($ một nửa, 6, 0, str_pad_left), 2));half = join(':', str_split(str_pad($half, 6, 0, STR_PAD_LEFT), 2));
In một nửa. "\N";$half . "\n";
$ video = __dir__. '/'. Tệp $;video = __DIR__ . '/' . $file;
$ Hình thu nhỏ = __dir__. '/'. Tệp $. '.jpg';thumbnail = __DIR__ . '/'. $file . '.jpg';
// -ss = tìm kiếm vị trí thời gian đã cho trong giây.
// -an = vô hiệu hóa ghi âm
// -R FPS = Đặt tốc độ khung hình
$ result = shell_exec ("ffmpeg -i $ video -deinterlace -an -ss $ nửa -t $ một nửa -r 1 -Y -VCODECresult = shell_exec("ffmpeg -i $video -deinterlace -an -ss $half -t $half -r 1 -y -vcodec mjpeg -f mjpeg $thumbnail 2>&1");
// Ngay cả khi thất bại, kết quả $ sẽ là một chuỗi của tất cả các đầu ra để tôi không nghĩ điều này là cần thiết
if (! $ result)( ! $result)
{
ThrownewException ('Lỗi tạo hình thu nhỏ video'); new Exception('Error creating video thumbnail');
}
In $ Kết quả. "\ n \ n";$result . "\n\n";

Làm thế nào để có được thời lượng video với FFMPEG trong PHP?

$ Video_File = $ getId3-> Phân tích ('Path-to-Your-Video');// Nhận thời lượng tính theo chuỗi, ví dụ: 4:37 (phút: giây) $ fitor_string = $ video_file ['playtime_string'];// Nhận thời lượng tính bằng giây, ví dụ: 277 (giây) $ foruration_seconds = $ video_file ['playtime_seconds'];

Làm cách nào để có thời lượng FFMPEG?

Nhận thời lượng bằng cách giải mã Bạn cũng có thể sử dụng FFMPEG để có thời lượng bằng cách giải mã hoàn toàn tệp.Null Muxer được sử dụng để không có tệp đầu ra được tạo.Tham khảo thời gian = trong dòng tiếp theo của đầu ra bảng điều khiển.Trong ví dụ này, đầu vào có thời lượng 00: 57: 28.87.use ffmpeg to get the duration by fully decoding the file. The null muxer is used so no output file is created. Refer to time= in the next-to-last line of the console output. In this example the input has a duration of 00:57:28.87 .