SegmentedTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Pbmedia\LaravelFFMpeg\Tests;
  3. use Mockery;
  4. use Pbmedia\LaravelFFMpeg\Media;
  5. use Pbmedia\LaravelFFMpeg\SegmentedExporter;
  6. use Pbmedia\LaravelFFMpeg\SegmentedFilter;
  7. class SegmentedTest extends TestCase
  8. {
  9. public function testFilter()
  10. {
  11. $media = $this->getVideoMedia();
  12. $playlist = 'MyPlaylist.m3u8';
  13. $format = new \FFMpeg\Format\Video\X264;
  14. $exporter = new SegmentedExporter($media);
  15. $exporter->setPlaylistPath($playlist);
  16. $exporter->inFormat($format);
  17. $exporter->setSegmentLength(20);
  18. $filter = $exporter->getFilter();
  19. $this->assertInstanceOf(SegmentedFilter::class, $filter);
  20. $this->assertEquals('./MyPlaylist_1000.m3u8', $filter->getPlaylistPath());
  21. $this->assertEquals(20, $filter->getSegmentLength());
  22. $this->assertEquals($filter->apply($media(), $format), [
  23. '-map',
  24. '0',
  25. '-flags',
  26. '-global_header',
  27. '-f',
  28. 'segment',
  29. '-segment_format',
  30. 'mpeg_ts',
  31. '-segment_list',
  32. './MyPlaylist_1000.m3u8',
  33. '-segment_time',
  34. 20,
  35. ]);
  36. }
  37. public function testExportingASegmented()
  38. {
  39. $file = $this->getVideoMedia()->getFile();
  40. $playlist = 'MyPlaylist.m3u8';
  41. $format = new \FFMpeg\Format\Video\X264;
  42. $media = Mockery::mock(Media::class);
  43. $media->shouldReceive('getFile')->once()->andReturn($file);
  44. $media->shouldReceive('save')->once()->withArgs([
  45. $format, $this->srcDir . '/MyPlaylist_1000_%05d.ts',
  46. ]);
  47. $exporter = new SegmentedExporter($media);
  48. $exporter->setPlaylistPath($playlist);
  49. $exporter->inFormat($format);
  50. $media->shouldReceive('addFilter')->once()->withArgs([
  51. $exporter->getFilter(),
  52. ]);
  53. $exporter->inFormat($format)
  54. ->toDisk('local')
  55. ->save($playlist);
  56. }
  57. }