使用Ffmpeg获取视频编码格式
1,自己去下载ffepeg工具包放在项目指定目录下
2,Ffmpeg工具类
public static String processflvcodetype(String ffmpegPath, String filePath) {String resultmessage=null;// String ffmpegPath = request.getSession().getServletContext().getRealPath(File.separator+"tools"+File.separator+"ffmpeg.exe");// String result = MediaService.processFLV(ffmpegPath, "C:\\Users\\Administrator\\Desktop\\乱七八糟\\20200722171230-23281_2_video_0_0_student_far.mp4");String result = MediaService.processFLV(ffmpegPath, filePath);System.out.println("Ffmpeg:" + result);PatternCompiler compiler = new Perl5Compiler();try {String regexDuration = "Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";String regexVideo = "Video: (.*?), (.*?), (.*?)[,\\s]";String regexAudio = "Audio: (\\w*), (\\d*) Hz";Pattern patternDuration = compiler.compile(regexDuration, Perl5Compiler.CASE_INSENSITIVE_MASK);PatternMatcher matcherDuration = new Perl5Matcher();if (matcherDuration.contains(result, patternDuration)) {MatchResult re = matcherDuration.getMatch();System.out.println("提取出播放时间 ===" + re.group(1));System.out.println("开始时间 =====" + re.group(2));System.out.println("bitrate 码率 单位 kb==" + re.group(3));}Pattern patternVideo = compiler.compile(regexVideo, Perl5Compiler.CASE_INSENSITIVE_MASK);PatternMatcher matcherVideo = new Perl5Matcher();if (matcherVideo.contains(result, patternVideo)) {MatchResult re = matcherVideo.getMatch();System.out.println("编码格式 ===" + re.group(1));//编码格式resultmessage=re.group(1);System.out.println("视频格式 ===" + re.group(2));System.out.println(" 分辨率 == =" + re.group(3));}Pattern patternAudio = compiler.compile(regexAudio, Perl5Compiler.CASE_INSENSITIVE_MASK);PatternMatcher matcherAudio = new Perl5Matcher();if (matcherAudio.contains(result, patternAudio)) {MatchResult re = matcherAudio.getMatch();System.out.println("音频编码 ===" + re.group(1));System.out.println("音频采样频率 ===" + re.group(2));}} catch (MalformedPatternException e) {e.printStackTrace();}return resultmessage;}
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)public static String processFLV(String ffmpegPath,String inputPath) {List<String> commend=new java.util.ArrayList<String>();commend.add(ffmpegPath); // 添加转换工具路径commend.add("-i");commend.add(inputPath);try {ProcessBuilder builder = new ProcessBuilder();builder.command(commend);builder.redirectErrorStream(true);Process p= builder.start();BufferedReader buf = null; // 保存ffmpeg的输出结果流String line = null;buf = new BufferedReader(new InputStreamReader(p.getInputStream()));StringBuffer sb= new StringBuffer();while ((line = buf.readLine()) != null) {System.out.println(line);sb.append(line);continue;}int ret = p.waitFor();//这里线程阻塞,将等待外部转换进程运行成功运行结束后,才往下执行return sb.toString();} catch (Exception e) {return null;}}
3测试
public static void main(String[] args) {String ffepegpath="F:\\workspace\\TestWork\\WebContent\\tools\\ffmpeg.exe";String filepath="C:\\Users\\Administrator\\Desktop\\spreedmovie_1.mp4";String processflvcodetype = MediaService.processflvcodetype(ffepegpath, filepath);System.out.println(processflvcodetype);}
使用Ffmpeg获取视频编码格式相关推荐
- php获得视频分辨率,php+ffmpeg 获取视频相关信息(缩略图、视频分辨率)
ffmpeg是一款开源.跨平台的视频处理程序,可用在Windows.mac.linux等平台,可以方便的运用多种语言脚本来调用其执行视频的操作. 下面介绍使用ffmpeg获取视频首帧的方法. & ...
- python ffmpeg 获取视频信息_ffmpeg获取视频信息
php使用ffmpeg获取视频信息可以获取到视频的分辨率.文件大小.播放时长.编码格式.视频格式.音频编码.音频采样频率.等..... 废话不多说,直接上代码.../** * Name: ffmpeg ...
- Java通过FFMPEG获取视频时长
2019独角兽企业重金招聘Python工程师标准>>> Java通过FFMPEG获取视频时长 详见https://www.yz1618.cn/view/19 转载于:https:// ...
- FFmpeg获取视频旋转角度rotate获取不到的问题解决
ffmpeg获取视频旋转角度,这个主要是在ios或者安卓手机拍照出来的视频,一般是高比宽大. 那么在我们自己用ffmpeg处理视频的时候,比如获取YUV的时候,其实倒立着的.即使你以后处理了,比如做水 ...
- ffmpeg获取视频时长和分辨率
文章目录 ffmpeg获取视频文件时长和分辨率 获取视频时长 获取视频分辨率 ffmpeg获取视频文件时长和分辨率 获取视频时长 import os import subprocess# video_ ...
- PHP中用ffmpeg获取视频封面图片详细步骤
PHP中用ffmpeg获取视频封面图片详细步骤 一.环境准备 官网下载:https://ffmpeg.org/download.html wget https://ffmpeg.org/release ...
- java通过使用ffmpeg获取视频的码率
2019独角兽企业重金招聘Python工程师标准>>> 工作过程中有使用JAVA代码获取视频码率的场景,网上搜索了找到了利用ffmpeg来获取,ffmpeg组件中有ffprobe是专 ...
- java ffmpeg 获取视频时长_Java通过调用FFMPEG获取视频时长
FFmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证.它提供了录制.转换以及流化音视频的完整解决方案.它包含了非常先进的音频/视频编解码库l ...
- FFmpeg获取视频的旋转角度
FFmpeg获取旋转角,目前只有在解析视频流的时候,调用rotate函数,才可以获取. 示例代码如下: int getRotateAngle(AVStream* avStream) {AVDictio ...
- ffmpeg获取视频封面图片
ffmpeg百度云盘下载地址:https://pan.baidu.com/s/1Am_x0abBvXTrbCFPHs5e9Q 提取码:4y2r /*** ffmpeg百度云盘下载地址:https:// ...
最新文章
- 员工考勤信息管理小程序
- drupal常用api
- 从babel实现es6类的继承来深入理解js的原型及继承
- SpringBoot+POI实现导入Excel时验证并返回错误Cell标红的文件
- 自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
- HDU - 1223 DP 分类
- spring配置详解-初始化销毁方法
- POJ 2299 - Ultra-QuickSort BIT
- 牛客 13822 Keep In Line(枚举与暴力、Python)
- IM、RTC技术两生花,看融云如何打造“IM+RTC+Push”一站式通信云服务
- CSS超全笔记(适合新手入门)
- 数据结构c语言版秦锋,数据结构(C语言版)黄国瑜.pdf
- 等价类划分法-案例剖析-设计测试用例
- 最新声鉴卡H5网页源码_完整可运转,引流专用神器
- zmap扫描mysql_zmap/masscan 快速扫描网络
- 知乎高赞的学习网站,建议收藏
- 林利军2018年致投资人的信:这是一个极致者胜的时代
- 列表解析式,生成表达式
- sql end关键字
- Freeswitch服务+语音网关设备发送短信功能