Converting into FLV using Java

后端 未结 3 781
庸人自扰
庸人自扰 2021-01-03 10:50

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 t

相关标签:
3条回答
  • 2021-01-03 11:40

    There is a wrapper for ffmpeg that plugs into JMF: Fobs4JMF

    0 讨论(0)
  • 2021-01-03 11:44

    None in Java comes directly to mind, even Java's own media framework JMF doesn't support FLV, but you may find this overview of Open Source Flash Projects useful. If any non-Java commandline tool turns out to be useful for you, then you could execute it from inside Java using Runtime#exec() (tutorial here) or preferably ProcessBuilder (tutorial here).

    0 讨论(0)
  • 2021-01-03 11:49

    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)

    0 讨论(0)
提交回复
热议问题