From f5da05c657166f174c13e67e8782974b93835f75 Mon Sep 17 00:00:00 2001 From: pixxxel Date: Mon, 27 May 2019 16:58:39 +0500 Subject: [PATCH] * Fix conversion output\n* Except conversion error to convert_status --- README.md | 21 +++++++++++++++------ django_ffmpeg/__init__.py | 2 +- django_ffmpeg/admin.py | 2 +- django_ffmpeg/utils.py | 6 ++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4a86db..bfceddd 100644 --- a/README.md +++ b/README.md @@ -48,18 +48,27 @@ for example: ```shell >>> from django_ffmpeg.models import ConvertingCommand ->>> ConvertingCommand(match_by='name', match_regex='.*', command='/usr/bin/ffmpeg -hide_banner -nostats -i %(input_file)s -target film-dvd %(output_file)s', convert_extension='mp4').save() +>>> ConvertingCommand( + match_by='name', + match_regex='.*', + command='ffmpeg -y -hide_banner -nostats -i %(input_file)s -threads 0 -xerror %(output_file)s', + convert_extension='mp4', + thumb_command='ffmpeg -hide_banner -nostats -i %(in_file)s -y -frames:v 1 -ss %(thumb_frame)s %(out_file)s' +).save() ``` Fragments `%(input_file)s` and `%(output_file)s` in `command` is required. +Fragments `%(in_file)s` and `%(thumb_frame)s` in `thumb_command` is required. + +Option `-xerror ` is required for except ffmpeg conversion error to convert_status. + After this you must run `python manage.py convert_videos` or set it to crontab. -Command convert one unprocessed video at time. -So execute this command as many times as video is. +Command is convert only one unconverted video at time. +So execute this command as many times as unconverted videos is it. Now you may reference on `django_ffmpeg.Video` model from other or get it directly. ## Todo -* Converting output is lose -* Add converting error output to `last_convert_msg` -* Refactoring thumbnail command +* Autocreate media directories +* Refactoring utils.Converter diff --git a/django_ffmpeg/__init__.py b/django_ffmpeg/__init__.py index 8049b42..e1bbace 100644 --- a/django_ffmpeg/__init__.py +++ b/django_ffmpeg/__init__.py @@ -1,3 +1,3 @@ -VERSION = (0, 0, 14,) +VERSION = (0, 0, 15,) __version__ = '.'.join(map(str, VERSION)) default_app_config = 'django_ffmpeg.app.DjangoFfmpegConfig' diff --git a/django_ffmpeg/admin.py b/django_ffmpeg/admin.py index dd20e16..f8aad39 100644 --- a/django_ffmpeg/admin.py +++ b/django_ffmpeg/admin.py @@ -6,7 +6,7 @@ def reconvert_video(modeladmin, request, queryset): - queryset.update(convert_status='pending') + queryset.update(convert_status='pending', last_convert_msg='') reconvert_video.short_description = _('Convert again') diff --git a/django_ffmpeg/utils.py b/django_ffmpeg/utils.py index b38d0c3..128b587 100644 --- a/django_ffmpeg/utils.py +++ b/django_ffmpeg/utils.py @@ -76,7 +76,9 @@ def convert(self): except: logger.error('Converting thumb error', exc_info=True) - video.convert_status = 'converted' + video.convert_status = 'error' \ + if output and output.find('Conversion failed') != -1 \ + else 'converted' video.last_convert_msg = repr(output).replace('\\n', '\n').strip('\'') video.converted_at = datetime.datetime.now(tz=timezone('UTC')) video.save() @@ -88,7 +90,7 @@ def _cli(self, cmd, without_output=False): import sys if sys.version_info[0] > 2: res = subprocess.getstatusoutput(cmd) - if without_output and res and len(res): + if not without_output and res and len(res): return res[1] elif os.name == 'posix': import commands