ffmepg started to learn two camera docking

1. Prepare

nginx-1.7.11.3-Gryphon download

Link: https: //pan.baidu.com/s/1EANAajsoGQcvjfphAuOoRQ 
extraction code: lhwb 

nginx.conf

Link: https: //pan.baidu.com/s/1IX26h92tUHD4XV5T4qygDw 
extraction code: c0z4 
copy the contents of this open Baidu network disk phone App, the operation more convenient oh

ffmpeg

Link: https: //pan.baidu.com/s/1oh_36qFxnLW5Kmdf8F5eTQ 
extraction code: rsdn 
copy the contents of this open Baidu network disk phone App, the operation more convenient oh

 

Decompression nginx-1.7.11.3-Gryphon, the downloaded nginx.conf, copied to the conf nginx-1.7.11.3-Gryphon, the port number is 5080 remember

2.ffmpeg environment to build

To see if the installation was successful 

3. Push stream transcoding

MP4 finished loading all because of the need to play, so the format used here m3u8

First guarantee, nginx has been launched to complete, so the test can be completed start

 Transcoding command:

ffmpeg -i "rtsp://admin:[email protected]:554/Streaming/Channels/101?transportmode=unicast" -c copy -f hls -hls_time 5 -hls_list_size 6 -hls_wrap 5 d:\project\direct\40\camera.m3u8
  
  

After the success of the corresponding directory will generate a file 

4. The front-end code 

Front-end browser compatibility issues need to be resolved, the following code is the Google version, ie need to use the flash, the front needs to do a corresponding identification code browser


  
  
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>java交流群 828638052 前端播放m3u8格式视频 </title>
  6. <link href="https://vjs.zencdn.net/7.4.1/video-js.css" rel="stylesheet">
  7. <script src='https://vjs.zencdn.net/7.4.1/video.js'> </script>
  8. <script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js" type="text/javascript"> </script>
  9. <!-- videojs-contrib-hls 用于在电脑端播放 如果只需手机播放可以不引入 -->
  10. </head>
  11. <body>
  12. <style>
  13. .video-js .vjs-tech { position: relative !important;}
  14. </style>
  15. <div>
  16. <video id="myVideo" muted class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" data-setup='{}' style='width: 100%;height: auto'>
  17. <source id="source" src="http://192.168.7.55:5080/images/camera.m3u8" type="application/x-mpegURL"> </source>
  18. </video>
  19. </div>
  20. <div class="qiehuan" style="width:100px;height: 100px;background: red;margin:0 auto;line-height: 100px;color:#fff;text-align: center">切换视频 </div>
  21. </body>
  22. <script>
  23. // videojs 简单使用
  24. var myVideo = videojs( 'myVideo', {
  25. bigPlayButton: true,
  26. textTrackDisplay: false,
  27. posterImage: false,
  28. errorDisplay: false,
  29. })
  30. myVideo.play()
  31. var changeVideo = function (vdoSrc) {
  32. if ( /\.m3u8$/.test(vdoSrc)) { //判断视频源是否是m3u8的格式
  33. myVideo.src({
  34. src: vdoSrc,
  35. type: 'application/x-mpegURL' //在重新添加视频源的时候需要给新的type的值
  36. })
  37. } else {
  38. myVideo.src(vdoSrc)
  39. }
  40. myVideo.load();
  41. myVideo.play();
  42. }
  43. var src = 'http://192.168.7.55:5080/images/camera.m3u8';
  44. document.querySelector( '.qiehuan').addEventListener( 'click', function () {
  45. changeVideo(src);
  46. })
  47. </script>

注意:http://192.168.7.55:5080/images/camera.m3u8 这个地址是nginx对应服务器 

        images 是反向代理,映射到本地D:\project\direct\40,不然会有跨域的问题,导致视频无法正常播放

nginx.conf里面的配置,这里就不过多的阐述勒。详细配置找度娘

   

转载自:https://blog.csdn.net/qq_16855077/article/details/89839708

发布了42 篇原创文章 · 获赞 115 · 访问量 1万+

1.准备

Guess you like

Origin blog.csdn.net/luoyong_blog/article/details/104497325