listenlive.cn

是谁来自山川湖海 却囿于昼夜厨房与爱


  • 首页

  • 技术

  • 笔记

  • 杂记

  • 分享

  • 归档

  • 关于

  • 搜索
close

PHP获取mp4和m3u8视频时长的方法

时间: 2022-07-17   |   分类: 笔记     |   阅读: 209 字 ~1分钟

PHP获取mp4视频时长

使用getid3获取mp4视频时长(同样适用于mp3等其他媒体文件)

    $getid3 = new getID3;
    $file = './test.mp4';
    $info = $getid3->analyze($file);
    $playtime_seconds = $info['playtime_seconds'];
    $duration = gmdate("H:i:s", $playtime_seconds); //将秒换算为分钟

PHP获取m3u8视频时长

读取m3u8文件获取视频时长

     $file_url = 'https://example.com/test.m3u8'; //m3u8视频地址
     $vtime = $this->getDuration($file_url); //获取文件时长
     $duration = gmdate("H:i:s", $vtime); //将秒换算为分钟

     function getDuration($file_url) {
         try {
            // 忽略ssl证书验证
            $stream_opts = [
                "ssl" => [
                    "verify_peer" => false,
                    "verify_peer_name" => false,
                ]
            ];
            $res = file_get_contents($file, false, stream_context_create($stream_opts));
        } catch (\ErrorException $e) {
            return 0;
        }
        // preg_match_all("/\EXTINF:(.*?)\,/i", $res, $arr);
        // $res = array_sum($arr[1]);
        preg_match_all('/\d+[.]\d+/', $res, $arr);
        $res = array_sum($arr[0]);
        return (int)$res;
     }

喜欢这篇文章的话 打赏一下吧!

Wechat Alipay

#PHP# #m3u8# #MP4#
Golang与PHP的AES加密解密互转
Harbor的安装配置与使用
  • 文章目录
  • 站点概览
一刀未剪

一刀未剪

Programmer & Architect

GitHub Instagram Weibo Email
70 日志
4 分类
69 标签
工具站
Harbor 在线文档 Quick Reference Linux 命令查询 Mock 模拟数据
友情链接
  • milu杰克
  • 使用getid3获取mp4视频时长(同样适用于mp3等其他媒体文件)
  • 读取m3u8文件获取视频时长
京ICP备17004223号 © 2020 - 2023 listenlive.cn
Powered by - HUGO
Theme by - NexT
访客量 -
0%