Skip to content

Commit

Permalink
* Fix conversion output\n* Except conversion error to convert_status
Browse files Browse the repository at this point in the history
  • Loading branch information
PixxxeL committed May 27, 2019
1 parent 2dbab9f commit f5da05c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
21 changes: 15 additions & 6 deletions README.md
Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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'
2 changes: 1 addition & 1 deletion django_ffmpeg/admin.py
Expand Up @@ -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')


Expand Down
6 changes: 4 additions & 2 deletions django_ffmpeg/utils.py
Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit f5da05c

Please sign in to comment.