Heim > Backend-Entwicklung > PHP-Tutorial > php获取flv视频时间_PHP教程

php获取flv视频时间_PHP教程

WBOY
Freigeben: 2016-07-13 17:39:30
Original
888 Leute haben es durchsucht

php获取flv时间!有源码!拿来就可以使用!超级简单。

<ol class="dp-c">
<li class="alt"><span><span><?php  </span></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 class="vars">$byte_wordlen</span><span>; </span><span class="vars">$i</span><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 <span class="vars">$byte_wordlen</span><span> - 1));  </span></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>
</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 class="vars">$flv_data_length</span><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>
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage