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

php获取flv视频时间

WBOY
풀어 주다: 2016-06-13 10:38:20
원래의
884명이 탐색했습니다.

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>
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿