我正在使用 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 流式传输视频。