首頁 >php教程 >php手册 >php获取flv视频时间

php获取flv视频时间

WBOY
WBOY原創
2016-06-13 10:38:20886瀏覽

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);  
</span>
</li>
</ol>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn