Skip to content

Commit

Permalink
finetuning, Readme, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
randomknowledge committed Mar 8, 2013
1 parent 0e5aa1a commit 7d51c32
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 14 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2013 Florian Finke

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72 changes: 72 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# django-webvideo
___
`django-webvideo` is a [Django](https://www.djangoproject.com/) module to convert videos into web video formats.
Converting is handled by [ffmpeg](http://www.ffmpeg.org/) and queued with [rq](http://python-rq.org/).
By now `django-webvideo` can convert to h264 and ogg/theora.
`django-webvideo` will also create 3 screenshots of each video.

____
## Requirements
* [Django](https://www.djangoproject.com/)
* [easy-thumbnails](https://github.com/SmileyChris/easy-thumbnails)
* [rq](http://python-rq.org/)

## Installation

Install [pip](http://pypi.python.org/pypi/pip):

```console
$ sudo easy_install pip
```

Download source and install package using pip:

```console
$ sudo pip install -e git+https://github.com/randomknowledge/django_webvideo.git#egg=django-webvideo
```

Add ``django_webvideo`` to your ``INSTALLED_APPS`` setting::

INSTALLED_APPS = (
...
'django_webvideo',
)

If you have South installed then run ``manage.py migrate``,
otherwise just run ``manage.py syncdb``.

## Configuration

The following settings can be added to your django settings (these are also the default settings):

DJANGO_WEBVIDEO_SETTINGS = {
'upload_to': 'videos',
'convert_to': 'videos/converted',
'screens_to': 'videos/screens',
'ffmpeg': {
'binary': 'ffmpeg',
'call_h264': "{ffmpeg} -y -i {infile} -acodec libmp3lame -ar 48000 -ab 128k -ac 2 -vcodec libx264 "
"-cmp 256 -subq 7 -trellis 1 -refs 5 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 "
"-i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' "
"-qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -r 30 -g 90 {outfile}",
'call_ogv': '{ffmpeg} -i {infile} -b 1200k -vcodec libtheora -acodec libvorbis -ab 160000 {outfile}',
},
'redis': {
'connection': {
'db': 0,
'host': 'localhost',
'port': 6379,
},
'eager': False, # If True, Tasks are not queued, but executed directly. Use for testing purposes only!
'queue_prefix': 'webvideo', # django_webvideo will prefix all (RQ-)Queues with this prefix.
'timeout': 600,
},
'use_admin': True,
}

Any setting missing in this dictionary will be replaced by the default one.

## Example Template usage

{% load webvideo_tags %}
{% video_tag webvideo_object width=640 height=480 autoplay=0 controls=1 attributes='id="test"' screen_num=2 %}
3 changes: 2 additions & 1 deletion django_webvideo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

# -*- coding: utf-8 -*-
__version__ = '0.1.0'
8 changes: 5 additions & 3 deletions django_webvideo/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
from django.contrib import admin
from django_webvideo.models import WebVideo
from django_webvideo.settings import get_setting


def admin_thumb_helper(image_object=True, for_admin=True, height=100, width=0):
Expand All @@ -26,10 +27,11 @@ def admin_thumb(*args):

class WebVideoAdmin(admin.ModelAdmin):
list_display = ('original', 'status', 'duration', 'admin_thumb', )
fields = ('status', 'original', 'h264', 'oggvorbis', 'duration', 'screen_1', 'screen_2', 'screen_3', )
readonly_fields = ('status', 'h264', 'oggvorbis', 'duration', )
fields = ('status', 'original', 'h264', 'oggtheora', 'duration', 'screen_1', 'screen_2', 'screen_3', )
readonly_fields = ('status', 'h264', 'oggtheora', 'duration', )

admin_thumb = admin_thumb_helper()


admin.site.register(WebVideo, WebVideoAdmin)
if get_setting('use_admin'):
admin.site.register(WebVideo, WebVideoAdmin)
4 changes: 2 additions & 2 deletions django_webvideo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def forwards(self, orm):
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('original', self.gf('django.db.models.fields.files.FileField')(max_length=100)),
('h264', self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True)),
('oggvorbis', self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True)),
('oggtheora', self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True)),
('status', self.gf('django.db.models.fields.SmallIntegerField')(default=0)),
('duration', self.gf('django.db.models.fields.FloatField')(default=0.0)),
('screen_1', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
Expand All @@ -34,7 +34,7 @@ def backwards(self, orm):
'duration': ('django.db.models.fields.FloatField', [], {'default': '0.0'}),
'h264': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'oggvorbis': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'oggtheora': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'original': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
'screen_1': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'screen_2': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
Expand Down
6 changes: 3 additions & 3 deletions django_webvideo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _convert(web_video):
class WebVideo(models.Model):
original = models.FileField(upload_to=get_setting('upload_to'))
h264 = models.FileField(upload_to=get_setting('convert_to'), blank=True, null=True, editable=False)
oggvorbis = models.FileField(upload_to=get_setting('convert_to'), blank=True, null=True, editable=False)
oggtheora = models.FileField(upload_to=get_setting('convert_to'), blank=True, null=True, editable=False)
status = models.SmallIntegerField(
choices=constants.VIDEO_STATE_CHOICES, default=constants.VIDEO_STATE_PENDING, editable=False
)
Expand Down Expand Up @@ -97,13 +97,13 @@ def convert(self):
result2 = convert_video(self.original.path, out2_abs, 'ogv')
if result1 and result2:
self.h264.name = out1_rel
self.oggvorbis.name = out2_rel
self.oggtheora.name = out2_rel
self.status = constants.VIDEO_STATE_SUCCESS
else:
if result1:
self.h264.name = out1_rel
if result2:
self.oggvorbis.name = out2_rel
self.oggtheora.name = out2_rel
self.status = constants.VIDEO_STATE_ERROR
self.save()

Expand Down
3 changes: 2 additions & 1 deletion django_webvideo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
'eager': False, # If True, Tasks are not queued, but executed directly. Use for testing purposes only!
'queue_prefix': 'webvideo', # django_webvideo will prefix all (RQ-)Queues with this prefix.
'timeout': 600,
}
},
'use_admin': True,
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<video {{ attributes }} width="{{ width }}" height="{{ height }}" preload="{{ preload }}" poster="{{ poster }}"{% if controls %} controls{% endif %}{% if autoplay %} autoplay="autoplay"{% endif %}>
<source src="{{ video.h264.url }}" type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;">
<source src="{{ video.oggvorbis.url }}" type="video/ogg; codecs=&quot;theora, vorbis&quot;">
<source src="{{ video.oggtheora.url }}" type="video/ogg; codecs=&quot;theora, vorbis&quot;">
</video>
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# coding=utf-8
from setuptools import setup
import django_webvideo
import finddata


setup(
name="django_webvideo",
name="django-webvideo",
author="Florian Finke",
author_email="[email protected]",
version='0.0.1',
version=django_webvideo.__version__,
packages=['django_webvideo'],
package_data=finddata.find_package_data(),
url='https://github.com/randomknowledge/django_webvideo',
include_package_data=True,
license='MIT',
description='',
description='A queuing web video converter',
long_description=open('Readme.md').read(),
zip_safe=False,
install_requires=[
'Django==1.5',
'South==0.7.6',
'PIL==1.1.7',
'easy-thumbnails==1.2',
'rq==0.3.7',
],
classifiers=[
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 7d51c32

Please sign in to comment.