本文介绍了如何在 Java 中进行从 .MOV 到 3GP 的转换操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 java 中将.MOV"扩展文件转换为 3GP 扩展文件.目前我正在使用 Java 媒体框架来创建 .MOV 文件.但现在我需要将这些视频转换为 3GP.我用谷歌搜索了我的问题,但找不到任何解决方案.我怎样才能做到这一点?任何帮助将不胜感激.

解决方案

我建议你使用 xuggler(ffmpeg 的 java 包装库).使用他们捆绑的 ffmpeg,您可以使用此命令测试您的视频之一.ffmpeg -i input.mov -acodec libamr_nb -ar 8000 -b 120000 -vcodec h263 -ab 10.2k -ac 1 output.3gp

这是一个可以与 xuggler 一起使用的简单类公共类 AnyMediaConverter {公共无效主(字符串 [] args){//假设如下:arg0是输入文件,arg1是输出文件IMediaReader reader = ToolFactory.makeReader(args[0]);IMediaWriter writer = ToolFactory.makeWriter(args[1], reader);writer.open();writer.setForceInterleave(真);IContainerFormat outFormat = IContainerFormat.make();outFormat.setOutputFormat("3gp", args[1], null);IContainer 容器 = 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);}}

如果您的源音频采样率和通道不相等,您将需要添加一个音频重采样器(也与 xuggler 相关)

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.

解决方案

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)

这篇关于如何在 Java 中进行从 .MOV 到 3GP 的转换操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 13:32