class MediaThumbnailVideo in Media Thumbnails Video 8
Media thumbnail plugin for videos.
Plugin annotation
@MediaThumbnail(
id = "media_thumbnail_video",
label = @Translation("Media Thumbnail Video"),
mime = {
"video/mp4",
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\media_thumbnails\Plugin\MediaThumbnailBase implements ContainerFactoryPluginInterface, MediaThumbnailInterface uses StringTranslationTrait
- class \Drupal\media_thumbnails_video\Plugin\MediaThumbnail\MediaThumbnailVideo
- class \Drupal\media_thumbnails\Plugin\MediaThumbnailBase implements ContainerFactoryPluginInterface, MediaThumbnailInterface uses StringTranslationTrait
Expanded class hierarchy of MediaThumbnailVideo
File
- src/
Plugin/ MediaThumbnail/ MediaThumbnailVideo.php, line 24
Namespace
Drupal\media_thumbnails_video\Plugin\MediaThumbnailView source
class MediaThumbnailVideo extends MediaThumbnailBase {
/**
* {@inheritdoc}
*/
public function createThumbnail($sourceUri) {
$config = $this->config
->getEditable('media_thumbnails_video.settings');
$path = $this->fileSystem
->realpath($sourceUri);
try {
// Create ffmpeg container.
$ffmpeg = FFMpeg::create([
'ffmpeg.binaries' => $config
->get('ffmpeg'),
'ffprobe.binaries' => $config
->get('ffprobe'),
'timeout' => $config
->get('timeout'),
'ffmpeg.threads' => $config
->get('threads'),
]);
try {
// Try open file form real path.
$video = $ffmpeg
->open($path);
$thumbnail_path = $path . '.png';
$width = $this->configuration['width'];
$video
->frame(TimeCode::fromSeconds(1))
->save($thumbnail_path);
if (!empty($width)) {
$image = imagecreatefrompng($thumbnail_path);
$image = imagescale($image, $width);
imagepng($image, $thumbnail_path);
}
// Create a managed file object.
$file = File::create([
'uri' => $sourceUri . '.png',
'status' => 1,
]);
try {
$file
->save();
return $file;
} catch (EntityStorageException $e) {
$this->logger
->warning(t('Could not create thumbnail file entity.'));
return NULL;
}
} catch (\Exception $e) {
$this->logger
->warning($e
->getMessage());
return NULL;
}
} catch (ExecutableNotFoundException $e) {
$this->logger
->warning($e
->getMessage());
return NULL;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MediaThumbnailBase:: |
protected | property | The config factory. | |
MediaThumbnailBase:: |
protected | property | The file system interface. | |
MediaThumbnailBase:: |
protected | property | The logger interface. | |
MediaThumbnailBase:: |
public static | function |
Injects some default services. Overrides ContainerFactoryPluginInterface:: |
|
MediaThumbnailBase:: |
public | function |
Constructs a new Media Thumbnail class. Overrides PluginBase:: |
|
MediaThumbnailVideo:: |
public | function |
Create a thumbnail file using the passed source uri. Overrides MediaThumbnailInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |