文章插图
文章插图
问题:原视频的编码格式为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-presets</groupId><artifactId>opencv-platform</artifactId><version>3.4.1-1.4.1</version></dependency><dependency><groupId>org.bytedeco.javacpp-presets</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.javacv.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.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);recorder.setFormat("mp4");recorder.setFrameRate(grabber.getFrameRate());recorder.setSampleRate(grabber.getSampleRate());recorder.setVideoBitrate(grabber.getVideoBitrate());recorder.setAspectRatio(grabber.getAspectRatio());recorder.setAudioBitrate(grabber.getAudioBitrate());recorder.setAudioOptions(grabber.getAudioOptions());recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);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.close();} catch (Exception e) {System.out.println("recorder.close异常" + e);}}try {grabber.close();} catch (FrameGrabber.Exception e) {System.out.println("frameGrabber.close异常" + e);}}}}
3、调用工具类方法VideoConvertUtil convertUtil = new VideoConvertUtil();convertUtil.convert(url, videoSavePath);
路漫漫其修远兮,吾将上下而求索
【手机转码工具 码率 转码工具有哪些】译文:在追寻真理方面,前方的道路还很漫长,但我将百折不挠,不遗余力地去追求和探索 。
- 苹果手机设置动态壁纸怎么设置 手机设置动态壁纸怎么设置
- iphone的悬浮球设置截屏 苹果手机的悬浮球怎么设置截屏
- 苹果机型对比图 苹果机型对比在哪里
- 苹果手机报价表 苹果手机报价最新报价单
- 手机怎么投屏到电视视频教程 手机怎么投屏到电视上?简单三步轻松搞定!
- 苹果在那清内存 苹果手机清理内存在哪里
- 腾讯木马专杀官方下载 qq游戏木马专杀工具官方下载
- 苹果数据备份到电脑怎么导入到新手机 苹果数据备份到电脑哪里去了
- 苹果手机电池突然掉电快怎么办 苹果手机电池掉电非常快怎么回事
- 扩容卡检测工具手机版 扩容卡检测软件