1.下载nginx(windows版已包含rtmp模块): 链接: https://pan.baidu.com/s/1IX8X2lzSfnIMeTOxv8o16g 提取码: q6cx 2. 配置rtmp : rtmp { server { listen 1935; chunk_size 4000; application live { live on; } application hls { live on; hls on; hls_path temp/hls; hls_fragment 8s; } } } 3.下载ffmpeg-20200831-4a11a6f-win64-static.zip 解压后配置 环境变化path ; 安装路径/bin 4. 查看版本号cmd 执行 ffmpeg -version 5. 通过cmd 推送一个rtsp转换成rtmp ffmpeg -rtsp_transport tcp -i “rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov” -vcodec copy -acodec copy -f flv “rtmp://127.0.0.1:1935/live/sz50” 6. java 推送代码
static boolean exit = false; public static void main(String[] args) throws Exception { System.out.println("start..."); String rtmpPath = "rtmp://ip:ng配置的端口/live/代号"; //live和ng配置中的要一直 String rtspPath = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; int audioRecord =0; // 0 = 不录制,1=录制 boolean saveVideo = false; push(rtmpPath,rtspPath,audioRecord,saveVideo); System.out.println("end..."); } public static void push(String rtmpPath,String rtspPath,int audioRecord,boolean saveVideo ) throws Exception { // 使用rtsp的时候需要使用 FFmpegFrameGrabber,不能再用 FrameGrabber int width = 640,height = 480; FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(rtspPath); grabber.setOption("rtsp_transport", "tcp"); // 使用tcp的方式,不然会丢包很严重 grabber.setImageWidth(width); grabber.setImageHeight(height); System.out.println("grabber start"); grabber.start(); // 流媒体输出地址,分辨率(长,高),是否录制音频(0:不录制/1:录制) FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(rtmpPath,width,height, audioRecord); recorder.setInterleaved(true); //recorder.setVideoOption("crf","28"); recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264); // 28 recorder.setFormat("flv"); // rtmp的类型 recorder.setFrameRate(25); recorder.setImageWidth(width);recorder.setImageHeight(height); recorder.setPixelFormat(0); // yuv420p System.out.println("recorder start"); recorder.start(); // OpenCVFrameConverter.ToIplImage conveter = new OpenCVFrameConverter.ToIplImage(); System.out.println("all start!!"); int count = 0; while(!exit){ count++; Frame frame = grabber.grabImage(); if(frame == null){ continue; } if(count % 100 == 0){ System.out.println("count="+count); } recorder.record(frame); } grabber.stop(); grabber.release(); recorder.stop(); recorder.release(); }