5

I keep getting an exception when I close an IMediaWriter doing a simple transcode. The exception is "java.lang.RuntimeException: error Operation not permitted, failed to write trailer to test.mp3" I get this whenever I call IMediaWriter.close(),Any ideas why I would be getting this for a simple transcoding? Here's the sample code:

IMediaReader reader = null; 
    IMediaWriter writer = null; 
    try { 
        reader = ToolFactory.makeReader("test.wav"); 
        writer = ToolFactory.makeWriter("test.mp3", reader); 
        reader.addListener(writer); 
        while (reader.readPacket() == null) ; 
        reader.close(); 
        writer.close(); 
    } catch (Exception ex) { 
        ex.printStackTrace(); 
    } 
4

1 回答 1

2

这肯定会奏效,因为我面临同样的问题。谢谢你。如果您需要更多说明,请询问...

IMediaReader reader = null; 
    IMediaWriter writer = null; 
    try { 
        reader = ToolFactory.makeReader("sijo.mp4"); 
        writer = ToolFactory.makeWriter("Thomas.flv", reader); 
        reader.addListener(writer); 
        while (reader.readPacket() == null) ; 
        //Should IMediaReader automatically call close(), only if ERROR_EOF (End of File) is returned from readPacket().
        reader.setCloseOnEofOnly(false); 
        //If false the media data will be left in the order in which it is presented to the IMediaWriter.
        //If true IMediaWriter will buffer media data in time stamp order, and only write out data when it has at least one same time or later packet from all streams.
        writer.setForceInterleave(false);
        System.out.println("closed...");
    } catch (Exception ex) { 
        ex.printStackTrace(); 
    }
于 2014-02-12T13:41:21.350 回答