Java 实现视频Mov转Mp4

package useful;

import java.io.File;

import java.io.IOException;

import it.sauronsoftware.jave.AudioAttributes;

import it.sauronsoftware.jave.Encoder;

import it.sauronsoftware.jave.EncodingAttributes;

import it.sauronsoftware.jave.VideoAttributes;

import net.bramp.ffmpeg.FFmpeg;

import net.bramp.ffmpeg.FFmpegExecutor;

import net.bramp.ffmpeg.FFprobe;

import net.bramp.ffmpeg.builder.FFmpegBuilder;

//import ws.schild.jave.Encoder;

//import ws.schild.jave.MultimediaObject;

//import ws.schild.jave.encode.AudioAttributes;

//import ws.schild.jave.encode.EncodingAttributes;

//import ws.schild.jave.encode.VideoAttributes;

public class MovToMp4 {

public static void main(String[] args) {

movToMp4();

}

//https://codeantenna.com/a/QFoYfQUJXV

// <dependency>

// <groupId>it.sauronsoftware.jave</groupId>

// <artifactId>jave</artifactId>

// <version>1.0.2</version>

// </dependency>

public void movToMp4_1() {

File source = new File("D:/Handle_the_loan_in_sake2_with_maker_approved_2023-11-08_17-34-20.mov");

File target = new File("D:/Web1.mp4");

try {

AudioAttributes audio = new AudioAttributes();

audio.setCodec("libmp3lame");

audio.setBitRate(new Integer(56000));

audio.setChannels(new Integer(1));

audio.setSamplingRate(new Integer(22050));

VideoAttributes video = new VideoAttributes();

video.setCodec("mpeg4");

video.setBitRate(new Integer(800000));

video.setFrameRate(new Integer(15));

EncodingAttributes attrs = new EncodingAttributes();

attrs.setFormat("mp4");

attrs.setAudioAttributes(audio);

attrs.setVideoAttributes(video);

Encoder encoder = new Encoder();

encoder.encode(source, target, attrs);

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("Finish");

}

//ffmpeg转换视频

//https://www.cnblogs.com/lccsdncnblogs/p/17723211.html

// <dependency>

// <groupId>net.bramp.ffmpeg</groupId>

// <artifactId>ffmpeg</artifactId>

// <version>0.7.0</version>

// </dependency>

public static void movToMp4() {

System.err.println("---------开始执行----------------");

String path1 = "D:/Handle_the_loan_in_sake2_with_maker_approved_2023-11-08_17-34-20.mov";

String path2 = "D:/Web2.mp4";

//将下载后并解压的 "ffmpeg.exe,ffprobe.exe" 执行文件路径填写进去

FFmpeg ffmpeg;

try {

ffmpeg = new FFmpeg("D:/Project/Program/ffmpeg-master-latest-win64-gpl-shared/bin/ffmpeg.exe");

FFprobe ffprobe = new FFprobe("D:/Project/Program/ffmpeg-master-latest-win64-gpl-shared/bin/ffprobe.exe");

FFmpegBuilder builder = new FFmpegBuilder()

// 源视频文件

.setInput(path1)

// 目标视频文件

.addOutput(path2)

.done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

executor.createJob(builder).run();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.err.println("---------执行完毕----------------");

}

//

// <!-- mov 转换 mp4 -->

// <dependency>

// <groupId>ws.schild</groupId>

// <artifactId>jave-all-deps</artifactId>

// <version>3.0.1</version>

// </dependency>

//https://www.codenong.com/cs111037890/

public static void movToMp4_2(){

File source = new File("D:\\mov视频文件\\视频\\视频\\IMG_0604.MOV");

File target = new File("D:\\mov视频文件\\视频\\视频\\IMG_0604-target.mp4");

try {

ws.schild.jave.encode.AudioAttributes audio = new ws.schild.jave.encode.AudioAttributes();

audio.setCodec("libmp3lame");

audio.setBitRate(new Integer(800000));//设置比特率

audio.setChannels(new Integer(1));//设置音频通道数

audio.setSamplingRate(new Integer(44100));//设置采样率

ws.schild.jave.encode.VideoAttributes video = new ws.schild.jave.encode.VideoAttributes();

video.setCodec("mpeg4");

// video.setCodec("libx264");

video.setBitRate(new Integer(3200000));

video.setFrameRate(new Integer(15));

ws.schild.jave.encode.EncodingAttributes attrs = new ws.schild.jave.encode.EncodingAttributes();

attrs.setOutputFormat("mp4");

attrs.setAudioAttributes(audio);

attrs.setVideoAttributes(video);

ws.schild.jave.Encoder encoder = new ws.schild.jave.Encoder();

encoder.encode(new ws.schild.jave.MultimediaObject(source), target, attrs);

} catch (Exception e) {

e.printStackTrace();

}

}

}

相关推荐
重生之绝世牛码2 分钟前
Java设计模式 —— 【结构型模式】外观模式详解
java·大数据·开发语言·设计模式·设计原则·外观模式
小蜗牛慢慢爬行8 分钟前
有关异步场景的 10 大 Spring Boot 面试问题
java·开发语言·网络·spring boot·后端·spring·面试
新手小袁_J32 分钟前
JDK11下载安装和配置超详细过程
java·spring cloud·jdk·maven·mybatis·jdk11
呆呆小雅33 分钟前
C#关键字volatile
java·redis·c#
Monly2134 分钟前
Java(若依):修改Tomcat的版本
java·开发语言·tomcat
Ttang2336 分钟前
Tomcat原理(6)——tomcat完整实现
java·tomcat
钱多多_qdd1 小时前
spring cache源码解析(四)——从@EnableCaching开始来阅读源码
java·spring boot·spring
waicsdn_haha1 小时前
Java/JDK下载、安装及环境配置超详细教程【Windows10、macOS和Linux图文详解】
java·运维·服务器·开发语言·windows·后端·jdk
Q_19284999061 小时前
基于Spring Boot的摄影器材租赁回收系统
java·spring boot·后端
Code_流苏1 小时前
VSCode搭建Java开发环境 2024保姆级安装教程(Java环境搭建+VSCode安装+运行测试+背景图设置)
java·ide·vscode·搭建·java开发环境