|
@@ -131,6 +131,7 @@ class GeneratePreviewVideo extends Command
|
|
|
return "https://mietublcom.oss-cn-hongkong.aliyuncs.com".'/'.$url;
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
|
|
|
public function generatePreview($inputUrl, $outputPath) {
|
|
|
$ffmpeg = FFMpeg::create([
|
|
@@ -150,6 +151,44 @@ class GeneratePreviewVideo extends Command
|
|
|
$format->setAdditionalParameters(['-an']); // 禁用音频,或者可以用 setAdditionalParameters(['-an'])
|
|
|
$video->save($format, $outputPath);
|
|
|
return $outputPath;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ public function generatePreview($inputUrl, $outputPath) {
|
|
|
+ $ffmpeg = FFMpeg::create([
|
|
|
+ 'ffmpeg.binaries' => '/usr/bin/ffmpeg',
|
|
|
+ 'ffprobe.binaries' => '/usr/bin/ffprobe',
|
|
|
+ 'timeout' => 300
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Open the video
|
|
|
+ $video = $ffmpeg->open($inputUrl);
|
|
|
+
|
|
|
+ // Use ffprobe to get original video dimensions
|
|
|
+ $ffprobe = \FFMpeg\FFProbe::create(['ffprobe.binaries' => '/usr/bin/ffprobe']);
|
|
|
+ $stream = $ffprobe->streams($inputUrl)->videos()->first();
|
|
|
+ $originalWidth = $stream->getDimensions()->getWidth();
|
|
|
+ $originalHeight = $stream->getDimensions()->getHeight();
|
|
|
+
|
|
|
+ // Calculate adaptive height for a fixed width of 300
|
|
|
+ $newWidth = 300;
|
|
|
+ $newHeight = (int) round(($originalHeight / $originalWidth) * $newWidth);
|
|
|
+
|
|
|
+ // Ensure dimensions are even (required by H.264)
|
|
|
+ $newHeight = $newHeight % 2 === 0 ? $newHeight : $newHeight + 1;
|
|
|
+
|
|
|
+ // Apply filters
|
|
|
+ $video->filters()->clip(TimeCode::fromSeconds(0), TimeCode::fromSeconds($this->timeSecond));
|
|
|
+ $video->filters()->framerate(new \FFMpeg\Coordinate\FrameRate(15), 60); // Lower frame rate
|
|
|
+ $video->filters()->resize(new \FFMpeg\Coordinate\Dimension($newWidth, $newHeight)); // Adaptive resize
|
|
|
+
|
|
|
+ // Output as H.264 encoded MP4
|
|
|
+ $format = new \FFMpeg\Format\Video\X264();
|
|
|
+ //$format->setKiloBitrate(200); // Set video bitrate (kbps)
|
|
|
+ $format->setAdditionalParameters(['-an']); // Disable audio
|
|
|
+
|
|
|
+ // Save the video
|
|
|
+ $video->save($format, $outputPath);
|
|
|
+ return $outputPath;
|
|
|
}
|
|
|
|
|
|
|