public function __construct($file, $screenshotDirectory = '/tmp') { $this->file = $file; $this->screenshotDirectory = $screenshotDirectory; $this->ffmpeg = FFMpeg::create(); $this->ffprobe = FFProbe::create(); $this->movie = $this->ffmpeg->open($file); $this->info = $this->ffprobe->format($file); }
/** * 영상에서 snapshot 추출 * * @param string $content media content * @param int $fromSecond 영상에서의 시간(초 단위) * @return string */ public function getSnapshot($content, $fromSecond = 10) { $videoFile = $this->temp->create($content); $imgPathname = $this->temp->getTempPathname(); $video = $this->ffmpeg->open($videoFile->getPathname()); $video->frame(TimeCode::fromSeconds($fromSecond))->save($imgPathname); $imageContent = file_get_contents($imgPathname); $videoFile->destroy(); @unlink($imgPathname); return $imageContent; }
public function testBatchGenerate() { $times = ['00:00:00:01', '00:00:00:11', '00:00:00:21']; foreach ($times as $time) { $timecode = TimeCode::fromString($time); $this->ffmpeg->open('1.mp4')->willReturn($this->video->reveal())->shouldBeCalled(); $this->video->frame($timecode)->willReturn($this->frame->reveal())->shouldBeCalled(); $this->frame->save(str_replace(':', '.', '/' . $time . '.jpg'))->shouldBeCalled(); } $this->videoThumbnailService->batchGenerate('1.mp4', $times, ''); }
/** * 영상에서 snapshot 추출 * * @param string $content media content * @param int $fromSecond 영상에서의 시간(초 단위) * @return string */ public function getSnapshot($content, $fromSecond = 10) { $tmpPathname = $this->temp->getTempPathname(); $tmpImgPathname = $this->temp->getTempPathname(); $this->temp->createFile($tmpPathname, $content); $video = $this->ffmpeg->open($tmpPathname); $video->frame(TimeCode::fromSeconds($fromSecond))->save($tmpImgPathname); $imageContent = file_get_contents($tmpImgPathname); $this->temp->remove($tmpPathname); $this->temp->remove($tmpImgPathname); return $imageContent; }
/** * {@inheritdoc} */ public function generate($file, $time, $destination) { $destination = $this->normalizeFilename($destination); try { $video = $this->ffmpeg->open($file); $timecode = TimeCode::fromString($time); $frame = $video->frame($timecode); $frame->save($destination); } catch (InvalidArgumentException $e) { // there will be no image file - so nothing to do here } return file_exists($destination); }
/** * @expectedException \FFMpeg\Exception\InvalidArgumentException */ public function testOpenUnknown() { $ffprobe = $this->getFFProbeMock(); $ffprobe->expects($this->once())->method('streams')->with(__FILE__)->will($this->returnValue(new StreamCollection())); $ffmpeg = new FFMpeg($this->getFFMpegDriverMock(), $ffprobe); $ffmpeg->open(__FILE__); }
/** * {@inheritdoc} */ public function extract($filename, Specification $targetFormat) { if (!file_exists($filename)) { return null; } $imageFilename = null; try { $filesystem = new Filesystem(); if (!$filesystem->exists($this->tempDir)) { $filesystem->mkdir($this->tempDir); } $imageFilename = $this->tempDir . '/' . uniqid() . '.jpg'; $this->converter->open($filename)->frame(TimeCode::fromSeconds(3))->save($imageFilename); } catch (\Exception $e) { $imageFilename = null; } return $imageFilename; }
/** * @param string $inFilename * @param Audio $spec * @param string $outFilename * * @return string */ public function convert($inFilename, Specification $spec, $outFilename) { $audio = $this->ffmpeg->open($inFilename); $format = $this->createFormat($spec->getAudioFormat()); if ($spec->getAudioCodec()) { $format->setAudioCodec($spec->getAudioCodec()); } if ($spec->getAudioBitrate()) { $format->setAudioKiloBitrate($spec->getAudioBitrate()); } if ($spec->getAudioSamplerate()) { $audio->addFilter(new AudioResamplableFilter($spec->getAudioSamplerate())); } if ($spec->getAudioChannels()) { $format->setAudioChannels($spec->getAudioChannels()); } $audio->save($format, $outFilename); }
/** * @covers FFMpeg\FFMpeg::encode * @covers FFMpeg\FFMpeg::encodeVideo */ public function testEncodeX264() { $dest = __DIR__ . '/../../files/encode_test.mp4'; $format = new Format\Video\WebM(); $format->setDimensions(32, 32); $this->object->open(__DIR__ . '/../../files/Test.ogv'); $this->object->encode($format, $dest); $this->probe->probeFormat($dest); unlink($dest); }
/** * @param string $inFilename * @param Video $spec * @param string $outFilename */ public function convert($inFilename, Specification $spec, $outFilename) { $video = $this->ffmpeg->open($inFilename); $format = $this->createFormat($spec->getVideoFormat()); $resizeMode = ResizeFilter::RESIZEMODE_FIT; if ($spec->getResizeMode()) { $resizeMode = $spec->getResizeMode(); } $video->addFilter(new SynchronizeFilter()); //if ($source->getWidth() > $spec->getWidth() || $source->getHeight() > $spec->getHeight()) { if ($spec->getWidth() && $spec->getHeight()) { $video->addFilter(new ResizeFilter(new Dimension($spec->getWidth(), $spec->getHeight()), $resizeMode)); } if ($spec->getVideoCodec()) { $format->setVideoCodec($spec->getVideoCodec()); } if ($spec->getAudioCodec()) { $format->setAudioCodec($spec->getAudioCodec()); } if ($spec->getVideoBitrate()) { $format->setKiloBitrate($spec->getVideoBitrate()); } if ($spec->getVideoFramerate() && $spec->getVideoGop()) { $video->addFilter(new FrameRateFilter(new FrameRate($spec->getVideoFramerate()), $spec->getVideoGop())); } if ($spec->getAudioBitrate()) { $format->setAudioKiloBitrate($spec->getAudioBitrate()); } if ($spec->getAudioSamplerate()) { $video->addFilter(new AudioResamplableFilter($spec->getAudioSamplerate())); } elseif ($format instanceof Flv) { $video->addFilter(new AudioResamplableFilter(44100)); } if ($spec->getAudioChannels()) { $format->setAudioChannels($spec->getAudioChannels()); } $video->save($format, $outFilename); if ($format instanceof X264) { $this->mp4box->process($outFilename); } }
public function __construct(File $file, FFMpeg $ffmpeg) { $this->video = $ffmpeg->open($file->getRealPath()); }
/** * Set File. * * @param string $file * * @return \Dms\FFmpeg\FFmpeg */ public function setFile($file) { $this->file = $file; $this->video = $this->ffmpeg->open($this->file); return $this; }