视频格式转换工具,用到ws.schild.jave,之前是用的it.sauronsoftware.jave,作者已经不维护了
视频格式转换工具,用到ws.schild.jave,之前是用的it.sauronsoftware.jave,作者已经不维护了 ,最近又看到了这个,算是它的升级版,所以自己摸索它的用法,也根据之前的方法一步步试的。
添加依赖:
核心依赖
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>3.0.1</version>
</dependency>
系统平台的依赖,看你程序使用的是什么系统,两个都可以加,这个是为了使用包里提供的工具,没有这个会出现错误!
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-win64</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-nativebin-linux64</artifactId>
<version>3.0.1</version>
</dependency>
package com.maike.common.util;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import com.maike.codegenerate.common.entity.VideoItem;
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 ws.schild.jave.info.MultimediaInfo;
import ws.schild.jave.info.VideoInfo;/**** @ClassName VideoFormatUtil* @Description 视频格式转换工具* @Author geekcjj* @Date 2020年12月13日 上午10:52:28*/
public class VideoFormatUtil {public static Logger Log = LoggerFactory.getLogger(VideoFormatUtil.class);/*** 视频文件转音频文件* @param videoPath* @param audioPath* @return*/public static boolean videoToAudio(String videoPath, String audioPath) {File fileMp4=new File(videoPath);File fileMp3=new File(audioPath);//Audio AttributesAudioAttributes audio = new AudioAttributes();audio.setCodec("libmp3lame");audio.setBitRate(128000);audio.setChannels(2);audio.setSamplingRate(44100);//Encoding attributesEncodingAttributes attrs = new EncodingAttributes();attrs.setOutputFormat("mp3");attrs.setAudioAttributes(audio);Encoder encoder = new Encoder();MultimediaObject mediaObject=new MultimediaObject(fileMp4);try {encoder.encode(mediaObject, fileMp3, attrs);Log.info("File MP4 convertito in MP3");return true;} catch (Exception e) {Log.error("File non convertito");Log.error(e.getMessage());return false;}}/*** 获取视频的基本信息,视频长宽高,视频的大小等* @param fileSource* @return*/public static VideoItem getVideoInfo(String fileSource) {// String filePath =// Utils.class.getClassLoader().getResource(fileSource).getPath();File source = new File(fileSource);//Encoder encoder = new Encoder();FileInputStream fis = null;FileChannel fc = null;VideoItem videoInfo = null;try {MultimediaObject MultimediaObject=new MultimediaObject(source);MultimediaInfo m = MultimediaObject.getInfo();fis = new FileInputStream(source);fc = fis.getChannel();videoInfo = new VideoItem(m.getVideo().getSize().getWidth(), m.getVideo().getSize().getHeight(), fc.size(),m.getDuration(), m.getFormat());System.out.println(videoInfo);} catch (Exception e) {e.printStackTrace();} finally {if (null != fc) {try {fc.close();} catch (IOException e) {e.printStackTrace();}}if (null != fis) {try {fis.close();} catch (IOException e) {e.printStackTrace();}}}return videoInfo;}/*** 截取视频中某一帧作为图片* @param videoPath* @param imagePath* @return*/public static boolean getVideoProcessImage(String videoPath,String imagePath){long times = System.currentTimeMillis();File videoSource = new File(videoPath);File imageTarget = new File(imagePath);MultimediaObject object = new MultimediaObject(videoSource);try {MultimediaInfo multimediaInfo = object.getInfo();VideoInfo videoInfo=multimediaInfo.getVideo();VideoAttributes video = new VideoAttributes();video.setCodec("png");video.setSize(videoInfo.getSize());EncodingAttributes attrs = new EncodingAttributes();//VideoAttributes attrs = ecodeAttrs.getVideoAttributes().get();attrs.setOutputFormat("image2");attrs.setOffset(11f);//设置偏移位置,即开始转码位置(11秒)attrs.setDuration(0.01f);//设置转码持续时间(1秒)attrs.setVideoAttributes(video);Encoder encoder = new Encoder();encoder.encode(object,imageTarget,attrs);return true;} catch (EncoderException e) {e.printStackTrace();return false;}}/*** m4r音频格式转换为mp3,audioPath可更换为要转换的音频格式* @param audioPath* @param mp3Path*/public static void m4rToMp3(String audioPath,String mp3Path){File source = new File(audioPath);File target = new File(mp3Path);AudioAttributes audio = new AudioAttributes();audio.setCodec("libmp3lame");audio.setBitRate(new Integer(128000));audio.setChannels(new Integer(2));audio.setSamplingRate(new Integer(44100));EncodingAttributes attrs = new EncodingAttributes();attrs.setOutputFormat("mp3");attrs.setAudioAttributes(audio);Encoder encoder = new Encoder();try {encoder.encode(new MultimediaObject(source), target, attrs);} catch (EncoderException e) {e.printStackTrace();}}/*** 从和视频中提取音频wav* @param aviPath* @param targetWavPath*/public static void videoExtractAudio(String aviPath,String targetWavPath){File source = new File(aviPath);File target = new File(targetWavPath);AudioAttributes audio = new AudioAttributes();audio.setCodec("pcm_s16le");EncodingAttributes attrs = new EncodingAttributes();attrs.setOutputFormat("wav");attrs.setAudioAttributes(audio);Encoder encoder = new Encoder();try {encoder.encode(new MultimediaObject(source), target, attrs);} catch (EncoderException e) {e.printStackTrace();}}/*** 视频转换为手机可播放的格式* @param sourceVideo sourceVideo.avi* @param targetVideo targetVideo.3gp*/public static void videoToMobileVideo(String sourceVideo, String targetVideo){File source = new File("source.avi");File target = new File("target.3gp");AudioAttributes audio = new AudioAttributes();audio.setCodec("libfaac");audio.setBitRate(new Integer(128000));audio.setSamplingRate(new Integer(44100));audio.setChannels(new Integer(2));VideoAttributes video = new VideoAttributes();video.setCodec("mpeg4");video.setBitRate(new Integer(160000));video.setFrameRate(new Integer(15));video.setSize(new VideoSize(176, 144));EncodingAttributes attrs = new EncodingAttributes();attrs.setOutputFormat("3gp");attrs.setAudioAttributes(audio);attrs.setVideoAttributes(video);Encoder encoder = new Encoder();try {encoder.encode(new MultimediaObject(source), target, attrs);} catch (EncoderException e) {e.printStackTrace();}}public static void main(String[] args) {//System.out.println("数据 = [" + getVideoProcessImage("E:/MyFile/mylove/video/dPQRVRFuZHJ8.mp4","E:/MyFile/sfaafasddxg.jpg") + "]");//System.out.println("数据 = [" + getVideoInfo("E:/MyFile/mylove/video/dPQRVRFuZHJ8.mp4") + "]");//System.out.println("数据 = [" + videoToAudio("E:/MyFile/mylove/video/dPQRVRFuZHJ8.mp4","E:/MyFile/sfaafasddxgd.mp3") + "]");}}
视频格式转换工具,用到ws.schild.jave,之前是用的it.sauronsoftware.jave,作者已经不维护了相关推荐
- pcm 采样率转换_Cool Audio Video Converter(音视频格式转换工具)V2.18 最新版 - 绿色先锋下载 -...
Cool Audio Video Converter(音视频格式转换工具)是一款十分优秀好用的音频格式转换助手.如果你需要一款好用的格式转换工具,小编带来的这款Cool Audio Video Con ...
- 视频格式转换工具使用
还记得世界杯期间的那个"神奇教练"米卢吗?在给球员讲解战术.观摩对手比赛的时候,他总是喜欢随身携带一个小巧的摄像机.的确,有些摄像机重量很轻,几乎与普通照相机相仿,拍摄.携带和输出 ...
- 有什么免费的视频格式转换工具?快试试这4款,堪称“良心”工具
无论是在娱乐.学习还是工作中,我们都有离线观看视频的需求,然而有些视频格式系统自带的播放软件不支持,这个时候就需要转换视频格式,有什么免费的视频格式转换工具呢?下面给大家分享4款. 我们要分享的第一款 ...
- 免费的多功能视频格式转换工具XMedia Recode
由于不同的设备对视频格式的支持程度不一样,同一个视频可能不能在每台设备上都正常播放,视频格式转换工具这时候就派上了用场.需要切换成中文只需要点开菜单栏点开options-preference-lang ...
- MakeMKV for mac(MKV视频格式转换工具)
MakeMKV for mac是一款运行在macOS上专业的MKV视频格式转换工具.Makemkv mac版能够读取受保护的蓝光光盘,并保留视频.音轨.元信息等所有相关数据.并且支持多平台,简单易用. ...
- WinX DVD Ripper for Mac(DVD视频格式转换工具)
还在寻找一款DVD全能转换器吗?未来小编为您带来全新中文版WinX DVD Ripper for Mac 中文激活版.WinX DVD Ripper for Mac是一款一流的DVD视频格式转换工具, ...
- 有什么免费的视频格式转换工具推荐?
日常工作或是生活中,我们经常会遇到视频格式不支持导致无法打开的情况.尤其是对于经常要剪辑视频的人来说,视频素材导入剪辑软件后发现无法识别,更是苦恼.这时就需要将视频转换成设备或者软件所支持的视频格式了 ...
- 视频剪辑工作者的福音,视频格式转换工具4Videosoft Video Converter Ultimate的介绍使用,可以转换所有的视频格式
使用平台:Windows10,当然macOS也有相关的版本,我这里就不做介绍了 app:4Videosoft Video Converter Ultimate 文末附下载文件路径,全部测试安全 文章目 ...
- Movavi HD Video Converter for Mac (优秀的视频格式转换工具) v22.1
今天和大家分享 Movavi HD Video Converter for Mac 中文版本,这是一款Mac上强大易用的视频格式转换工具,支持几乎所有常见的视频格式,提供大量针对不同设备的预设,简单易 ...
- Freemake Video Converter 免费优秀的万能视频格式转换工具 (支持CUDA/DXVA显卡加速)
如今视频文件的格式越来越多,下载回来的高清电影.手机录制的视频.普通的音乐MV,或者在优酷土豆等网站上下载的网络视频,它们很多时候都是不同格式的文件.有时为了使用,不得不将视频格式进行转换 Freem ...
最新文章
- 首家A股云计算公司背后:黑客大神创办,2019上半年净利润下跌84%
- Yii中POS和GET并用范例
- 7000更换控制器电源步骤_恒温恒湿试验箱几大故障的检查步骤及解决方法说明...
- SQL Server 2008将数据导出为脚本 [SQL Server]
- CVPR 2020 论文和开源项目合集(Papers with Code)
- 不需要人际交往的计算机系,计算机对大学生人际交往影响.doc
- 在.NET3.5平台上使用LinQ to SQL + NBear 创建三层WEB应用
- 设置SVN忽略文件和文件夹(文件夹)
- 土豆 android 缓存路径,#土豆记事#教你开发Android App之 —— Hello Android
- 项目后台运行关闭_iOS到底有没有必要上滑强制关闭APP?
- mysql hash索引_mysql hash索引
- html前端订餐网页代码_21天学通HTML+CSS+JavaScript Web开发 中文完整PDF版
- 2013 VS 2018:五年前和今天的十大数字货币大比拼
- 通过adb命令查看手机中sp xml文件
- flask 数据库迁移migration
- 火山PC编辑框组件详解3
- qq邮件服务器名字怎么填,qq邮箱名称应该填写什么?(写qq昵称不好使)
- 薛定谔 | 诱导契合对接(结合位点柔性)
- 第7章第27节:三图排版:三张图片交错对齐排列 [PowerPoint精美幻灯片实战教程]
- c语言图形学画扇形代码,利用CSS绘制任意角度的扇形示例代码
热门文章
- 360网络修复大师_360补丁大师免安装下载-360补丁大师下载 v8.0 官方最新版
- JSON七彩影视双端二开修复源码
- Halcon学习笔记之OCR系列-喷码字体识别
- VS2017适配版的 VA 安装教程
- Java后端开发需要学什么?为什么选择后端开发
- sw4stm32开发stm32
- 办公软件应用2010是国家计算机一级吗,今年计算机二级办公软件高级应用考试,对word版本的要求还是2010的吗?...
- 兼容pmbus的降压DC/DC模块提供更高的输出电流
- 腾讯产培课堂|产品经理岗位解析×面试指南
- J-link J-flash 工程配置及下载