Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting into FLV using Java

does anybody know how to convert any kind of video format into flv using java, i have been searching for a java api for converting video but it seems that there is no such thing but there might be a way to do it, i mean to make something like youtube service does converting the videos, but using java, i need a web application that can show videos into FLv Format but to be uploaded in any format, if somebody has made something like this please let me know how or any idea,

thanks.

like image 743
Alvaro Castro Avatar asked Jul 22 '26 00:07

Alvaro Castro


1 Answers

Using xuggler, here is a simple piece of code to do exactly what you asked for:

public class AnyMediaConverter {
    public void main(String[] args) {
        //assumes the following: arg0 is input file and arg1 is output file
        IMediaReader reader = ToolFactory.makeReader(args[0]);
        IMediaWriter writer = ToolFactory.makeWriter(args[1], reader);
        writer.open();
        writer.setForceInterleave(true);
        IContainerFormat outFormat = IContainerFormat.make();
        outFormat.setOutputFormat("flv", args[1], null);
        IContainer container = writer.getContainer();
        container.open(args[1], IContainer.Type.WRITE, outFormat);
        writer.addVideoStream(0, 0, ICodec.findEncodingCodecByName("flv"), 320, 240);
        writer.addAudioStream(1, 0, ICodec.findEncodingCodecByName("libmp3lame"), 2, 44100);
        reader.addListener(writer);
        while (reader.readPacket() == null);
    }
}
now try doing that in JMF or FMJ or whatever (if you want a headache)
like image 80
Paul Gregoire Avatar answered Jul 23 '26 13:07

Paul Gregoire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!