3

我正在尝试使用 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)

你能给我一些解决这个问题的建议吗?谢谢

4

1 回答 1

6

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

BufferedImage.TYPE_3BYTE_BGR使用而不是创建 BufferedImageBufferedImage.TYPE_INT_RGB

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

于 2011-11-30T19:36:17.217 回答