利用流媒體將RSTP流轉成WEB端可播放(使用ffmpeg+nginx)

ffmpeg:

下載鏈接:鏈接:https://pan.baidu.com/s/1btHQR4Ik3RKApjKPzvTUiw  提取碼:2yl8 

配置環境:

電腦-屬性-高級系統設置-環境變量-系統變量-path:

出現如下代表成功:

 

Nginx(帶rtmp模塊):

鏈接:https://pan.baidu.com/s/1jmc-ySktHvrbAi4Z9e8Upw 
提取碼:l1sx 

右擊以管理員身份運行;

win+R——cmd:

ffmpeg -i "rtsp://admin:****[email protected]:554/h264/ch01/sub/av_stream" -f flv -r 25 -s 640x360 -an rtmp://localhost:1935/live/sub

出現如下即可表明推流成功:

 

通過網頁調試:

可以看到已經成功拉到推的流了(網頁與rtsp相差無幾,但是用VLC播放時有幾秒延遲)

感覺應該是VLC播放的問題。

後續再處理rtmp鑑權相關問題。

提供相關參考地址:

https://blog.csdn.net/u014373554/article/details/87889772

https://blog.csdn.net/luoc83/article/details/79240774

https://www.cnblogs.com/wunaozai/p/9427730.html

-----------------------------------------------------------------------------------------------------------------------

測試了播放鑑權,是可行的,流程如下:

nginx的配置:

worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application rtmp {
            live on;
			on_play http://127.0.0.1:8081/rtmp/on_play;
        }
		
        #application hls {
        #  live on;
        #   hls on;  
        #   hls_path temp/hls;  
        #   hls_fragment 8s;  
        #}
    }
}

http {
    server {
        listen      8080;
		
        location / {
            root html;
        }
		
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
           root html;
        }
		
        location /hls {  
            #server hls fragments  
            types{  
                application/vnd.apple.mpegurl m3u8;  
               video/mp2t ts;  
            }  
            alias temp/hls;  
            expires -1;  
        }  
    }
}

#http {
#    server {
#        listen      8080;
#		
#        location / {
#            root html;
#        }
#		
#        location /stat {
#            rtmp_stat all;
#            rtmp_stat_stylesheet stat.xsl;
#        }
#
#        location /stat.xsl {
#            root html;
#        }
#		
#        location /hls {  
#            #server hls fragments  
#            types{  
#                application/vnd.apple.mpegurl m3u8;  
#                video/mp2t ts;  
#            }  
#            alias temp/hls;  
#            expires -1;  
#        }  
#    }
#}

spring boot的接口:

@Controller
@RequestMapping(value = "rtmp")
public class RtmpController {

    @Autowired
    private UserService userService;
    

    /***
     * 這是一種返回形式 以ModelAndView 視圖返回數據的形式返回 和返回map一樣 調用方式不一樣
     * */
    @RequestMapping(value="/on_play",method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public  String userLogin(HttpServletRequest request, HttpServletResponse response,HttpSession session){
         String id=request.getParameter("id");
         String password=request.getParameter("password");
         if(StringUtils.isBlank(id)||StringUtils.isBlank(password)){
        	 response.setStatus(500);
             return  "fail";
         }
         User user=new User();
         User loginUser=new User();
         user.setPassword(password);
         user.setUserId(Integer.parseInt(id));
         loginUser=userService.getUserById(user);
         if(null!=loginUser){
        	 return "ok";
         }
         response.setStatus(500);
         return  "fail";
    }
}

測試如下:

黃色區域是沒有攜帶id和pssword或者輸入錯誤的信息,下面就是正常的播放rtmp流

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章