问题描述
HTML 视频播放器必须知道其播放文件的帧率,否则播放视频不可避免地会以错误的速度播放。
如何获取视频播放器当前为当前加载的视频使用的帧速率?
解决方法
如果您想要帧率,请按照以下解决方案进行操作。
$(video).on('timeupdate',function () {
var ct = document.getElementById('#video').currentTime;
var dur = document.getElementById('#video').duration;
var videoProgressPos = ct / dur;
console.log(videoProgressPos)
});
这个 videoProgressPos 变量将为您提供您正在播放的视频的当前帧。 我混合了 JS 和 jQuery,您可以将其开发为您的愿望逻辑。 如果我的回答对您没有帮助,请告诉我。 谢谢。
,您可以使用 FFprobe 测试您正在查看的每个视频。它是 FFMPEG 的一部分,我在 https://ffprobe.a.video 建立了一个在线版本。
它会告诉你比特率(以及关于你的视频的许多其他有趣的事实
它需要一个节点服务器和 FFMPEG:
URL 作为查询字符串发送,然后弹出到 ffprobe....Node 的其余部分正在格式化...
app.get('/probe',(req,res) =>{
let url = req.query.url;
console.log(" url="+url);
let ffprobeResult = ffprobe(url)
ffprobeResult.then(function(info){
//extract some essentials
//sometimes video is thr first stream.. someties second
var streamCount = info.format.nb_streams;
//format data is overall
var bitrate= info.format.bit_rate;
var sizeBytes = info.format.size;
var duration = info.format.duration;
var formatName = info.format.format_name;
var formatLong = info.format.format_long_name;
//get video/audio specific infos
for (var i=0;i<streamCount;i++){
if (info.streams[i].codec_type == "video"){
var height = info.streams[i].height;
var width =info.streams[i].width;
var aspectRatio = info.streams[i].display_aspect_ratio;
var videoCodec = info.streams[i].codec_name;
}else{
//audio
var audioCodec = info.streams[i].codec_name;
}
}
console.log(bitrate,sizeBytes,duration,formatLong);
console.log(height,width,aspectRatio,videoCodec,audioCodec);
var format = info.format;
var streams = info.streams;
console.log(format);
console.log(streams);
return res.render('results',{format,streams,bitrate,formatLong,height,audioCodec});
但此数据不会从 HTML5 视频播放器中公开。
道格