PHP code example of baohanddd / m3u8

1. Go to this page and download the library: Download baohanddd/m3u8 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

baohanddd / m3u8 example snippets


# load m3u8 file from url...
$filename = new Filename("https://video3.futurelink.live/record/aliyun/en2/a.m3u8");
$m3u8 = new M3U8($filename);
$m3u8->setFFMPEG('/data/bin/ffmpeg');   // Optional,default bin path is /usr/bin/ffmpeg
$m3u8->setSavePath("/oss/video3");      // Optional, default save path is /tmp
$m3u8->addClippableDomain('video3.futurelink.live');
$m3u8->addClippableDomain('video2.futurelink.live');
$m3u8->setIndexSaveHandler(function(string $m3u8Name, string $content): string {
    $path = "/tmp/{$m3u8Name}";
    $fp = fopen($path, 'wb');
    fwrite($fp, $content);
    fclose($fp);
    return $path;
});

# drop clips before 10 seconds and after 200 seconds...
$start = 10.0;
$end = 200.0;
$m3u8->load($filename);
$m3u8->getTimeline()->clip($start, $end)->cut();

# save clips between start and end...
$start = 10.0;
$end = 200.0;
$m3u8->load($filename);
$m3u8->getTimeline()->merge($start, $end)->cut();