From 6cfaa54f977dedb97eca090b4f6874bf5b3c79ff Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 16 Dec 2012 19:56:54 +0100 Subject: [PATCH] use aac encoder(libvo_aacenc) available in ubuntu 12.04 universe (libavcodec-extra-53) --- README | 10 +--------- pandora/app/config.py | 28 ++++++++++++++++++++++++++++ pandora/archive/extract.py | 34 ++++++++++++++++++++++++---------- pandora/config.pandora.jsonc | 1 + vm/build.sh | 3 ++- vm/firstboot.sh | 6 ------ 6 files changed, 56 insertions(+), 26 deletions(-) diff --git a/README b/README index 418226ab5..10300013c 100644 --- a/README +++ b/README @@ -29,7 +29,7 @@ To run pan.do/ra you need to install and setup: python-geoip python-html5lib python-lxml \ python-gst0.10 gstreamer0.10-plugins-good gstreamer0.10-plugins-bad \ postgresql postgresql-contrib rabbitmq-server \ - ffmpeg2theora ffmpeg \ + ffmpeg2theora libav-tools libavcodec-extra-53 \ python-ox oxframe @@ -138,14 +138,6 @@ b) apache2 (if you need it for other sites on the same server) Now you can open pandora in your browser, the first user to sign up will become admin. - -* A note about providing H.264 versions - For H.264 videos, you need ffmpeg with x264 and libfaac enabled, - you also need to install qt-faststart (from ffmpeg/tools) - (you can use medibuntu.org packages or compile ffmpeg yourself) - to enable H.264 derivatives add "mp4" to video.formats in your config.jsonc - - === Updating === To update a pandora installation get the latest version from bzr by running su pandora diff --git a/pandora/app/config.py b/pandora/app/config.py index 5c2933631..07d0baf90 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -14,6 +14,8 @@ from django.contrib.auth.models import User import ox.jsonc from ox.utils import json +from archive.extract import supported_formats, AVCONV + _win = (sys.platform == "win32") @@ -49,6 +51,32 @@ def load_config(): for key in config['itemKeys']: config['keys'][key['id']] = key + old_formats = getattr(settings, 'CONFIG', {}).get('video', {}).get('formats', []) + formats = config.get('video', {}).get('formats') + if set(old_formats) != set(formats): + sformats = supported_formats() + if sformats: + for f in formats: + if f not in sformats or not sformats[f]: + sys.stderr.write('''WARNING: +Your configuration contains a video format "%s" that is +not supported by your version of avconv. Make sure you +dont have a local version of avconv in /usr/local/bin +and libavcodec-extra-53 and libav-tools are installed: + + sudo apt-get install libavcodec-extra-53 libav-tools + +''' % f) + else: + sys.stderr.write('''WARNING: +You dont have "%s" installed. +To fix this on Ubuntu 12.04, run: + + sudo apt-get install libavcodec-extra-53 libav-tools + +check the README for further details. + +''' % AVCONV) settings.CONFIG = config admin = len(settings.CONFIG['userLevels']) - 1 if not 'syncdb' in sys.argv \ diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index 8b35790bb..e1ddb524d 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -20,7 +20,8 @@ from ox.utils import json img_extension='jpg' -FFMPEG2THEORA = 'ffmpeg2theora' +AVCONV = 'avconv' + MAX_DISTANCE = math.sqrt(3 * pow(255, 2)) @@ -46,6 +47,20 @@ class AspectRatio(fractions.Fraction): def ratio(self): return "%d:%d" % (self.numerator, self.denominator) +def supported_formats(): + p = subprocess.Popen(['which', AVCONV], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + if not stdout.strip(): + return None + p = subprocess.Popen([AVCONV, '-codecs'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + return { + 'ogg': 'libtheora' in stdout and 'libvorbis' in stdout, + 'webm': 'libvpx' in stdout and 'libvorbis' in stdout, + 'mp4': 'libx264' in stdout and 'libvo_aacenc' in stdout, + } def stream(video, target, profile, info): if not os.path.exists(target): @@ -207,14 +222,13 @@ def stream(video, target, profile, info): if audiobitrate: audio_settings += ['-ab', audiobitrate] if format == 'mp4': - audio_settings += ['-acodec', 'libfaac'] + audio_settings += ['-acodec', 'libvo_aacenc'] else: audio_settings += ['-acodec', 'libvorbis'] else: audio_settings = ['-an'] - ffmpeg = FFMPEG2THEORA.replace('2theora', '') - cmd = [ffmpeg, '-y', '-i', video, '-threads', '4'] \ + cmd = [AVCONV, '-y', '-i', video, '-threads', '4'] \ + audio_settings \ + video_settings @@ -222,23 +236,23 @@ def stream(video, target, profile, info): cmd += ['-f', 'webm', target] elif format == 'mp4': #mp4 needs postprocessing(qt-faststart), write to temp file - cmd += ["%s.mp4"%target] - else : + cmd += ["%s.mp4" % target] + else: cmd += [target] - print cmd + #print cmd p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) p.communicate() if format == 'mp4': - cmd = ['qt-faststart', "%s.mp4"%target, target] - print cmd + cmd = ['qt-faststart', "%s.mp4" % target, target] + #print cmd p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) p.communicate() - os.unlink("%s.mp4"%target) + os.unlink("%s.mp4" % target) return True diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index 721de90c7..d96cade3b 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -609,6 +609,7 @@ "userLevels": ["guest", "member", "staff", "admin"], "video": { "download": true, + //supported formats: webm, mp4 "formats": ["webm"], "previewRatio": 1.3333333333, //supported resolutions are diff --git a/vm/build.sh b/vm/build.sh index 860f26f16..d102fefaa 100755 --- a/vm/build.sh +++ b/vm/build.sh @@ -42,7 +42,8 @@ sudo vmbuilder vbox ubuntu --suite=precise \ --addpkg gstreamer0.10-plugins-good \ --addpkg gstreamer0.10-plugins-bad \ --addpkg oxframe \ - --addpkg ffmpeg \ + --addpkg libavcodec-extra-53 \ + --addpkg libav-tools \ --addpkg ffmpeg2theora \ --execscript=$base/install.sh \ --firstboot=$base/firstboot.sh diff --git a/vm/firstboot.sh b/vm/firstboot.sh index 68746024e..5a347be96 100755 --- a/vm/firstboot.sh +++ b/vm/firstboot.sh @@ -4,12 +4,6 @@ apt-get -y install ipython ntp add-apt-repository ppa:j/pandora -#ffmpeg installed as apt package -#wget http://firefogg.org/nightly/ffmpeg.linux -O /usr/local/bin/ffmpeg -#chmod 755 /usr/local/bin/ffmpeg -#wget http://firefogg.org/nightly/ffmpeg2theora.linux -O /usr/local/bin/ffmpeg2theora -#chmod 755 /usr/local/bin/ffmpeg2theora - #postgresql apt-get -y install postgresql postgresql-contrib sudo -u postgres createuser -S -D -R pandora