Get flv video time with php_PHP tutorial

WBOY
Release: 2016-07-13 17:39:30
Original
865 people have browsed it

Get flv time with php! There is source code! Just grab it and use it! Super simple.

<ol class="dp-c">
<li class="alt"><span><span><?php  </span></span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">function</span><span> BigEndian2Int(</span><span class="vars">$byte_word</span><span>, </span><span class="vars">$signed</span><span> = false) {  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$int_value</span><span> = 0;  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$byte_wordlen</span><span> = </span><span class="func">strlen</span><span>(</span><span class="vars">$byte_word</span><span>);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">for</span><span> (</span><span class="vars">$i</span><span> = 0; </span><span class="vars">$i</span><span> < </span><span class="vars">$byte_wordlen</span><span>; </span><span class="vars">$i</span><span>++)  </span></li><li><span> </span></li><li class="alt"><span>  {  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$int_value</span><span> += ord(</span><span class="vars">$byte_word</span><span>{</span><span class="vars">$i</span><span>}) * pow(256, (</span><span class="vars">$byte_wordlen</span><span> - 1 - </span><span class="vars">$i</span><span>));  </span></li><li><span> </span></li><li class="alt"><span>  }  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">if</span><span> (</span><span class="vars">$signed</span><span>)  </span></li><li><span> </span></li><li class="alt"><span>  {  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$sign_mask_bit</span><span> = 0x80 << (8 * (</span><span class="vars">$byte_wordlen</span><span> - 1));  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">if</span><span> (</span><span class="vars">$int_value</span><span> & </span><span class="vars">$sign_mask_bit</span><span>)  </span></li><li><span> </span></li><li class="alt"><span>  {  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$int_value</span><span> = 0 - (</span><span class="vars">$int_value</span><span> & (</span><span class="vars">$sign_mask_bit</span><span> - 1));  </span></li><li><span> </span></li><li class="alt"><span>  }  </span></li><li><span> </span></li><li class="alt"><span>  }  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">return</span><span> </span><span class="vars">$int_value</span><span>;  </span></li><li><span> </span></li><li class="alt"><span>  }  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">function</span><span> getTime(</span><span class="vars">$name</span><span>){  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">if</span><span>(!</span><span class="func">file_exists</span><span>(</span><span class="vars">$name</span><span>)){  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">return</span><span>;  </span></li><li><span> </span></li><li class="alt"><span>  } </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$flv_data_length</span><span>=</span><span class="func">filesize</span><span>(</span><span class="vars">$name</span><span>);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$fp</span><span> = @</span><span class="func">fopen</span><span>(</span><span class="vars">$name</span><span>, </span><span class="string">rb</span><span>);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$flv_header</span><span> = </span><span class="func">fread</span><span>(</span><span class="vars">$fp</span><span>, 5);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="func">fseek</span><span>(</span><span class="vars">$fp</span><span>, 5, SEEK_SET);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$frame_size_data_length</span><span> =BigEndian2Int(</span><span class="func">fread</span><span>(</span><span class="vars">$fp</span><span>, 4));  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$flv_header_frame_length</span><span> = 9;  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">if</span><span> (</span><span class="vars">$frame_size_data_length</span><span> > </span><span class="vars">$flv_header_frame_length</span><span>) {  </span></span></li>
<li><span> </span></li>
<li class="alt">
<span>  </span><span class="func">fseek</span><span>(</span><span class="vars">$fp</span><span>, </span><span class="vars">$frame_size_data_length</span><span> - </span><span class="vars">$flv_header_frame_length</span><span>, SEEK_CUR);  </span>
</li>
<li><span> </span></li>
<li class="alt"><span>  }  </span></li>
<li><span> </span></li>
<li class="alt">
<span>  </span><span class="vars">$duration</span><span> = 0;  </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>  </span><span class="keyword">while</span><span> ((</span><span class="func">ftell</span><span>(</span><span class="vars">$fp</span><span>) + 1) < </span><span class="vars">$flv_data_length</span><span>) {  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$this_tag_header</span><span> = </span><span class="func">fread</span><span>(</span><span class="vars">$fp</span><span>, 16);  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$data_length</span><span> = BigEndian2Int(</span><span class="func">substr</span><span>(</span><span class="vars">$this_tag_header</span><span>, 5, 3));  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$timestamp</span><span> = BigEndian2Int(</span><span class="func">substr</span><span>(</span><span class="vars">$this_tag_header</span><span>, 8, 3));  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="vars">$next_offset</span><span> = </span><span class="func">ftell</span><span>(</span><span class="vars">$fp</span><span>) - 1 + </span><span class="vars">$data_length</span><span>;  </span></li><li><span> </span></li><li class="alt"><span>  </span><span class="keyword">if</span><span> (</span><span class="vars">$timestamp</span><span> > </span><span class="vars">$duration</span><span>) {  </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>  </span><span class="vars">$duration</span><span> = </span><span class="vars">$timestamp</span><span>;  </span>
</li>
<li><span> </span></li>
<li class="alt"><span>  }  </span></li>
<li><span> </span></li>
<li class="alt">
<span>  </span><span class="func">fseek</span><span>(</span><span class="vars">$fp</span><span>, </span><span class="vars">$next_offset</span><span>, SEEK_SET);  
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486304.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/486304.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">php获取flv时间!有源码!拿来就可以使用!超级简单。 ?php function BigEndian2Int( $byte_word , $signed =false){ $int_value =0; $byte_wordlen = strlen ( $byte_word...</span>
</div>
<div class="art_confoot"></div></span>
</li>
</ol>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template