Home > Back-end >  JavaCV RTSP turn RTMP is implemented, and push the video stream to the cloud Nginx server
JavaCV RTSP turn RTMP is implemented, and push the video stream to the cloud Nginx server

Time:09-16

The import org. Bytedeco. Javacpp. Avcodec;
The import org. Bytedeco. Javacv. FFmpegFrameGrabber;
The import org. Bytedeco. Javacv. FFmpegFrameRecorder;
The import org. Bytedeco. Javacv. Frame;
The import org. Bytedeco. Javacv. OpenCVFrameConverter;

To introduce the development kit implementation transcoding to push streaming service

 
The static Boolean exit=false;
Public static void main (String [] args) throws the Exception {
System. Out.println (" start... ");
String rtmpPath="RTMP://111.230. * * *. * * * : 1936/HLS/YFZX2";
String rtspPath="RTSP://admin: [email protected]:554/h264/ch34/sub/av_stream";

Int audioRecord=0;//0=not recorded, 1=recording
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 the Exception {
//need to use when using RTSP FFmpegFrameGrabber, can no longer use FrameGrabber
Int width=640, height=480;
FFmpegFrameGrabber grabber=FFmpegFrameGrabber. CreateDefault (rtspPath);
Grabber. SetOption (" rtsp_transport ", "TCP");//using TCP, or you will lost package serious

Grabber. SetImageWidth (width);
Grabber. SetImageHeight (height);
System. The out. Println (" grabber and start ");
Grabber. Start ();
//streaming output address resolution (long, high), whether recording audio (0: no record/1: recording)
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 ");//the type of the RTMP
Recorder. SetFrameRate (25);
Recorder. SetImageWidth (width); Recorder. SetImageHeight (height);
Recorder. SetPixelFormat (0);//yuv420p
System. The out. Println (" recorder start ");
Recorder. The start ();
//
OpenCVFrameConverter. ToIplImage conveter=new OpenCVFrameConverter. ToIplImage ();
System. Out.println (" all start!!!!! ");
Int count=0;
while(! The exit) {
count++;
=Frame Frame grabber. GrabImage ();
If (frame==null) {
continue;
}
If (count %==0 100) {
System. The out. Println (" count="+ count);
}
Recorder. Record (frame);
}

Grabber. Stop ();
Grabber. Release ();
Recorder. Stop ();
Recorder. The release ();
}


Video streaming is normal out, but there are warning information

[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd8500cfa00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd850c3ba00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd850c3ba00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd850c3ba00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd8500cfa00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd851513600] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd851513600] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd84fd04c00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd851513600] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd8500cfa00] deprecated pixel format, informs, make sure you did the set range correctly
[swscaler @ 0 x7fd851513600] deprecated pixel format, informs, make sure you did the set range correctly


CodePudding user response:

You use the pixel format is the FLV does not support, need to specify the format
Recorder. SetPixelFormat (avutil. AV_PIX_FMT_YUV420P);

CodePudding user response:

You can refer to:
https://jingyan.baidu.com/article/6dad5075d8885fe022e36e38.html

CodePudding user response:

I take a video stream in the callback function, just don't know how to use javaCV forwarded to the RTMP

CodePudding user response:

There is no way to solve.
I choose to ignore it
 
//to filter out the warn log
Avutil. Av_log_set_level (avutil. AV_LOG_ERROR);
  • Related