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
usingToolFactory.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:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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: