forked from GNUsocial/gnu-social
[PLUGIN][VideoEncoder] Some videos don't have images (video stream), only audio, handle that
This commit is contained in:
parent
4501b7e85e
commit
044649c745
@ -1,3 +1,4 @@
|
|||||||
|
{% if attachment.getFilename() is not null %}
|
||||||
<div>
|
<div>
|
||||||
<figure>
|
<figure>
|
||||||
<audio class="u-audio" src="{{ attachment.getUrl() }}" controls>
|
<audio class="u-audio" src="{{ attachment.getUrl() }}" controls>
|
||||||
@ -11,3 +12,6 @@
|
|||||||
</figcaption>
|
</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{# Not stored locally. #}
|
||||||
|
{% endif %}
|
||||||
|
@ -69,36 +69,31 @@ class StoreRemoteMedia extends Plugin
|
|||||||
'.*', // Default to allowing any host
|
'.*', // Default to allowing any host
|
||||||
];
|
];
|
||||||
public array $domain_blacklist = [];
|
public array $domain_blacklist = [];
|
||||||
// Whether to maintain a copy of the original media or only a thumbnail of it
|
|
||||||
public bool $store_original = false;
|
|
||||||
public ?int $thumbnail_width;
|
|
||||||
public ?int $thumbnail_height;
|
|
||||||
public ?int $max_size;
|
|
||||||
public ?bool $smart_crop;
|
|
||||||
|
|
||||||
|
// Whether to maintain a copy of the original media or only a thumbnail of it
|
||||||
private function getStoreOriginal(): bool
|
private function getStoreOriginal(): bool
|
||||||
{
|
{
|
||||||
return $this->store_original ?? Common::config('plugin_store_remote_media', 'store_original');
|
return Common::config('plugin_store_remote_media', 'store_original');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getThumbnailWidth(): int
|
private function getThumbnailWidth(): int
|
||||||
{
|
{
|
||||||
return $this->thumbnail_width ?? Common::config('thumbnail', 'width');
|
return Common::config('thumbnail', 'width');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getThumbnailHeight(): int
|
private function getThumbnailHeight(): int
|
||||||
{
|
{
|
||||||
return $this->thumbnail_height ?? Common::config('thumbnail', 'height');
|
return Common::config('thumbnail', 'height');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMaxSize(): int
|
private function getMaxFileSize(): int
|
||||||
{
|
{
|
||||||
return $this->max_size ?? Common::config('plugin_store_remote_media', 'max_file_size');
|
return Common::config('plugin_store_remote_media', 'max_file_size');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSmartCrop(): bool
|
private function getSmartCrop(): bool
|
||||||
{
|
{
|
||||||
return $this->smart_crop ?? Common::config('plugin_store_remote_media', 'smart_crop');
|
return Common::config('plugin_store_remote_media', 'smart_crop');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,7 +54,8 @@ class VideoEncoder extends Plugin
|
|||||||
return '1.0.0';
|
return '1.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function shouldHandle (string $mimetype): bool {
|
public static function shouldHandle(string $mimetype): bool
|
||||||
|
{
|
||||||
return GSFile::mimetypeMajor($mimetype) === 'video' || $mimetype === 'image/gif';
|
return GSFile::mimetypeMajor($mimetype) === 'video' || $mimetype === 'image/gif';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,10 +108,12 @@ class VideoEncoder extends Plugin
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$metadata = $ffprobe->streams($file->getRealPath()) // extracts streams informations
|
$metadata = $ffprobe->streams($file->getRealPath()) // extracts streams informations
|
||||||
->videos() // filters video streams
|
->videos() // filters video streams
|
||||||
->first(); // returns the first video stream
|
->first(); // returns the first video stream
|
||||||
$width = $metadata->get('width');
|
if (!\is_null($metadata)) {
|
||||||
$height = $metadata->get('height');
|
$width = $metadata->get('width');
|
||||||
|
$height = $metadata->get('height');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
<div>
|
{% if attachment.getFilename() is not null %}
|
||||||
<figure>
|
<div>
|
||||||
<video class="u-video" src="{{ attachment.getUrl() }}" controls poster="{{ attachment.getThumbnailUrl('medium')}}">
|
<figure>
|
||||||
</video>
|
<video
|
||||||
<figcaption>
|
{% if attachment.getWidth() is not null %}
|
||||||
{% if attachment.getFilename() is not null %}
|
class="u-video"
|
||||||
<a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
{% else %}
|
||||||
{% else %}
|
class="u-audio"
|
||||||
{{ attachment.getBestTitle(note) }}
|
{% endif %}
|
||||||
{% endif %}
|
src="{{ attachment.getUrl() }}" controls
|
||||||
</figcaption>
|
{% if attachment.getWidth() is not null %}
|
||||||
</figure>
|
poster="{{ attachment.getThumbnailUrl('medium')}}"
|
||||||
</div>
|
{% endif %}
|
||||||
|
>
|
||||||
|
</video>
|
||||||
|
<figcaption>
|
||||||
|
<a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getBestTitle(note) }}</a>
|
||||||
|
</figcaption>
|
||||||
|
</figure>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{# Not stored locally. #}
|
||||||
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user