问题:原视频的编码格式为h265,在小程序上面无法播放,需要转为mpeg-4格式。
1、引入相关依赖
<dependency> <groupid>org.bytedeco</groupid> <artifactid>javacv</artifactid> <version>1.4.1</version></dependency><dependency> <groupid>org.bytedeco</groupid> <artifactid>javacpp</artifactid> <version>1.4.1</version></dependency><dependency> <groupid>org.bytedeco.javacpp-prets</groupid> <art骆宾王的诗ifactid>opencv-platform</artifactid> <version>3.4.1-1.4.1</version></dependency><dependency> <groupid>org.bytedeco.javacpp-prets</groupid> <artifactid>ffmpeg-platform</artifactid> <version>3.4.2-1.4.1</version></dependency>
2、视频转码工具类
import org.bytedeco.javacv.frame;import org.bytedeco.javacpp.avcodec;import org.bytedeco.javacv.framegrabber;import org.bytedeco.javacv.framerecorder;import org.bytedeco.javac中国杀人排行榜v.ffmpegframegrabber;import org.bytedeco.javacv.ffmpegframerecorder;/** * 视频转码工具类 */public class videoconvertutil { public void convert(string inputfile, string outputfile) throws exception { ffmpegframegrabber grabber = ffmpegframegrabber.createdefault(inputfile); frame captured_frame;昌谷北园新笋 ffmpegframerecorder recorder = null; try { grabber.start(); recorder = new ffmpegframerecorder(outputfile, grabber.getimagewidth(), grabber.getimageheight(), grabber.getaudiochannels()); recorder.tvideocodec(avcodec.av_codec_id_mpeg4); recorder.tformat("mp4"); recorder.tframerate(grabber.getframerate()); recorder.tsamplerate(grabber.getsamplerate()); recorder.tvideobitrate(grabber.getvideobitrate()); recorder.taspectratio(grabber.getaspectratio()); recorder.taudiobitrate(grabber.getaudiobitrate()); recorder.taudiooptions(grabber.getaudiooptions()); r古代诚信的故事ecorder.taudiocodec(avcodec.av_codec_id_aac); 宾得k50 recorder.start(); while (true) { captured_frame = grabber.grabframe(); if (captured_frame == null) { system.out.println("转码完成"); break; } recorder.record(captured_frame); } } catch (framerecorder.exception e) { e.printstacktrace(); } finally { if (recorder != null) { try { recorder.clo(); } catch (exception e) { system.out.println("recorder.clo异常" + e); } } try { grabber.clo(); } catch (framegrabber.exception e) { system.out.println("framegrabber.clo异常" + e); } } }}
3、调用工具类方法
videoconvertutil convertutil = new videoconvertutil();convertutil.convert(url, videosavepath);
路漫漫其修远兮,吾将上下而求索
译文:在追寻真理方面,前方的道路还很漫长,但我将百折不挠,不遗余力地去追求和探索。
本文发布于:2023-04-05 07:34:24,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/57ac9d9d45d5c2f1d6be48a74d404090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:手机转码工具(免费转视频格式的软件).doc
本文 PDF 下载地址:手机转码工具(免费转视频格式的软件).pdf
留言与评论(共有 0 条评论) |