Can't encode video with Xuggler
Asked Answered
S

1

4

I'm trying to create simple application with Xuggler, which has to encode sequence of pictures into video. I've installed xuggler, as described in official site. Here is example of code (which I've actually found on Xuggler wiki site)

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();

    }

}

After launching, I've got exception:

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)

Could you advise me something to solve this problem? Thanks

Smackdab answered 30/11, 2011 at 14:54 Comment(0)
G
7

Xuggler is complaining that it cannot find a converter for the BufferedImage.

Create the BufferedImage with BufferedImage.TYPE_3BYTE_BGR instead of BufferedImage.TYPE_INT_RGB

See http://wiki.xuggle.com/Encoding_Video_from_a_sequence_of_Images for more information

Globeflower answered 30/11, 2011 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.