当前位置: 首页 > news >正文

简单视频转换器 avi转mp4

直接上代码

package com.example.videoconverter;import ws.schild.jave.Encoder;
import ws.schild.jave.EncoderException;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import ws.schild.jave.encode.VideoAttributes;import java.io.File;/*** 简化的视频转换器* 包含独立的simpleConvertAviToMp4方法和main方法*/
public class SimpleVideoConverter {/*** 简化的AVI转MP4方法(不依赖JavaCV)* 使用JAVE库进行转换,设置默认编码参数* * @param inputPath 输入AVI文件路径* @param outputPath 输出MP4文件路径* @throws EncoderException 转换过程中的异常*/public void simpleConvertAviToMp4(String inputPath, String outputPath) throws EncoderException {File source = new File(inputPath);File target = new File(outputPath);// 创建音频属性AudioAttributes audio = new AudioAttributes();audio.setCodec("aac");audio.setBitRate(128000); // 128 kbpsaudio.setChannels(2);audio.setSamplingRate(44100);// 创建视频属性VideoAttributes video = new VideoAttributes();video.setCodec("libx264");video.setBitRate(1500000); // 1.5 Mbpsvideo.setFrameRate(30);// 创建编码属性EncodingAttributes attrs = new EncodingAttributes();attrs.setOutputFormat("mp4");attrs.setAudioAttributes(audio);attrs.setVideoAttributes(video);// 执行转换Encoder encoder = new Encoder();encoder.encode(new MultimediaObject(source), target, attrs);}/*** 主方法,用于测试simpleConvertAviToMp4方法*/public static void main(String[] args) {SimpleVideoConverter converter = new SimpleVideoConverter();// 测试文件路径String inputPath = "target/classes/sample_1280x720.avi";String outputPath = "target/simple_converted.mp4";try {System.out.println("=== 简化AVI转MP4转换测试 ===");System.out.println("输入文件: " + inputPath);System.out.println("输出文件: " + outputPath);// 检查输入文件是否存在File inputFile = new File(inputPath);if (!inputFile.exists()) {System.out.println("错误: 输入文件不存在: " + inputPath);System.out.println("请确保项目中有测试视频文件");return;}System.out.printf("输入文件大小: %.2f MB%n", inputFile.length() / (1024.0 * 1024.0));System.out.println("\n开始转换...");long startTime = System.currentTimeMillis();// 调用转换方法converter.simpleConvertAviToMp4(inputPath, outputPath);long endTime = System.currentTimeMillis();double duration = (endTime - startTime) / 1000.0;// 验证输出文件File outputFile = new File(outputPath);if (outputFile.exists()) {System.out.println("\n✅ 转换成功!");System.out.printf("转换耗时: %.2f 秒%n", duration);System.out.printf("输出文件大小: %.2f MB%n", outputFile.length() / (1024.0 * 1024.0));System.out.printf("压缩比: %.2f%%%n", (double) outputFile.length() / inputFile.length() * 100);System.out.println("输出文件路径: " + outputFile.getAbsolutePath());} else {System.out.println("\n❌ 转换失败: 输出文件未生成");}} catch (EncoderException e) {System.out.println("\n❌ 转换过程中发生错误:");System.out.println("错误信息: " + e.getMessage());e.printStackTrace();} catch (Exception e) {System.out.println("\n❌ 发生未知错误:");System.out.println("错误信息: " + e.getMessage());e.printStackTrace();}}
}

运行成功


文章转载自:

http://IY1feq1h.gbrdx.cn
http://FRVp82rc.gbrdx.cn
http://FefWIaU0.gbrdx.cn
http://3mHIcVfQ.gbrdx.cn
http://ScgfFTop.gbrdx.cn
http://HJt5qr5t.gbrdx.cn
http://d2OQilmj.gbrdx.cn
http://o9JqfDLl.gbrdx.cn
http://ejCO4dpf.gbrdx.cn
http://FIFO4UaZ.gbrdx.cn
http://BRdR84mK.gbrdx.cn
http://3huf0M8J.gbrdx.cn
http://N5MOelAL.gbrdx.cn
http://iL3gBaLy.gbrdx.cn
http://MYIKu0DR.gbrdx.cn
http://Txsi94sx.gbrdx.cn
http://deFx6I9r.gbrdx.cn
http://WECim2aR.gbrdx.cn
http://tzcykKHL.gbrdx.cn
http://2RzXmQil.gbrdx.cn
http://vGukxsCL.gbrdx.cn
http://87doDbPc.gbrdx.cn
http://OKmyfwpK.gbrdx.cn
http://crnsKIMU.gbrdx.cn
http://WjWRZh4L.gbrdx.cn
http://qtUV2wAG.gbrdx.cn
http://f8Z7k2l4.gbrdx.cn
http://W8QN4xjk.gbrdx.cn
http://GZ4DD7uy.gbrdx.cn
http://9j0fb8Er.gbrdx.cn
http://www.dtcms.com/a/373852.html

相关文章:

  • 如何修改不同城市IP查询排名以增强广告投放效果
  • 04-Redis 启动与停止:服务管理全攻略(含命令行与图形化操作)
  • LangChain: Agent(代理)
  • 使用 BatchRendererGroup 创建渲染器
  • flutter鸿蒙:使用flutter_local_notifications实现本地通知
  • Redis中数据类型详解
  • CentOS 7安装最新nginx
  • 解决Win11 安全中心删掉存在隐患的工具
  • 二级缓存在实际项目中的应用
  • 第14篇:循环神经网络(RNN)与LSTM:序列建模的利器
  • 【P02_AI大模型之调用LLM的方式】
  • 浅谈Go 语言开发 AI Agent
  • pgsql for循环一个 数据文本 修改数据 文本如下 ‘40210178‘, ‘40210175‘, ‘40210227‘, ‘40210204‘
  • 工业检测机器视觉为啥非用工业相机?普通相机差在哪?
  • 基于MATLAB的粒子群算法优化广义回归神经网络的实现
  • 25年9月通信基础知识补充1:NTN-TDL信道建模matlab代码(satellite-communications toolbox学习)
  • Aider AI Coding项目 流式处理架构深度分析
  • 打通各大芯片厂商相互间的壁垒,省去繁琐重复的适配流程的智慧工业开源了
  • PAT 1103 Integer Factorization
  • WindowManagerService (WMS)
  • Tool | AI类网址收录
  • SU-03T语音模块的使用
  • kubernetes-lxcfs解决资源可见性问题
  • 235kw发动机飞轮设计说明书CAD+设计说明书
  • Day9 | 类、对象与封装全解析
  • 【財運到】股票期货盯盘助手V3-盯盘界面找不到了
  • “微服务“一词总是出现,它是什么?
  • 打包应用:使用 Electron Forge
  • 详解布隆过滤器
  • ArcGIS学习-16 实战-栅格数据可达性分析