Topic: 一个JMF的问题请教 |
Print this page |
1.一个JMF的问题请教 | Copy to clipboard |
Posted by: losfound Posted on: 2005-12-14 21:20 我写了一个简单程序,读取一个mpg文件,转换成quicktime格式。 在debug时成功,release运行失败,不知道什么原因。 程序运行过程中会产生一个临时文件butter.nonstreamable.mov,debug和release都可以的,不同的是release运行时最后的butter.mov文件大小是零。 做过JMF的麻烦指教一下,下面是源代码,前面的import省略了: public class DataSinkSample { private JFrame frame; DataSink filewriter = null; Processor processor = null; public static void main(String args[]) { try { DataSinkSample window = new DataSinkSample(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public DataSinkSample() { initialize(); } private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 500, 375); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton(); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String mediaFile = "file://f://butterfly.mpg"; MediaLocator mrl = null; try { URL url = new URL(mediaFile); mediaFile = url.toExternalForm(); mrl = new MediaLocator(mediaFile); if (mrl == null) { System.exit(1); } } catch (MalformedURLException mue) { System.exit(1); } Format formats[] = new Format[2]; formats[0] = new AudioFormat(AudioFormat.IMA4); formats[1] = new VideoFormat(VideoFormat.JPEG); FileTypeDescriptor outputType = new FileTypeDescriptor( FileTypeDescriptor.QUICKTIME); try { processor = Manager .createRealizedProcessor(new ProcessorModel(mrl, formats, outputType)); } catch (CannotRealizeException ex) { System.out.println(ex.getMessage()); System.exit(1); } catch (IOException ex) { System.exit(1); } catch (NoProcessorException ex) { System.out.println(ex.getMessage()); System.exit(1); } DataSource source = processor.getDataOutput(); MediaLocator dest = new MediaLocator("file://f://butter.mov"); try { filewriter = Manager.createDataSink(source, dest); filewriter.open(); filewriter.start(); } catch (NoDataSinkException ex) { System.out.println(ex.getMessage()); filewriter.close(); System.exit(1); } catch (IOException ex) { filewriter.close(); System.exit(1); } catch (SecurityException ex) { filewriter.close(); System.exit(1); } processor.addControllerListener(new ControllerAdapter() { /* * (非 Javadoc) * * @see javax.media.ControllerAdapter#start(javax.media.StartEvent) */ public void start(StartEvent arg0) { // TODO 自动生成方法存根 super.start(arg0); } /* * (非 Javadoc) * * @see javax.media.ControllerAdapter#stop(javax.media.StopEvent) */ public void stop(StopEvent arg0) { // TODO 自动生成方法存根 try{ filewriter.stop(); }catch(IOException ex){ System.out.println(ex.getMessage()); } System.out.println("write ok"); //super.stop(arg0); } }); processor.start(); } }); button.setText("Start"); frame.getContentPane().add(button, BorderLayout.NORTH); final JButton button_1 = new JButton(); button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { processor.close(); } }); button_1.setText("Stop"); frame.getContentPane().add(button_1, BorderLayout.CENTER); } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |