Skip to content

Download and encode video files by using ffmpeg utilit

License

Notifications You must be signed in to change notification settings

PixxxeL/django-ffmpeg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django ffmpeg

Download and re-encode video files by using ffmpeg utilit or any another command line tool.

Since version 0.1.7 support Django 2 and above only. Before version 0.1.7 support Django 2 and below only.

Authors

The original version is created by Alrusdi. Modify, making separate application, refactoring and further development pixxxel

Install

pip install django-ffmpeg

Optionally in settings.py set directories names (FFMPEG_PRE_DIR, FFMPEG_ORIG_VIDEO, FFMPEG_THUMB_VIDEO, FFMPEG_CONV_VIDEO) for video files. Structure in MEDIA_ROOT by default is:

media
  ├ ...
  └ videos
    ├ conv
    ├ orig
    └ thumb

Add 'django_ffmpeg' to INSTALLED_APPS and execute python manage.py migrate

Dependencies

You must have Ffmpeg (or any other) utilit for converting video.

Possible get it for Ubuntu as:

sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install ffmpeg

For Windows you must download it.

Obviously, Django must have.

Usage

For converting video set the command(s) to ConvertingCommand model for example:

>>> from django_ffmpeg.models import ConvertingCommand
>>> 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()

or add fixture:

python manage.py loaddata django-ffmpeg-init

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 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.

If you're using Celery, you may invoke task for convert concrete video:

from django_ffmpeg.tasks import convert_video

convert_video.delay(command_id, video_id)

or for convert last uncoverted:

from django_ffmpeg.tasks import convert_first_pending

convert_first_pending.delay()

About

Download and encode video files by using ffmpeg utilit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages