gpt4 book ai didi

video-streaming - 使用 javacv 将视频流式传输到 rtsp 服务器

转载 作者:行者123 更新时间:2023-12-01 05:22:28 28 4
gpt4 key购买 nike

我正在使用 java CV 进行视频流。我从网络摄像头捕获了视频。但是当我尝试将流传输到 Darwin 服务器时它失败了。代码是,

package streamingapp;

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.avcodec;
import com.googlecode.javacv.cpp.opencv_objdetect;
import static com.googlecode.javacv.cpp.avutil.*;
import static com.googlecode.javacv.cpp.opencv_core.*;


public class StreamingApp {

public static void main(String[] args) throws Exception {

Loader.load(opencv_objdetect.class);
CanvasFrame frame = new CanvasFrame("webcam");
FrameGrabber grabber = new OpenCVFrameGrabber(0);

grabber.setImageHeight(500);
grabber.setImageWidth(500);
grabber.start();

IplImage grabbedImage = grabber.grab();
int width = grabbedImage.width();
int height = grabbedImage.height();

CvMemStorage storage = CvMemStorage.create();

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("rtsp://ipaddress:portno/testVideoStream.3gp", width, height);



recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setFormat("rtsp");
recorder.setFrameRate(grabber.getFrameRate());
recorder.setVideoCodec(13);
recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
recorder.setVideoBitrate(10 * 1024 * 1024);
recorder.start();

int i = 0;

while (frame.isVisible() && (grabbedImage = grabber.grab()) != null) {
System.out.println("(" + i++ + ") Invio. . .");
frame.showImage(grabbedImage);
recorder.record(grabbedImage);
}

cvClearMemStorage(storage);
recorder.stop();
grabber.stop();
}

}

是否可以使用 rtsp 格式的 javacv 流式传输视频。

最佳答案

试试这个......我得到了结果(达尔文服务器)

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("rtp://ipaddress:portno/testVideoStream.sdp", width, height);

recorder.setVideoCodec(13);
recorder.setFormat("rtp");
recorder.setFrameRate(30);

//recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
//recorder.setVideoBitrate(10 * 1024 * 1024);
recorder.start();

关于video-streaming - 使用 javacv 将视频流式传输到 rtsp 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15758158/

28 4 0