JMF で音声形式を変更したけど,フォーマットが期待外れだった
Windows XP Startup.wav を mp3 にしたが,MPEG2-LayerII となっている.ファイルサイズは10分の1以下になっている.Windows XP Shutdown.mp3 は ffmpeg.exe の出力で,こちらは MPEG2-LayerIII だ.
[Windows XP Startup.mp3] MPEG2-LayerII 22.05kHz 64.00kb/s CBR Stereo 184f 00:00:04.806 (4.806sec) / 38,452Bytes [Windows XP Startup.wav] PCM 22.05kHz 16Bit 2ch 705.60kb/s [RIFF(WAVE)] 00:00:04.814 (4.814sec) / 424,644Bytes [Windows XP Shutdown.mp3] MPEG2-LayerIII 22.05kHz 64.00kb/s CBR JointStereo/MS 125f ID3v2 00:00:03.265 (3.265sec) / 26,154Bytes 真空波動研Lite 081122 / DLL 081122
package test; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.media.CannotRealizeException; import javax.media.ControllerEvent; import javax.media.ControllerListener; import javax.media.NoDataSinkException; import javax.media.NoProcessorException; import javax.media.protocol.DataSource; import javax.media.Processor; import javax.media.DataSink; import javax.media.EndOfMediaEvent; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Format; import javax.media.ProcessorModel; import javax.media.format.AudioFormat; import javax.media.protocol.ContentDescriptor; import javax.media.protocol.FileTypeDescriptor; public class AudioConvert implements ControllerListener { public Processor processor; public DataSource source; public DataSink sink; public AudioConvert() throws MalformedURLException, IOException, NoProcessorException, CannotRealizeException, NoDataSinkException { File sfile = new File("resource/Windows XP Startup.wav"); MediaLocator slocator = new MediaLocator(sfile.toURL()); Format formats[] = new Format[1]; formats[0] = new AudioFormat(AudioFormat.MPEG); FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MPEG_AUDIO); // ContentDescriptor outputType = new ContentDescriptor("resource/audio.mpeg"); // ContentDescriptor outputType = // new ContentDescriptor(FileTypeDescriptor.MPEG_AUDIO); processor = Manager.createRealizedProcessor( new ProcessorModel(slocator, formats, outputType)); processor.addControllerListener(this); source = processor.getDataOutput(); File dfile = new File("resource/Windows XP Startup.mp3"); MediaLocator dlocator = new MediaLocator(dfile.toURL()); sink = Manager.createDataSink(source, dlocator); sink.open(); sink.start(); processor.start(); } public void controllerUpdate(ControllerEvent e) { if (e instanceof EndOfMediaEvent) { //StopEvent processor.stop(); processor.close(); sink.close(); System.exit(0); } } public static void main(String[] args) { try { AudioConvert conv = new AudioConvert(); } catch (MalformedURLException ex) { Logger.getLogger(AudioConvert.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AudioConvert.class.getName()).log(Level.SEVERE, null, ex); } catch (NoProcessorException ex) { Logger.getLogger(AudioConvert.class.getName()).log(Level.SEVERE, null, ex); } catch (CannotRealizeException ex) { Logger.getLogger(AudioConvert.class.getName()).log(Level.SEVERE, null, ex); } catch (NoDataSinkException ex) { Logger.getLogger(AudioConvert.class.getName()).log(Level.SEVERE, null, ex); }finally{ System.exit(0); } } }