xuggler

Transcode mp4 to flv using Xuggler

This is an example that demonstrates how to transcode mp4 to flv using Xuggler. This is a very easy and common transcoding.

To do that, one should follow these basic steps:

  • Create a IMediaReader to read the video file.
  • Create an IMediaWriter using ToolFactory.makeWriter.
  • Add a writer to the reader, to create the output file
  • Create a IMediaViewer with stats enabled
  • Add a viewer to the reader, to see the decoded media
  • Read and decode packets from the source file and dispatch decoded audio and video to the writer .

Let’s see the code:

package com.javacodegeeks.xuggler;

import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;

public class TranscodingExample {

    private static final String inputFilename = "c:/myvideo.mp4";
    private static final String outputFilename = "c:/myvideo.flv";

    public static void main(String[] args) {

  // create a media reader

  IMediaReader mediaReader = 

   ToolFactory.makeReader(inputFilename);

  // create a media writer

  IMediaWriter mediaWriter = 

   ToolFactory.makeWriter(outputFilename, 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);

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

    }

}

This was an example on how to transcode mp4 to flv using Xuggler.

Related Article:

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button