准备:

官网地址:https://github.com/a-schild/jave2

步骤

  • 添加依赖

<dependency><groupId>ws.schild</groupId><artifactId>jave-all-deps</artifactId><version>2.4.6</version>
</dependency><!--根据环境添加ffmpeg执行包-->
<!--For one platform only (Linux 64Bit in this case)-->
<dependency><groupId>ws.schild</groupId><artifactId>jave-native-linux64</artifactId><version>2.4.6</version>
</dependency>
<!--For one platform only (Windows 64Bit in this case)-->
<dependency><groupId>ws.schild</groupId><artifactId>jave-native-win64</artifactId><version>2.4.6</version>
</dependency>
<!--For one platform only (MACOS 64Bit in this case)-->
<dependency><groupId>ws.schild</groupId><artifactId>jave-native-osx64</artifactId><version>2.4.6</version>
</dependency>
  • 代码编写

代码路径见:https://github.com/muxiyue/docker-test/blob/master/src/test/java/video/VideoTest.java

普通的转码操作

@Testpublic void test() {ConvertProgressListener listener = new ConvertProgressListener();String inputFilePath = VideoTest.class.getResource("/").getPath() + "file/input/test2.3gp";String outputFilePath = VideoTest.class.getResource("/").getPath() + "file/output/test.mp4";try {File source = new File(inputFilePath);File target = new File(outputFilePath);AudioAttributes audio = new AudioAttributes();audio.setCodec("aac");audio.setBitRate(new Integer(236000/2));
//            audio.setChannels(new Integer(1));audio.setSamplingRate(new Integer(8000));VideoAttributes video = new VideoAttributes();video.setCodec("mpeg4");video.setBitRate(new Integer(128000));video.setFrameRate(new Integer(15));video.setSize(new VideoSize(1760, 1440));EncodingAttributes attrs = new EncodingAttributes();attrs.setFormat("3gp");attrs.setAudioAttributes(audio);attrs.setVideoAttributes(video);Encoder encoder = new Encoder();try {encoder.encode(new MultimediaObject(source), target, attrs, listener);}catch (Exception e) {e.printStackTrace();System.out.println(encoder.getUnhandledMessages());}} catch (Exception ex) {ex.printStackTrace();}}public class ConvertProgressListener implements EncoderProgressListener {public ConvertProgressListener() {//code}public void message(String m) {//code}public void progress(int p) {//Find %100 progressdouble progress = p / 1000.00;System.out.println(progress);}public void sourceInfo(MultimediaInfo m) {//code}}

filter测试

@Testpublic void test2() {ConvertProgressListener listener = new ConvertProgressListener();String inputFilePath = VideoTest.class.getResource("/").getPath() + "file/input/test2.3gp";String outputFilePath = VideoTest.class.getResource("/").getPath() + "file/output/test.mp4";String ttfPath = VideoTest.class.getResource("/").getPath() + "file/input/Songti.ttc";try {File source = new File(inputFilePath);File target = new File(outputFilePath);AudioAttributes audio = new AudioAttributes();audio.setSamplingRate(new Integer(8000));audio.setVolume(512);audio.setChannels(1);VideoAttributes video = new VideoAttributes();//            命令行: ffplay -i test2.mp4 -vf drawtext="fontfile=Songti.ttc:text='指定时间段内才能看见':x='if((gte(t\,5) * (lte(t\,10)))\,w-t*50\,NAN)':fontcolor=darkorange:fontsize=30"
//            去掉了反斜杠和drawtext后面的双引号环绕VideoFilter videoFilter = new VideoFilter("drawtext=fontfile=" + ttfPath + ":text='指定时间段内才能看见':x='if((gte(t,1) * (lte(t,8))),w-t*50,NAN)':fontcolor=darkorange:fontsize=50");video.addFilter(videoFilter);EncodingAttributes attrs = new EncodingAttributes();attrs.setFormat("3gp");attrs.setAudioAttributes(audio);attrs.setVideoAttributes(video);Encoder encoder = new Encoder();try {encoder.encode(new MultimediaObject(source), target, attrs, listener);}catch (Exception e) {e.printStackTrace();System.out.println(encoder.getUnhandledMessages());}} catch (Exception ex) {ex.printStackTrace();}}

(四)、jave2加工视频相关推荐

  1. 安卓 camera 调用流程_音视频开发之旅(四)Camera视频采集

    目录 Camera基础知识 视频采集的流程 遇到的问题和常见的坑(重点) 收获 一. Camera基础知识 Camera 有几个重要的基础概念. facing相机的方向,一般后置摄像头和前置摄像头. ...

  2. 软件合码器-驾考-驾驶员考试-音视频合成-四合一-多路视频合成一路技术开发-音视频合码器

    本技术以实际开发实施案例为基础(驾驶员路考系统用的音视频监控合成) 软件合码器-驾考-驾驶员考试-音视频合成-四合一-多路视频合成一路技术开发-音视频合码器 软件效果: 设计流程: 简介 视频合成软件 ...

  3. android硬编码封装mp4,【Android 音视频开发打怪升级:音视频硬解码篇】四、音视频解封和封装:生成一个MP4...

    [声 明] 首先,这一系列文章均基于自己的理解和实践,可能有不对的地方,欢迎大家指正. 其次,这是一个入门系列,涉及的知识也仅限于够用,深入的知识网上也有许许多多的博文供大家学习了. 最后,写文章过程 ...

  4. 2011何凯文四六级冲刺视频及讲义

    不错,比做题有用 整理所得,并非原创 视频地址: http://www.tudou.com/programs/view/sQz8Qmq9lok/?fr=rec1 2011年12月文都大学英语 &quo ...

  5. matplotlib-bilibili,抖音很火的动态数据视频自动生成(第四节)-视频,语音合成

    " matplotlib-bilibili,抖音很火的动态数据视频自动生成(第四节)-视频,语音自动合成" 还记得上一节中我们所提到的数据动态视频吗​?这次,为了让大家更加方便的制 ...

  6. html怎么把视频设置为背景音乐,简单四步为视频添加背景音乐

    平时拍摄的视频,或网上下载的视频需要再剪辑,这其中有一个常见的步骤便是加上背景音乐,通过给视频加背景音乐,可以轻松替换掉拍摄的视频中不理想的音频,还可以使视频更具有感染力.那么,怎么给视频加背景音乐呢 ...

  7. 音视频开发之旅(四)Camera视频采集

    目录 Camera基础知识 视频采集的流程 遇到的问题和常见的坑(重点) 收获 一. Camera基础知识 Camera 有几个重要的基础概念. facing相机的方向,一般后置摄像头和前置摄像头. ...

  8. 四款AI视频翻译产品横评

    本文内容节选自 Paxi.ai 的文章分享,从其中摘录了我觉得有意思的一部分.Paxi.ai 是一个基于 GPT-4 打造的帮用户快速使用AI的AI工具,通过与它的小助手对话可以了解各种AI的产品功能 ...

  9. iOS直播(四)对视频进行压缩编码

    1.为什么要进行编码? 不经过压缩编码的原视频,所占空间大,不便于保存和网络传输,所以视频录制完后,需要先编码,再传输,解码后再播放. 2.视频为什么可以被压缩? 视频存在冗余信息,主要为数据冗余和视 ...

  10. python opencv输出mp4_Python玩转视频处理(四):视频按场景进行分割

    在上一篇文章(python在手,女神视频轻松有)分享了用AI人脸识别技术标记人物出现时间点来截取视频片段的教程,它的局限性在于只能通过识别特定的对象(比如人脸)来操作.在本文中将分享一个按场景进行分割 ...

最新文章

  1. mysql的优化之table_open_cache 篇_mysql性能优化之table_open_cache
  2. python设置ini文件中的值_PyCharm设置python文件模板,自动读取文件信息。
  3. Java中String类型的数据比较
  4. pycharm专业版(window)安装
  5. 释放mysql ibdata1文件_释放MySQL ibdata1文件的空间
  6. skiplist原理与实现
  7. 如何迁移outlook邮件到另一个硬盘_猎头如何有效的搜寻与筛选简历
  8. 如何设置ftp服务器上传文件夹至不同路径,设置ftp服务器上传文件夹
  9. linux mysql 升级_linux mysql5.7升级到mysql8.0
  10. 最近出现Matlab2010b点击matlab.exe运行时,不断提示Activate MathWorks Software,无法正常使用
  11. 尝试Python的websockets库的最基础功能
  12. Laravel快速入门
  13. hive之内表和外表
  14. [HAOI2006]聪明的猴子 题解
  15. java刮刮乐,20行JS代码实现网页刮刮乐效果
  16. linux解冻用户的密码,linux – 透明地冻结和解冻进程?
  17. html中scr作用,可控硅的作用是什么
  18. 考研调剂 计算机科学 软件,四川大学计算机学院(软件学院)2020非全日制考研调剂信息...
  19. knex 找不到mysql_node knex mysql ER_NOT_SUPPORTED_AUTH_MODE
  20. http409 415报错原因

热门文章

  1. STM32MP157AAA3裸机点灯(汇编)
  2. Hexo+Github博客搭建教程
  3. python爬取喜马拉雅vip音频_Python简易爬虫教程(三)--爬取喜马拉雅音频
  4. UVM学习整理——附录(部分组件源码)
  5. c4d——界面认识、视图快捷键、常用的快捷键
  6. 数据结构视频教程哪个好
  7. Hypermesh软件初学
  8. 高等数学常用符号大全及符号的含义
  9. linux r语言 安装包下载,R语言安装程序包(示例代码)
  10. ecshop index.php,]ECSHOP 源码分析(install/index.php1)