如何在没有浏览器支持h.264的情况下从纯ecmascript的MP4 URL中获取视频的高度和宽度? [英] How to get video height and width from a MP4 URL with pure ecmascript and without browser support for h.264?

查看:102
本文介绍了如何在没有浏览器支持h.264的情况下从纯ecmascript的MP4 URL中获取视频的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写用于下载视频的用户脚本.网站的Flash Player使用JSON文件.
我的脚本的目的是通过根据网页下载和解析视频来获取视频的网址.目前,它可以成功下载视频的URL摘录.

I'm writing a user script for downloading videos. The flash player of the web site use a JSON file.
The purpose of my script is to get the url of the video by downloading and parsing the video according to the web page. Currently it can download an extract the URL of the videos successfully.

JSON文件的重要部分如下所示:

The important part of the JSON file look like this :

    {
        "ammProfile": "AMM-HBBTV",
        "version": "VF",
        "versionProg": "1",
        "VFO": "HBBTV",
        "VMT": "mp4",
        "VUR": "http://vo.llnwd.net/v2/am/HBBTV/051332-074-A_SQ_2_VF_01464306_MP4-2200_AMM-HBBTV.mp4"
    }, {
        "ammProfile": "AMM-HBBTV",
        "version": "VF",
        "versionProg": "1",
        "VFO": "HBBTV",
        "VMT": "mp4",
        "VUR": "http://vo.llnwd.net/v2/am/HBBTV/051332-074-A_EQ_2_VF_01464315_MP4-1500_AMM-HBBTV.mp4"
    }

这里的两个URL都是关于同一视频的,这只是变化的分辨率.

Both URL here are about the same video, this just is just the resolution which change.

因此,如何在不下载整个文件的情况下解析相关元数据? H.264视频编解码器的标准非常难以理解.

So, How I can parse the relevant metadata without downloading the whole file? The standard for the H.264 video codec is very hard to read.

推荐答案

您无需加载整个视频即可获得高度:

you don't need to load the whole video to get the height:

function getVideoHeight(url, fnCallback){

var video=document.createElement("video");
  video.autoplay=true;
  video.oncanplay=function(){
     fnCallback(this.offsetWidth, this.offsetHeight);
     this.src="about:blank";
     document.body.removeChild(video);   
  };

  document.body.appendChild(video);
  video.src=url;

}


//test:

getVideoHeight(
  "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", 
  function(w,h){ alert( w+"X"+h); }
); // shows: "640X360"

这篇关于如何在没有浏览器支持h.264的情况下从纯ecmascript的MP4 URL中获取视频的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆