手机转码工具_免费转视频格式的软件

手机转码工具_免费转视频格式的软件,第1张

手机转码工具_免费转视频格式的软件 问题:原视频的编码格式为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);路漫漫其修远兮,吾将上下而求索译文:在追寻真理方面,前方的道路还很漫长,但我将百折不挠,不遗余力地去追求和探索。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/653768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-18
下一篇 2022-04-18

发表评论

登录后才能评论

评论列表(0条)

保存