我正在使用java CV进行视频流播放。我从网络摄像头捕获了视频。但是当我尝试将流传输到达尔文服务器时,它失败了。代码是,
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流式传输视频。
答案 0 :(得分:1)
试试这个....我得到了结果(达尔文服务器)
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();