mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-19 18:15:31 +01:00
Add support for libav-tools
This commit is contained in:
@@ -1101,24 +1101,35 @@
|
||||
</div>
|
||||
</div>
|
||||
<%
|
||||
if config['encoder'] == 'lame':
|
||||
lameselect = 'selected="selected"'
|
||||
ffmpegselect = ''
|
||||
xldselect = ''
|
||||
elif config['encoder'] == 'ffmpeg':
|
||||
lameselect = ''
|
||||
ffmpegselect = 'selected="selected"'
|
||||
xldselect = ''
|
||||
else:
|
||||
lameselect = ''
|
||||
ffmpegselect = ''
|
||||
xldselect = 'selected="selected"'
|
||||
if config['encoder'] == 'lame':
|
||||
lameselect = 'selected="selected"'
|
||||
ffmpegselect = ''
|
||||
xldselect = ''
|
||||
libavselect = ''
|
||||
elif config['encoder'] == 'ffmpeg':
|
||||
lameselect = ''
|
||||
ffmpegselect = 'selected="selected"'
|
||||
xldselect = ''
|
||||
libavselect = ''
|
||||
elif config['encoder'] == 'libav':
|
||||
lameselect = ''
|
||||
ffmpegselect = ''
|
||||
xldselect = ''
|
||||
libavselect = 'selected="selected"'
|
||||
else:
|
||||
lameselect = ''
|
||||
ffmpegselect = ''
|
||||
xldselect = 'selected="selected"'
|
||||
libavselect = ''
|
||||
%>
|
||||
<div class="row">
|
||||
<label>Encoder</label>
|
||||
<label title="Name of encoder to use. Lame, FFmpeg and libav are available for most Linux distributions. On Ubuntu, libav replaces FFmpeg. xld is OS X-only.">
|
||||
Encoder
|
||||
</label>
|
||||
<select name="encoder" id="encoder">
|
||||
<option value="lame" ${lameselect}>lame</option>
|
||||
<option value="ffmpeg" ${ffmpegselect}>ffmpeg</option>
|
||||
<option value="libav" ${libavselect}>libav</option>
|
||||
<option value="xld" ${xldselect}>xld</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -1409,13 +1420,16 @@
|
||||
switch ($(this).val()) {
|
||||
case 'xld':
|
||||
$("#xldproperties").slideDown();
|
||||
break;
|
||||
break;
|
||||
case 'ffmpeg':
|
||||
$("#lameffmpegproperties").slideDown();
|
||||
break;
|
||||
break;
|
||||
case 'libav':
|
||||
$("#lameffmpegproperties").slideDown();
|
||||
break;
|
||||
case 'lame':
|
||||
$("#lameffmpegproperties").slideDown();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ def command(encoder, musicSource, musicDest, albumPath):
|
||||
elif headphones.ENCODER == 'lame':
|
||||
cmd = [encoder]
|
||||
opts = []
|
||||
if headphones.ADVANCEDENCODER =='':
|
||||
if not headphones.ADVANCEDENCODER:
|
||||
opts.extend(['-h'])
|
||||
if headphones.ENCODERVBRCBR=='cbr':
|
||||
opts.extend(['--resample', str(headphones.SAMPLINGFREQUENCY), '-b', str(headphones.BITRATE)])
|
||||
@@ -284,7 +284,7 @@ def command(encoder, musicSource, musicDest, albumPath):
|
||||
elif headphones.ENCODER == 'ffmpeg':
|
||||
cmd = [encoder, '-i', musicSource]
|
||||
opts = []
|
||||
if headphones.ADVANCEDENCODER =='':
|
||||
if not headphones.ADVANCEDENCODER:
|
||||
if headphones.ENCODEROUTPUTFORMAT=='ogg':
|
||||
opts.extend(['-acodec', 'libvorbis'])
|
||||
if headphones.ENCODEROUTPUTFORMAT=='m4a':
|
||||
@@ -303,14 +303,28 @@ def command(encoder, musicSource, musicDest, albumPath):
|
||||
|
||||
# Libav
|
||||
elif headphones.ENCODER == "libav":
|
||||
pass
|
||||
cmd = [encoder, '-i', musicSource]
|
||||
opts = []
|
||||
if not headphones.ADVANCEDENCODER:
|
||||
if headphones.ENCODEROUTPUTFORMAT=='ogg':
|
||||
opts.extend(['-acodec', 'libvorbis'])
|
||||
if headphones.ENCODEROUTPUTFORMAT=='m4a':
|
||||
opts.extend(['-strict', 'experimental'])
|
||||
if headphones.ENCODERVBRCBR=='cbr':
|
||||
opts.extend(['-ar', str(headphones.SAMPLINGFREQUENCY), '-ab', str(headphones.BITRATE) + 'k'])
|
||||
elif headphones.ENCODERVBRCBR=='vbr':
|
||||
opts.extend(['-aq', str(headphones.ENCODERQUALITY)])
|
||||
opts.extend(['-y', '-ac', '2', '-vn'])
|
||||
else:
|
||||
advanced = (headphones.ADVANCEDENCODER.split())
|
||||
for tok in advanced:
|
||||
opts.extend([tok.encode(headphones.SYS_ENCODING)])
|
||||
opts.extend([musicDest])
|
||||
cmd.extend(opts)
|
||||
|
||||
# Encode
|
||||
logger.info('Encoding %s...' % (musicSource.decode(headphones.SYS_ENCODING, 'replace')))
|
||||
logger.debug(subprocess.list2cmdline(cmd))
|
||||
|
||||
# stop windows opening the cmd
|
||||
# Prevent Windows from opening a terminal window
|
||||
startupinfo = None
|
||||
|
||||
if headphones.SYS_PLATFORM == "win32":
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
try:
|
||||
@@ -318,12 +332,17 @@ def command(encoder, musicSource, musicDest, albumPath):
|
||||
except AttributeError:
|
||||
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
|
||||
|
||||
p = subprocess.Popen(cmd, startupinfo=startupinfo, stdin=open(os.devnull, 'rb'), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
# Encode
|
||||
logger.info('Encoding %s...' % (musicSource.decode(headphones.SYS_ENCODING, 'replace')))
|
||||
logger.debug(subprocess.list2cmdline(cmd))
|
||||
|
||||
stdout, stderr = p.communicate(headphones.ENCODER)
|
||||
process = subprocess.Popen(cmd, startupinfo=startupinfo,
|
||||
stdin=open(os.devnull, 'rb'), stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
stdout, stderr = process.communicate(headphones.ENCODER)
|
||||
|
||||
# error if return code not zero
|
||||
if p.returncode:
|
||||
# Error if return code not zero
|
||||
if process.returncode:
|
||||
logger.error('Encoding failed for %s' % (musicSource.decode(headphones.SYS_ENCODING, 'replace')))
|
||||
out = stdout if stdout else stderr
|
||||
out = out.decode(headphones.SYS_ENCODING, 'replace')
|
||||
|
||||
Reference in New Issue
Block a user