سؤال

I'm trying to convert a video using Java and Xuggler. But when im trying to run this code I get the following error message.

Do I need to specify the format manually or is it mp4 per default?

converting Exception in thread "main" java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.

at javax.sound.sampled.AudioSystem.getLine(Unknown Source)
at com.xuggle.mediatool.MediaViewer.getJavaSoundLine(MediaViewer.java:730)
at com.xuggle.mediatool.MediaViewer.getAudioQueue(MediaViewer.java:575)
at com.xuggle.mediatool.MediaViewer.onAddStream(MediaViewer.java:440)
at com.xuggle.mediatool.AMediaToolMixin.onAddStream(AMediaToolMixin.java:78)
at com.xuggle.mediatool.MediaReader.getStreamCoder(MediaReader.java:375)
at com.xuggle.mediatool.MediaReader.readPacket(MediaReader.java:461)
at at.jku.tk.mms.xuggler.VideoTranscoderApp.transcode(VideoTranscoderApp.java:44)
at at.jku.tk.mms.xuggler.VideoTranscoderApp.main(VideoTranscoderApp.java:53)


    IMediaReader mediaReader = 
           ToolFactory.makeReader(source.getAbsolutePath());

    // create a media writer
    IMediaWriter mediaWriter = 
           ToolFactory.makeWriter(target.getAbsolutePath(), mediaReader);

    // add a writer to the reader, to create the output file
    mediaReader.addListener(mediaWriter);

    // create a media viewer with stats enabled
    IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
    System.out.println("converting");
    // add a viewer to the reader, to see the decoded media
    mediaReader.addListener(mediaViewer);

    // read and decode packets from the source file and
    // and dispatch decoded audio and video to the writer
    while (mediaReader.readPacket() == null) ;
}

public static void main(String[] args) {
    File source = new File(args[0]);
    if (source.canRead()) {
        File target = new File(args[1]);
        VideoTranscoderApp transcoder = new VideoTranscoderApp(source,
                target);
        transcoder.transcode();
    }
}
هل كانت مفيدة؟

المحلول

If you specify the output file as "xxxx.mp4" then Xuggler will automatically detect you are trying to encode an MP4. It will draw any conclusions it can from that fact, such as the video codec and sample format to use. You would be wise to not rely on this, and manually set a sample rate, channel count, bitrate, sample format and codec for your audio, and set a frame rate, frame size, codec and bitrate for your video.

To do this you need to use some functions to set properties on the IMediaWriter involved, its underlying IContainer, its underlying IStream's and their underlying IStreamCoder's.

Now, here's the thing: sometimes the input file will perfectly match the wanted output file and Xuggler will process the encoding without problems. But let's say the input has a different sample format or sample rate, then encoding it into the output will cause errors or malformed output files.

You would be wise to insert an IAudioResampler in between input and output, which will convert the audio from its source format to the wanted output format.

I believe that may be the problem here. The sample format mentioned in your error, namely PCM_SIGNED, I believe is not usually used for MP3 or AAC audio within an MP4 container. An IAudioResampler will be able to convert it to a better suited sample format.

You can find an example on how to use the IAudioResampler over here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top