Unverified Commit 26d4cafd authored by Seb Brown's avatar Seb Brown Committed by GitHub
Browse files

Merge pull request #108 from jkevingutierrez/patch-6

Add ability to generate thumbnail in different formats
parents 67f6fb48 df708015
...@@ -13,7 +13,7 @@ Requirements ...@@ -13,7 +13,7 @@ Requirements
------------ ------------
- Wagtail >= 4.0 (for older wagtail version see the tags) - Wagtail >= 4.0 (for older wagtail version see the tags)
- `ffmpeg <https://ffmpeg.org/>`__ - `ffmpeg <https://ffmpeg.org/>`__
Installing Installing
---------- ----------
...@@ -31,7 +31,7 @@ Add `wagtailvideos` to your installed apps. ...@@ -31,7 +31,7 @@ Add `wagtailvideos` to your installed apps.
INSTALLED_APPS = [ INSTALLED_APPS = [
'wagtailvideos', 'wagtailvideos',
] ]
Using Using
----- -----
...@@ -121,6 +121,16 @@ Transcode can be disabled using the ``WAGTAIL_VIDEOS_DISABLE_TRANSCODE`` setting ...@@ -121,6 +121,16 @@ Transcode can be disabled using the ``WAGTAIL_VIDEOS_DISABLE_TRANSCODE`` setting
# settings.py # settings.py
WAGTAIL_VIDEOS_DISABLE_TRANSCODE = True WAGTAIL_VIDEOS_DISABLE_TRANSCODE = True
Modify Thumbnail extension:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The automatically generated Thumbnail extension can be modified using the ``WAGTAIL_VIDEOS_THUMBNAIL_EXTENSION`` setting. Default value is jpg
.. code:: django
# settings.py
WAGTAIL_VIDEOS_THUMBNAIL_EXTENSION = 'webp'
Custom Video models: Custom Video models:
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
......
...@@ -7,6 +7,7 @@ import subprocess ...@@ -7,6 +7,7 @@ import subprocess
import tempfile import tempfile
from django.core.files.base import ContentFile from django.core.files.base import ContentFile
from django.conf import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -46,7 +47,8 @@ def get_thumbnail(file_path): ...@@ -46,7 +47,8 @@ def get_thumbnail(file_path):
raise RuntimeError('ffmpeg is not installed') raise RuntimeError('ffmpeg is not installed')
file_name = os.path.basename(file_path) file_name = os.path.basename(file_path)
thumb_name = '{}_thumb{}'.format(os.path.splitext(file_name)[0], '.jpg') thumb_extension = getattr(settings, 'WAGTAIL_VIDEOS_THUMBNAIL_EXTENSION', 'jpg').lower()
thumb_name = '{}_thumb.{}'.format(os.path.splitext(file_name)[0], thumb_extension)
try: try:
output_dir = tempfile.mkdtemp() output_dir = tempfile.mkdtemp()
...@@ -57,9 +59,9 @@ def get_thumbnail(file_path): ...@@ -57,9 +59,9 @@ def get_thumbnail(file_path):
'-v', 'quiet', '-v', 'quiet',
'-itsoffset', '-4', '-itsoffset', '-4',
'-i', file_path, '-i', file_path,
'-vcodec', 'mjpeg', '-update', 'true',
'-vframes', '1', '-vframes', '1',
'-an', '-f', 'rawvideo', '-an',
'-vf', 'scale=iw:-1', # Make thumbnail the size & aspect ratio of the input video '-vf', 'scale=iw:-1', # Make thumbnail the size & aspect ratio of the input video
output_file, output_file,
], stdin=DEVNULL(), stdout=DEVNULL()) ], stdin=DEVNULL(), stdout=DEVNULL())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment