protected void initVideoFrameRateMap(Properties videoProperties) { _videoFrameRateMap = new HashMap<String, IRational>(); for (String previewVideoContainer : _previewVideoContainers) { int numerator = GetterUtil.getInteger( videoProperties.getProperty( PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_FRAME_RATE_NUMERATOR + "[" + previewVideoContainer + "]")); int denominator = GetterUtil.getInteger( videoProperties.getProperty( PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_FRAME_RATE_DENOMINATOR + StringPool.OPEN_BRACKET + previewVideoContainer + StringPool.CLOSE_BRACKET)); if ((numerator > 0) && (denominator > 0)) { IRational iRational = IRational.make(numerator, denominator); _videoFrameRateMap.put(previewVideoContainer, iRational); if (_log.isInfoEnabled()) { _log.info( "Frame rate for " + previewVideoContainer + " set to " + iRational.getNumerator() + "/" + iRational.getDenominator()); } } } }
protected void prepareVideo( IVideoResampler[] iVideoResamplers, IVideoPicture[] inputIVideoPictures, IVideoPicture[] outputIVideoPictures, IStreamCoder inputIStreamCoder, IStreamCoder[] outputIStreamCoders, IContainer outputIContainer, IStream[] outputIStreams, ICodec.Type inputICodecType, String outputURL, int index) throws Exception { IStream outputIStream = outputIContainer.addNewStream(index); outputIStreams[index] = outputIStream; IStreamCoder outputIStreamCoder = outputIStream.getStreamCoder(); outputIStreamCoders[index] = outputIStreamCoder; int bitRate = inputIStreamCoder.getBitRate(); if (_log.isInfoEnabled()) { _log.info("Original video bitrate " + bitRate); } if (bitRate == 0) { bitRate = GetterUtil.getInteger(_videoBitRateMap.get(_outputVideoFormat), _VIDEO_BIT_RATE_DEFAULT); } else if (bitRate > _VIDEO_BIT_RATE_MAX) { bitRate = _VIDEO_BIT_RATE_MAX; } if (_log.isInfoEnabled()) { _log.info("Modified video bitrate " + bitRate); } outputIStreamCoder.setBitRate(bitRate); ICodec iCodec = ICodec.guessEncodingCodec(null, null, outputURL, null, inputICodecType); if (_outputVideoFormat.equals("mp4")) { iCodec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_H264); } if (iCodec == null) { throw new RuntimeException( "Unable to determine " + inputICodecType + " encoder for " + outputURL); } outputIStreamCoder.setCodec(iCodec); IRational iRational = inputIStreamCoder.getFrameRate(); if (_log.isInfoEnabled()) { _log.info( "Original frame rate " + iRational.getNumerator() + "/" + iRational.getDenominator()); } if (_videoFrameRateMap.containsKey(_outputVideoFormat)) { iRational = _videoFrameRateMap.get(_outputVideoFormat); } if (_log.isInfoEnabled()) { _log.info( "Modified frame rate " + iRational.getNumerator() + "/" + iRational.getDenominator()); } outputIStreamCoder.setFrameRate(iRational); if (inputIStreamCoder.getHeight() <= 0) { throw new RuntimeException("Unable to determine height for " + _inputURL); } outputIStreamCoder.setHeight(_height); outputIStreamCoder.setPixelType(Type.YUV420P); outputIStreamCoder.setTimeBase( IRational.make(iRational.getDenominator(), iRational.getNumerator())); if (inputIStreamCoder.getWidth() <= 0) { throw new RuntimeException("Unable to determine width for " + _inputURL); } outputIStreamCoder.setWidth(_width); iVideoResamplers[index] = createIVideoResampler(inputIStreamCoder, outputIStreamCoder, _height, _width); inputIVideoPictures[index] = IVideoPicture.make( inputIStreamCoder.getPixelType(), inputIStreamCoder.getWidth(), inputIStreamCoder.getHeight()); outputIVideoPictures[index] = IVideoPicture.make( outputIStreamCoder.getPixelType(), outputIStreamCoder.getWidth(), outputIStreamCoder.getHeight()); ICodec.ID iCodecID = iCodec.getID(); if (iCodecID.equals(ICodec.ID.CODEC_ID_H264)) { Configuration.configure(_ffpresetProperties, outputIStreamCoder); } }
protected void prepareVideo( IVideoResampler[] iVideoResamplers, IVideoPicture[] inputIVideoPictures, IVideoPicture[] outputIVideoPictures, IStreamCoder inputIStreamCoder, IStreamCoder[] outputIStreamCoders, IContainer outputIContainer, IStream[] outputIStreams, ICodec.Type inputICodecType, String outputURL, int index) throws Exception { 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; IStreamCoder outputIStreamCoder = outputIStream.getStreamCoder(); outputIStreamCoders[index] = outputIStreamCoder; int bitRate = inputIStreamCoder.getBitRate(); if (_log.isInfoEnabled()) { _log.info("Original video bitrate " + bitRate); } bitRate = getVideoBitRate(bitRate); if (_log.isInfoEnabled()) { _log.info("Modified video bitrate " + bitRate); } outputIStreamCoder.setBitRate(bitRate); IRational iRational = inputIStreamCoder.getFrameRate(); if (_log.isInfoEnabled()) { _log.info( "Original frame rate " + iRational.getNumerator() + "/" + iRational.getDenominator()); } iRational = getVideoFrameRate(iRational); if (_log.isInfoEnabled()) { _log.info( "Modified frame rate " + iRational.getNumerator() + "/" + iRational.getDenominator()); } outputIStreamCoder.setFrameRate(iRational); if (inputIStreamCoder.getHeight() <= 0) { throw new RuntimeException("Unable to determine height for " + _inputURL); } if (_height == 0) { _height = inputIStreamCoder.getHeight(); } outputIStreamCoder.setHeight(_height); outputIStreamCoder.setPixelType(Type.YUV420P); outputIStreamCoder.setTimeBase( IRational.make(iRational.getDenominator(), iRational.getNumerator())); if (inputIStreamCoder.getWidth() <= 0) { throw new RuntimeException("Unable to determine width for " + _inputURL); } if (_width == 0) { _width = inputIStreamCoder.getWidth(); } outputIStreamCoder.setWidth(_width); iVideoResamplers[index] = createIVideoResampler(inputIStreamCoder, outputIStreamCoder, _height, _width); inputIVideoPictures[index] = IVideoPicture.make( inputIStreamCoder.getPixelType(), inputIStreamCoder.getWidth(), inputIStreamCoder.getHeight()); outputIVideoPictures[index] = IVideoPicture.make( outputIStreamCoder.getPixelType(), outputIStreamCoder.getWidth(), outputIStreamCoder.getHeight()); ICodec.ID iCodecID = iCodec.getID(); if (iCodecID.equals(ICodec.ID.CODEC_ID_H264)) { Configuration.configure(_ffpresetProperties, outputIStreamCoder); } }