use aac encoder(libvo_aacenc) available in ubuntu 12.04 universe (libavcodec-extra-53)
This commit is contained in:
parent
348adff954
commit
6cfaa54f97
6 changed files with 56 additions and 26 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -609,6 +609,7 @@
|
|||
"userLevels": ["guest", "member", "staff", "admin"],
|
||||
"video": {
|
||||
"download": true,
|
||||
//supported formats: webm, mp4
|
||||
"formats": ["webm"],
|
||||
"previewRatio": 1.3333333333,
|
||||
//supported resolutions are
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue