如何判断视频编码格式是否h264?

hulabang 2016-12-14 11:40:20
各位大神,用户上传视频后,我想先用php判断是否h264编码的,如否,我则ffmpeg转码,如是则不转码。我用什么方式能通过php判断视频的编码是否h264?
谢谢!!!
...全文
5276 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
老猪佩琪bridge 2019-07-12
  • 打赏
  • 举报
回复
需要jave 1.0.2 jar包,自己找去,亲测可以用.....方法我已经找了好久了,全他妈扯淡,还是自己研究的
import it.sauronsoftware.jave.Encoder;

File file = new File(filePath);
Encoder encoder = new Encoder();
MultimediaInfo info = encoder.getInfo(file);
VideoInfo video = info.getVideo();
String decoder = video.getDecoder();
System.out.println(decoder);
//decoder 值就是H264,很多功能自己get()

hulabang 2016-12-18
  • 打赏
  • 举报
回复
搞定了,谢谢大神。开始是php.ini没有注释掉passthru,后来又发现ffmpeg的安装路径不对,现在对了,谢谢大神!
hulabang 2016-12-18
  • 打赏
  • 举报
回复
我确认一下,是看vsodec而不是vformat?谢谢大神…
傲雪星枫 2016-12-18
  • 打赏
  • 举报
回复
你找一个h264的视频率,然后用上面的程序调用ffmpeg判断,根据返回的[vcodec]看看是什么。

define('KC_FFMPEG_PATH', '/usr/local/ffmpeg/bin/ffmpeg -i "%s" 2>&1');
这里就是定义ffmpeg的路径。


ffmpeg -i 表示获取视频信息,不执行转码的,你可以判断之后做转码。
hulabang 2016-12-18
  • 打赏
  • 举报
回复
太牛了,谢谢大神。但我还是没看明白,您大概思路是通过ffmpeg提取视频的相关参数,然后比较,是么?如我想识别是否h264,那我该判断哪个参数呢?还有如果我能用ffmpeg转码的话,我还需要定义路径么?谢谢大神。
傲雪星枫 2016-12-18
  • 打赏
  • 举报
回复
你打印出来看看就知道了。应该是看vcodec
傲雪星枫 2016-12-17
  • 打赏
  • 举报
回复

<?php
// 定义 FFmpeg的路径,最好在网站的全局配置文件里定义好
// 另外,重定向符号在FreeBSD等csh系统中为 >&
define('KC_FFMPEG_PATH', '/usr/local/ffmpeg/bin/ffmpeg -i "%s" 2>&1');
function video_info($file) {
	ob_start();
	passthru(sprintf(KC_FFMPEG_PATH, $file));
	$info = ob_get_contents();
	ob_end_clean();
	// 通过使用输出缓冲,获取到ffmpeg所有输出的内容。
	$ret = array();
	// Duration: 01:24:12.73, start: 0.000000, bitrate: 456 kb/s
	if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $info, $match)) {
		$ret['duration'] = $match[1]; // 提取出播放时间
		$da = explode(':', $match[1]);
		$ret['seconds'] = $da[0] * 3600 + $da[1] * 60 + $da[2]; // 转换为秒
		$ret['start'] = $match[2]; // 开始时间
		$ret['bitrate'] = $match[3]; // bitrate 码率 单位 kb
		
	}
	// Stream #0.1: Video: rv40, yuv420p, 512x384, 355 kb/s, 12.05 fps, 12 tbr, 1k tbn, 12 tbc
	if (preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $info, $match)) {
		$ret['vcodec'] = $match[1]; // 编码格式
		$ret['vformat'] = $match[2]; // 视频格式
		$ret['resolution'] = $match[3]; // 分辨率
		$a = explode('x', $match[3]);
		$ret['width'] = $a[0];
		$ret['height'] = $a[1];
	}
	// Stream #0.0: Audio: cook, 44100 Hz, stereo, s16, 96 kb/s
	if (preg_match("/Audio: (\w*), (\d*) Hz/", $info, $match)) {
		$ret['acodec'] = $match[1]; // 音频编码
		$ret['asamplerate'] = $match[2]; // 音频采样频率
		
	}
	if (isset($ret['seconds']) && isset($ret['start'])) {
		$ret['play_time'] = $ret['seconds'] + $ret['start']; // 实际播放时间
		
	}
	$ret['size'] = filesize($file); // 文件大小
	return array($ret, $info);
}
// 调用方法:
print_r(video_info('cuepoints.flv'));
?>

输出: Array ( [duration] => 00:00:16.33 [seconds] => 16.33 [start] => 0.000000 [bitrate] => 568 [vcodec] => vp6f [vformat] => yuv420p [resolution] => 320x213 [width] => 320
hulabang 2016-12-16
  • 打赏
  • 举报
回复
有人知道么?快哭了。。。
hulabang 2016-12-15
  • 打赏
  • 举报
回复
大神们指点一下吧。。。
kakoY 2016-12-15
  • 打赏
  • 举报
回复
真巧 两分钟前我也想到了这个问题 ...

21,894

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧