无法使用Xuggler对视频进行编码

时间:2011-11-30 14:54:19

标签: java video xuggler

我正在尝试使用Xuggler创建简单的应用程序,Xuggler必须将图片序列编码为视频。 我已经安装了xuggler,如官方网站所述。 这是代码示例(我实际上在Xuggler wiki网站上找到了)

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;

import static com.xuggle.xuggler.Global.DEFAULT_TIME_UNIT;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;


public class Test {

    private static final Logger log = LoggerFactory.getLogger(Test.class);
    {
        log.trace("<init>");
    }

    public static void main(String[] args) {

        final long duration = DEFAULT_TIME_UNIT.convert( 3, SECONDS );

        final int videoStreamIndex = 0;
        final int videoStreamId = 0;
        final long frameRate = DEFAULT_TIME_UNIT.convert(15, MILLISECONDS);
        final int width = 320;
        final int height = 200;

        long nextFrameTime = 0;

        final IMediaWriter writer = ToolFactory.makeWriter("/out.mov");

        writer.addVideoStream(videoStreamIndex, videoStreamId, 
                      width, height);

        while ( nextFrameTime < duration )
            {
                BufferedImage frame = new BufferedImage( 320, 200, BufferedImage.TYPE_INT_RGB );
                Graphics2D gr = (Graphics2D) frame.getGraphics();
                gr.setColor(Color.RED);
                gr.drawLine(0, 0, 200, 200);
                writer.encodeVideo(videoStreamIndex, frame, nextFrameTime, 
                       DEFAULT_TIME_UNIT);
                nextFrameTime += frameRate;
            }

        writer.close();

    }

}

发布后,我有例外:

Exception in thread "main" java.lang.UnsupportedOperationException: No converter "null" found.
    at com.xuggle.xuggler.video.ConverterFactory.createConverter(ConverterFactory.java:313)
    at com.xuggle.mediatool.MediaWriter.convertToPicture(MediaWriter.java:967)
    at com.xuggle.mediatool.MediaWriter.encodeVideo(MediaWriter.java:812)
    at Test.main(Test.java:48)

你能告诉我一些解决这个问题的方法吗? 感谢

1 个答案:

答案 0 :(得分:6)

Xuggler抱怨它找不到BufferedImage的转换器。

使用BufferedImage.TYPE_3BYTE_BGR而非BufferedImage.TYPE_INT_RGB

创建BufferedImage

有关详细信息,请参阅http://wiki.xuggle.com/Encoding_Video_from_a_sequence_of_Images