Xuggler - Yash-777/SeleniumDriverAutomation GitHub Wiki

Xuggler: Decode, Encode and Experience Video

Xuggler is a Java library that allows you to decode and encode a variety of media file formats directly from Java.

Supported operating systems

Xuggler consists of a small amount of Java (i.e. architecture independent) code and a large amount of native code that needs to be specifically compiled for different operating systems. That means different binary packages must be used with different operating systems (unlike most Java programs).

  • The good news is that (as of Xuggler 5.2) for the users of the following operating systems, you can effectively ignore that distinction. xuggle‑xuggler.jar have Java code and native code for each of the operating systems.

Xuggler IO: Xuggler uses FFMPEG's libav libraries to do the encoding and decoding of fils. By default FFMPEG can read files, and some other protocols (like http), but it implements all IO itself.

Fortunately FFMPEG comes with a way to extend the data sources it can read; unfortunately it's a call back mechanism. Still, the Xuggler IO library allows you to implement IO callbacks for FFMPEG in the language of your choice (Java) as opposed to native C code.

ICodec.java « File was automatically generated by SWIG and it have A "key" like Codes - ICodec.ID.CODEC_ID_H264 to an IStreamCoder that tells it how to encode or decode data. Use these objects to tell a IStreamCoder you want to use MP4, MP3 or NellyMoser.

Xugglerio_architecture:

Xugglerio_architecture

SWIG « SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Javascript, Perl, PHP, Python, Tcl and Ruby.

Xugglerio_callflow:

Xugglerio_callflow

Video Decoding codes supported to my System:

CODEC_ID_MPEG4, CODEC_ID_H264, 

CODEC_ID_MJPEGB
	an error occurred: cannot encode with codec: CODEC_ID_MJPEGB
	
CODEC_ID_PNG, CODEC_ID_MJPEG, CODEC_ID_JPEGLS
	ERROR org.ffmpeg - [png @ 0000000000385250] Specified pix_fmt is not supported
	
Specifid File Name as -: E:\IMediaWriterVedio.mp4
CODEC_ID_RAWVIDEO
	ERROR org.ffmpeg - [mp4 @ 0000000000317050] track 0: could not find tag, codec not currently supported in container

Xuggler Video File Decoding code CODEC_ID_MPEG4 Firefox error.

  • No video with supported format and MIME type found
  • Video can't be played because the file is corrupt

To solve the problem use CODEC_ID_H264


Examples

class Start extends CaptureScreenToFile implements Runnable {
    public void run() {
        StartRecording();
    }
}

class Stop extends CaptureScreenToFile implements Runnable {
    public void run() {
        stopRecording();
    }
}

public class CaptureScreenToFile {
    
    static IRational FRAME_RATE = IRational.make(25, 1);
    final static Integer numberOfScreens = 300;
    final static String outFile = "E:\\IMediaWriterVedio.mp4";
    volatile static boolean isSTOPRecording = false;
    
    public static void main(String[] args) {
        new Thread( new Start() ).start();
        sleep( 1000 * 2 );
        new Thread( new Stop() ).start();
    }
    
    public void StartRecording() {
    
    try {
        // This is the robot for taking a snapshot of the screen. It's part of Java AWT
        final Robot robot = new Robot();
        final Toolkit toolkit = Toolkit.getDefaultToolkit();
        final Rectangle screenBounds = new Rectangle( toolkit.getScreenSize() );
    
        // First, let's make a IMediaWriter to write the file.
        final IMediaWriter writer = ToolFactory.makeWriter( outFile );
        System.out.println("MP4 File Location : "+outFile);

        // writer.addVideoStream(0, 0, FRAME_RATE, screenBounds.width, screenBounds.height);
        writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, screenBounds.width, screenBounds.height);
    
        // Capturing the screen with in nano-seconds and combing them all as video.
        long startTime = System.nanoTime();
        for (int index = 0; index < numberOfScreens; index++) {
            // take the screen shot
            BufferedImage screen = robot.createScreenCapture(screenBounds);
        
            // convert to the right image type.
            BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR);
        
            // encode the image
            writer.encodeVideo(0, bgrScreen, System.nanoTime()-startTime, TimeUnit.NANOSECONDS);
        
            System.out.println("encoded image: " +index);
        
            // sleep for FrameRate milliseconds
            Thread.sleep((long) (1000 / FRAME_RATE.getDouble()));
        
            if( isSTOPRecording ) {
                writer.close();    break;
            }
        }
        
        // Tell the writer to close and write the trailer if needed
        if( !isSTOPRecording ) {
            writer.close();
        }
    } catch (Throwable e) {
        System.err.println("an error occurred: " + e.getMessage());
    }
    
    }
    protected void stopRecording() {
        System.out.println("Stop Recording...");
        isSTOPRecording = true;
    }
    
    public BufferedImage convertToType(BufferedImage sourceImage, int targetType){
        BufferedImage image;
        /* If the source image is the same type as the target type,
         * then original image is returned.*/
        if (sourceImage.getType() == targetType) {
            return sourceImage;
        }
        /* otherwise new image of the correct type is created 
         * and the content of the source image is copied into the new image.
         */
        else { 
            image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), targetType);
            image.getGraphics().drawImage(sourceImage, 0, 0, null);
        }
        return image;
    }
    protected static void sleep(int millis) {
        try {
            Thread.sleep( millis );
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Xuggler Status:

Xuggler is on hiatus as no one is actively developing it anymore. Sorry. That said, you can always find the source code and start hacking yourself. Good luck!

FFmpeg

FFmpeg is the leading multimedia framework to decode, encode, transcode, mux, demux, stream, filter and play. FFmpeg supports a wide variety of video formats and can utilize hardware acceleration to minimize conversion time.

ffmpeg -i IMediaWriterAudio.mp3 -i IMediaWriterVedio.mp4 -acodec copy -vcodec copy IMediaWriterAudioVedio.mp4