File source = new File("source.mp4"); File target = new File("target.mp3"); AudioAttributes audioAttributes = new AudioAttributes(); audioAttributes.setCodec("libmp3lame") .setBitRate(new Integer(128000)) .setChannels(new Integer(2)) .setSamplingRate(new Integer(44100)); EncodingAttributes encodingAttributes = new EncodingAttributes(); encodingAttributes.setFormat("mp3") .setAudioAttributes(audioAttributes); Encoder encoder = new Encoder(); encoder.encode(source, target, encodingAttributes);
Encoder encoder = new Encoder(); EncodingAttributes attributes = new EncodingAttributes(); attributes.setFormat("wav"); AudioAttributes audio = new AudioAttributes(); audio.setBitRate(new Integer(64000)); audio.setChannels(new Integer(1)); audio.setSamplingRate(new Integer(22050)); attributes.setAudioAttributes(audio); File source = new File("mysong.mp3"); File target = new File("mysong.wav"); try { encoder.encode(source, target, attributes); } catch (IllegalArgumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InputFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (EncoderException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
public class VideoConvert { public static void main(String[] args) throws IOException { File source = new File("D:\\video\\mp4\\Sample.ogv"); File target = new File("D:\\video\\ogv\\Sample.mp4"); AudioAttributes audio = new AudioAttributes(); audio.setCodec(AudioAttributes.DIRECT_STREAM_COPY); audio.setBitRate(new Integer(128000)); audio.setSamplingRate(new Integer(44100)); audio.setChannels(new Integer(2)); VideoAttributes video = new VideoAttributes(); video.setBitRate(new Integer(160000)); video.setFrameRate(new Integer(15)); video.setCodec("mpeg4"); video.setCodec(VideoAttributes.DIRECT_STREAM_COPY); EncodingAttributes attrs = new EncodingAttributes(); attrs.setFormat("mp4"); attrs.setAudioAttributes(audio); attrs.setVideoAttributes(video); Encoder encoder = new Encoder(); try { encoder.encode(source, target, attrs); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InputFormatException e) { e.printStackTrace(); } catch (EncoderException e) { e.printStackTrace(); }
AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); if (quality.equalsIgnoreCase("high")) {
try { EncodingAttributes attr = new EncodingAttributes(); attr.setAudioAttributes(new AudioAttributes()); //default values attr.setVideoAttributes(new VideoAttributes()); //default values attr.setFormat("wav"); //this is the target format I am trying to achieve //b.wma is a file I brought to the project File wma = new File("Resources\\b.wma"); //target.wav is the created file I'll achieve after the encode, which gets used to make a Clip File target = new File("Resources\\target.wav"); Encoder encoder = new Encoder(); //this will show you all supported encoding / decoding formats //String[] list = encoder.getSupportedEncodingFormats(); //String[] list = encoder.getSupportedDecodingFormats() encoder.encode(wma, target, attr); AudioInputStream is = AudioSystem.getAudioInputStream(target); Clip clip = AudioSystem.getClip(); clip.open(is); clip.setFramePosition(0); clip.start(); } catch (IllegalArgumentException | EncoderException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); }
int bitRate = 190000;// this could be 128, 160, 190 kbps, etc.. AudioAttributes audio = new AudioAttributes(); audio.setCodec("libmp3lame"); audio.setBitRate(bitRate);