首页 \ 问答 \ 检测mp4文件(Detect mp4 files)

检测mp4文件(Detect mp4 files)

我必须设计一个检测mp4文件的模块。 如果将任何随机文件作为输入,它必须告诉它是否是一个mp4文件。 在哪里可以找到mp4文件的标题规范? 尝试谷歌搜索除了签名之外找不到任何东西。 关于模块的C编程的其他任何提示?


I have to design a module that detects mp4 files. If will get any random file as input and it has to tell whether it is a mp4 file or not. Where can I find the specification of headers for the mp4 file? Tried googling but could not find anything except the signature. Any other tips regarding C programming for the module?


原文:https://stackoverflow.com/questions/13190005
更新时间:2022-10-01 21:10

最满意答案

这是您目前正在考虑的非常糟糕的解决方案:

<span\b[^<>]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?)</span><br\s*/>

演示

它确保我们找到了一个<span>标签,并且有一个以ctl00_MainContent_ListView2_ctrl2_ctl01_开头的id属性,并且有一些以475px;结尾的属性(你知道它是style475px; ,然后我们只捕获任何截至</span>标记的内容。

您可以使用DOM和XPath来实现这一点,这是一个更安全的解决方案,它使用与上面相同的逻辑:

$html = "<span id=\"ctl00_MainContent_ListView2_ctrl2_ctl01_Label17\" class=\"vehicledetailTable\" style=\"display:inline-block;width:475px;\">OWNED</span><br />"; 
$dom = new DomDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$spans = $xpath->query("//span[starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') and @class='vehicledetailTable'  and contains(@style,'475px;')]");
$data = array();
foreach ($spans as $span) {
    array_push($data, $span->textContent);
}
print_r($data);

输出: [0] => OWNED

注意XPath表达式包含3个条件,随意修改任何:

  • //span - 获取所有span标签
  • starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') - 有一个属性id ,其值以ctl00_MainContent_ListView2_ctrl2_ctl01_
  • @class='vehicledetailTable' - 并且class属性的值等于vehicledetailTable
  • contains(@style,'475px;') - 并且有一个style属性,其值包含475px;

条件包含在[...] ,并与orand 。 它们也可以用圆括号分组。 您也可以使用not(...)来反转条件。 XPath在这种情况下非常有用。


Here is a very poor solution that you are currently considering:

<span\b[^<>]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?)</span><br\s*/>

See demo

It makes sure we found a <span> tag and there is id attribute starting with ctl00_MainContent_ListView2_ctrl2_ctl01_, and there is some attribute (and you know it is style) ending with 475px;, and then we just capture anything up to the closing </span> tag.

You can get this with DOM and XPath, which is a much safer solution that uses the same logic as above:

$html = "<span id=\"ctl00_MainContent_ListView2_ctrl2_ctl01_Label17\" class=\"vehicledetailTable\" style=\"display:inline-block;width:475px;\">OWNED</span><br />"; 
$dom = new DomDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$spans = $xpath->query("//span[starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') and @class='vehicledetailTable'  and contains(@style,'475px;')]");
$data = array();
foreach ($spans as $span) {
    array_push($data, $span->textContent);
}
print_r($data);

Output: [0] => OWNED

Note that the XPath expression contains 3 conditions, feel free to modify any:

  • //span - get all span tags that
  • starts-with(@id,'ctl00_MainContent_ListView2_ctrl2_ctl01_') - have an attribute id with value starting with ctl00_MainContent_ListView2_ctrl2_ctl01_
  • @class='vehicledetailTable' - and have class attribute with value equal to vehicledetailTable
  • contains(@style,'475px;') - and have a style attribute whose value contains 475px;.

Conditions are enclosed into [...] and are joined with or or and. They can also be grouped with round brackets. You can also use not(...) to invert the condition. XPath is very helpful in such situations.

相关问答

更多
  • 表达方式 {{\*(\w+)}}((?:.|\n)+?){{\/\w+}} 非常无效,更好用 {{\*(\w+)}}(.+?){{/\w+}} 与其他分隔符,例如~代替。 您的旧表达式需要 780步 (请参阅 regex101.com上的此演示 ),而后者只需要 404步 (请参阅 此处的另一个演示 )。 The expression {{\*(\w+)}}((?:.|\n)+?){{\/\w+}} is very ineffective, better use {{\*(\w+)}}(.+?){{/ ...
  • '/{if\s+(isRegion|isCountry)([az]+?)}/i'对我来说很好。 在这里看到它。 '/{if\s+(isRegion|isCountry)([a-z]+?)}/i' works just fine for me. See it in action here.
  • 您只能获得组的最后一场比赛。 两个得到所有的值,如x,x; 你可以使用你当前的正则表达式,改变一下: preg_match_all('/("message":")([a-z0-9A-Z]+):(.*)"/', $customerMessage, $matches); /* $matches[3] --> 2,2;3,3; 现在你可以使用$matches[3]获得第3组并匹配所有x,x; [0-9]+,[0-9]+; preg_match_all('/[0-9]+,[0-9]+/', $matches[3] ...
  • preg_match_all()在匹配结果中返回一个数组数组。 然后显示您必须使用的所有匹配项: $remove = preg_match_all('/;([\d]{4};[\d]{3});/', $str, $m); foreach($m[0] as $item) { echo $item . '
    '; } 如果您只想要捕获组的内容,只需将$m[0]替换$m[0] $m[1] preg_match_all() returns in match result an array of arrays ...
  • 如果我理解正确,count($ matches [0]假设$ content中只有一个匹配。 不完全的; $matches[0]表示整个正则表达式中的匹配数组(与$matches[1] ,后者是正则表达式的第一个匹配组中的匹配数组)。 因此, count($matches[0])是他第一个匹配组中的匹配数。 你可以做你所说的并将for循环重写for foreach循环,但这可能不会改变任何东西,因为两个方法都应该遍历$matches[0]所有元素。 您确定您要查找的结果是否与正则表达式相匹配? If I u ...
  • 这是您目前正在考虑的非常糟糕的解决方案: ]*\bid="ctl00_MainContent_ListView2_ctrl2_ctl01_[^"]*"[^<>]*475px;">(.*?) 见演示 它确保我们找到了一个标签,并且有一个以ctl00_MainContent_ListView2_ctrl2_ctl01_开头的id属性,并且有一些以475px;结尾的属性(你知道它是style ) 475px; ,然后我们只捕获任何截至 ...
  • 积极的向前看 /(?=(1[^1]+1))/ 阅读: http : //www.regular-expressions.info/lookaround.html Positive lookahead /(?=(1[^1]+1))/ Read this: http://www.regular-expressions.info/lookaround.html
  • [ , ]和*是正则表达式中的特殊元字符,您需要转义它们。 您还需要根据您的问题选择last [] 。 遵循以下建议应该工作: $name = 'hello $this->row[today1][] dfh fgh df $this->row[test1] ,how good $this->row[test2][] is $this->row[today2][*] is monday'; echo $name."\n"; preg_match_all( '/\$this->row\[.*?\](?:\[ ...
  • 远程文件使用序列CR LF作为换行符,这就是锚$不匹配的原因。 当您将文件内容复制/粘贴到默认情况下仅使用LF作为换行符的应用程序时,序列CR LF可能会默默地替换为LF并且您的模式可以正常工作。 解决问题的几种方法: 1)在你的模式中明确写出回车: #^BEGIN:VEVENT.*?END:VEVENT\r$#sm 如果您不希望在匹配结束时返回回车,请使用trim或将其置于先行断言中: #^BEGIN:VEVENT.*?END:VEVENT(?=\r$)#sm 。 您也可以删除$并使用与\r , \r\ ...
  • 这个正则表达式应该工作: "/array\.content\(2\,\'?([0-9]+)\'?\,[^\)]*\)\;/ui" 并且在preg_match_all的参数中使用$con swiitch $result变量在这里测试: http ://regexr.com?34e0q 如果第一个参数不总是2(但是数字变量),您可以使用: "/array\.content\(\'?[0-9]+\'?,\'?([0-9]+)\'?\,[^\)]*\)\;/ui" 测试: htt ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)