How to make convert operation from .MOV to 3GP in Java

假装没事ソ 提交于 2019-12-08 06:28:11

问题


I wanna convert ".MOV" extentioned files to 3GP extentioned Files in java. Currently i m using Java Media Framework for creation opetion of .MOV file. But now my need is converting these videos to 3GP. I googled my issue but i couldnt get any solution. How can i do this? Any help will be appreciated.


回答1:


I suggest that you use xuggler (java wrapper library for ffmpeg). With their bundled ffmpeg you can test one of your videos with this command.

ffmpeg -i input.mov -acodec libamr_nb -ar 8000 -b 120000 -vcodec h263 -ab 10.2k -ac 1 output.3gp
Here is a simple class you can use with xuggler
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("3gp", args[1], null);
        IContainer container = writer.getContainer();
        container.open(args[1], IContainer.Type.WRITE, outFormat);
        writer.addVideoStream(0, 0, ICodec.findEncodingCodecByName("h263"), 320, 240);
        writer.addAudioStream(1, 0, ICodec.findEncodingCodecByName("libamr_nb"), 1, 8000);
        reader.addListener(writer);
        while (reader.readPacket() == null);
    }
}
If your source audio sample rate and channels are not equal you will need to add an audio resampler (also ez to do with xuggler)



来源:https://stackoverflow.com/questions/2768672/how-to-make-convert-operation-from-mov-to-3gp-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!