Skip to content

Commit

Permalink
LPS-26138 Upgrade Liferay code to work with Xuggler 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
juangon authored and brianchandotcom committed May 11, 2012
1 parent 452bfc4 commit c3d3d7c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 37 deletions.
Expand Up @@ -169,7 +169,7 @@ protected void doConvert() throws Exception {
}

@Override
protected int getAudioBitRate(int originalBitRate) {
protected int getAudioBitRate(ICodec outputICodec,int originalBitRate) {
return getProperty(originalBitRate, _audioBitRate, AUDIO_BIT_RATE_MAX);
}

Expand Down
Expand Up @@ -44,6 +44,7 @@
import java.io.File;
import java.io.FileOutputStream;

import java.util.List;
import java.util.Properties;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -416,10 +417,16 @@ protected void flush(
}
}

protected int getAudioBitRate(int originalBitRate) {
protected int getAudioBitRate(ICodec outputICodec, int originalBitRate) {
if ((originalBitRate == 0) || (originalBitRate > AUDIO_BIT_RATE_MAX)) {
originalBitRate = AUDIO_BIT_RATE_DEFAULT;
}

if (outputICodec.getID().equals(ICodec.ID.CODEC_ID_VORBIS)){
if (originalBitRate < 64000){
originalBitRate = 64000;
}
}

return originalBitRate;
}
Expand Down Expand Up @@ -455,6 +462,25 @@ protected ICodec getAudioEncodingICodec(IContainer outputIContainer) {

return null;
}

protected Format getAudioEncodingSampleFormat(ICodec outputCodec,
IStreamCoder inputStreamCoder) {

Format returnFormat = null;
Format preferredFormat = inputStreamCoder.getSampleFormat();
System.out.println("Preferido:"+preferredFormat);
List<Format> formats = outputCodec.getSupportedAudioSampleFormats();
for (Format format : formats) {
System.out.println("A comprobar:"+format.toString());
returnFormat = format;
if (format == preferredFormat) {
System.out.println("Coinciden!!");
break;
}
}

return returnFormat;
}

protected int getAudioSampleRate() {
return AUDIO_SAMPLE_RATE_DEFAULT;
Expand Down Expand Up @@ -590,7 +616,7 @@ protected void openContainer(
int value = 0;

if (writeContainer) {
value = iContainer.open(url, IContainer.Type.WRITE, null);
value = iContainer.open(url, IContainer.Type.WRITE, null);
}
else {
value = iContainer.open(url, IContainer.Type.READ, null);
Expand All @@ -610,7 +636,15 @@ protected void openStreamCoder(IStreamCoder iStreamCoder) throws Exception {
if ((iStreamCoder != null) &&
(iStreamCoder.getCodecType() != ICodec.Type.CODEC_TYPE_UNKNOWN)) {

if (iStreamCoder.open() < 0) {
// some codecs require experimental mode to be set, and so we set it
// here.
if (iStreamCoder
.setStandardsCompliance(IStreamCoder.CodecStandardsCompliance.COMPLIANCE_EXPERIMENTAL) < 0) {
throw new RuntimeException(
"could not set compliance mode to experimental");
}

if (iStreamCoder.open(null, null) < 0) {
throw new RuntimeException("Unable to open coder");
}
}
Expand All @@ -625,21 +659,53 @@ protected void prepareAudio(
String outputURL, int index)
throws Exception {

IStream outputIStream = outputIContainer.addNewStream(index);
ICodec iCodec = getAudioEncodingICodec(outputIContainer);

if (iCodec == null) {
iCodec = ICodec.guessEncodingCodec(
null, null, outputURL, null, inputICodecType);
}

if (iCodec == null) {
throw new RuntimeException(
"Unable to determine " + inputICodecType + " encoder for " +
outputURL);
}

IStream outputIStream = outputIContainer.addNewStream(iCodec);

outputIStreams[index] = outputIStream;

IStreamCoder outputIStreamCoder = outputIStream.getStreamCoder();

outputIStreamCoders[index] = outputIStreamCoder;

Format sampleFormat = getAudioEncodingSampleFormat(iCodec, inputIStreamCoder);

System.out.println("Establecemos formato a "+sampleFormat.toString());

outputIStreamCoder.setSampleFormat(sampleFormat);

/*Format preferredFormat = inputIStreamCoder.getSampleFormat();
System.out.println("Formato preferido:"+preferredFormat.toString());
List<Format> formats = iCodec.getSupportedAudioSampleFormats();
for (Format format : formats) {
System.out.println("Formato a comprobar:"+format.toString());
outputIStreamCoder.setSampleFormat(format);
if (format == preferredFormat) {
System.out.println("Formato "+format.toString()+" es igual que el preferido");
break;
}
}*/

int bitRate = inputIStreamCoder.getBitRate();

if (_log.isInfoEnabled()) {
_log.info("Original audio bitrate " + bitRate);
}

bitRate = getAudioBitRate(bitRate);
bitRate = getAudioBitRate(iCodec, bitRate);

if (_log.isInfoEnabled()) {
_log.info("Modified audio bitrate " + bitRate);
Expand All @@ -652,31 +718,19 @@ protected void prepareAudio(

outputIStreamCoder.setChannels(channels);

ICodec iCodec = getAudioEncodingICodec(outputIContainer);

if (iCodec == null) {
iCodec = ICodec.guessEncodingCodec(
null, null, outputURL, null, inputICodecType);
}

if (iCodec == null) {
throw new RuntimeException(
"Unable to determine " + inputICodecType + " encoder for " +
outputURL);
}

outputIStreamCoder.setCodec(iCodec);

outputIStreamCoder.setGlobalQuality(0);
outputIStreamCoder.setSampleRate(getAudioSampleRate());

iAudioResamplers[index] = createIAudioResampler(
inputIStreamCoder, outputIStreamCoder);

inputIAudioSamples[index] = IAudioSamples.make(
1024, inputIStreamCoder.getChannels());
outputIAudioSamples[index] = IAudioSamples.make(
1024, outputIStreamCoder.getChannels());
inputIAudioSamples[index] = IAudioSamples.make(1024,
inputIStreamCoder.getChannels(),
inputIStreamCoder.getSampleFormat());
outputIAudioSamples[index] = IAudioSamples.make(1024,
outputIStreamCoder.getChannels(),
outputIStreamCoder.getSampleFormat());
}

protected IAudioSamples resampleAudio(
Expand Down
Expand Up @@ -339,7 +339,15 @@ protected void prepareVideo(
ICodec.Type inputICodecType, String outputURL, int index)
throws Exception {

IStream outputIStream = outputIContainer.addNewStream(index);
ICodec iCodec = getVideoEncodingICodec(inputICodecType, outputURL);

if (iCodec == null) {
throw new RuntimeException(
"Unable to determine " + inputICodecType + " encoder for " +
outputURL);
}

IStream outputIStream = outputIContainer.addNewStream(iCodec);

outputIStreams[index] = outputIStream;

Expand All @@ -361,16 +369,6 @@ protected void prepareVideo(

outputIStreamCoder.setBitRate(bitRate);

ICodec iCodec = getVideoEncodingICodec(inputICodecType, outputURL);

if (iCodec == null) {
throw new RuntimeException(
"Unable to determine " + inputICodecType + " encoder for " +
outputURL);
}

outputIStreamCoder.setCodec(iCodec);

IRational iRational = inputIStreamCoder.getFrameRate();

if (_log.isInfoEnabled()) {
Expand All @@ -388,7 +386,7 @@ protected void prepareVideo(
}

outputIStreamCoder.setFrameRate(iRational);

if (inputIStreamCoder.getHeight() <= 0) {
throw new RuntimeException(
"Unable to determine height for " + _inputURL);
Expand Down
4 changes: 3 additions & 1 deletion portal-impl/src/portal.properties
Expand Up @@ -6662,7 +6662,7 @@
xuggler.ffpreset.cmp=+chroma
xuggler.ffpreset.coder=0
xuggler.ffpreset.flags=+loop
xuggler.ffpreset.flags2=-wpred-dct8x8+mbtree
#xuggler.ffpreset.flags2=-wpred-dct8x8+mbtree
xuggler.ffpreset.i_qfactor=0.71
xuggler.ffpreset.me_method=umh
xuggler.ffpreset.me_range=16
Expand All @@ -6674,6 +6674,8 @@
xuggler.ffpreset.subq=8
xuggler.ffpreset.trellis=0
xuggler.ffpreset.wpredp=0
xuggler.ffpreset.8x8dct=0
xuggler.ffpreset.mbtree=1

##
## JSP
Expand Down

0 comments on commit c3d3d7c

Please sign in to comment.