3
我正在使用Java CV進行視頻流式傳輸。我從網絡攝像頭捕獲視頻。但是,當我試圖將流傳輸到達爾文服務器時,它失敗。代碼是,使用javacv將視頻流傳輸到rtsp服務器
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流式傳輸視頻。