PDA

View Full Version : Best way to stream and record a webcam



ichigo
17th November 2010, 01:50
Hi all!

I'm new to this forum, and also relatively new to Qt programming.

I'm developing (or trying to develop) a instant messaging program with webcam support (this is essential). It has to be multiplatform and be able to record and stream the video to another PC in the same network.

For now, I have working the chat part and the local webcam using the QCamera class from qt-mobility, but I don't know if this is the best way as it doesn't seem trivial how to stream it...

I'm thinking to use gstreamer, maybe with phonon? but I'm getting lost with all the libraries and with the best way to make it also multiplatform

Maybe I could try to launch gstreamer to record and stream the webcam, later with a "VideoPlayer" form phonon show the stream of both the local and the remote webcam... is this possible?

Do you know any example on how to use gstreamer?

I'm developing with QtCreator under linux, but it also has to work in windows...

Thanks!

ichigo
17th November 2010, 17:26
Ok, so I made some progress although I don't know if it's in the good direction :confused:

First of all, I have tested gstreamer alone, with gst-launch, and it works great to capture, record and stream the webcam both on linux and windows. If anyone is interested this is the command I use for the server part in linux (it also works in windows with some changes):



gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv,width=640,height=480,framerate=30/1 ! tee name=t_vid ! queue ! videorate ! video/x-raw-yuv,framerate=30/1 ! theoraenc ! queue ! oggmux ! filesink location=test.ogg t_vid. ! queue ! xvimagesink sync=false t_vid. ! queue ! ffmpegcolorspace ! smokeenc keyframe=8 qmax=40 ! udpsink host=192.168.2.70 port=5000


I also have been able to play a video recorded with the command above with this code:



QCoreApplication::setApplicationName("PhononTest");
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
Phonon::createPath(mediaObject, videoWidget);

QString url("./test.ogg");
mediaObject->setCurrentSource(url);
mediaObject->play();


But I still don't know how to show the live stream in the VideoWidget, I think setCurrentSource doesn't support that, but I'm not sure...

It also would be great to be able to know how to launch gstreamer from my program, but I think first I have to be able to show the stream... any ideas?

Is it possible with phonon or do I have to make it with plain gstreamer libraries? any examples?

Thanks!

ichigo
17th November 2010, 21:34
Well, this is starting to become a monologue, maybe due to my impatience... :D

But, in case anyone is interested I'm starting to get it working thanks to QtGStreamer which can be obtained from http://gitorious.org/qtgstreamer (more info in http://gkiagia.wordpress.com/) and makes it easy to work with GStreamer :-)

I still have to test if QtGst will compile under windows, but in linux all works well :-)

So many thanks to the QtGStreamer developers for making it so easy that a newbie can get it working in one day! :D:D:D

vattipalli
21st June 2014, 18:07
hi,

can you help me how you are streaming webcam using qt-gstreamer.
I am using Qt-4.8.5.
I am using linux.

obalouchi
28th June 2014, 00:51
this worked for me ;)

void gst_setup()
{

gst_init (NULL,NULL);

bin = gst_pipeline_new ("pipeline");
g_assert( bin);



testSrc = gst_element_factory_make("v4l2src", "source");
g_assert(testSrc);



ffmpegcs = gst_element_factory_make ( "ffmpegcolorspace", "ffmpegcs" );


encoder = gst_element_factory_make ( "jpegenc", "encoder" );
g_assert(encoder);





tcp = gst_element_factory_make ("tcpserversink", "tcp");
g_assert(tcp);


muxer = gst_element_factory_make ( "multipartmux", "muxer");


g_object_set(tcp , "host", "192.168.5.77", NULL );
g_object_set(tcp , "port", 5000 , NULL );
g_object_set (testSrc, "capture-mode", 3 , NULL);


videoOut = gst_element_factory_make("autovideosink", "video out");
g_assert(videoOut);




gst_bin_add_many(GST_BIN( bin), testSrc, ffmpegcs, encoder, muxer , tcp , NULL);


gst_element_link_many( testSrc, ffmpegcs ,encoder, muxer, tcp, NULL);
}
if you have any questions let me know
my Email : obalouchi1@gmail.com