PDA

View Full Version : Load a sequence of frames



perseo
1st April 2008, 16:20
Hello to all, I have one problem.

My situation is the next:
- I can extract all frames of one video. (I can't use QMovie because I have another format)
- I would like to view these frames in a QLabel.

I did these things but when I probe, I only view the last frame of my video, I think that this is a problem of refresh ¿?
--> data is the bytes in unsigned char format. All the process is ok because I view the last frame perfect. Always I view the last frame perfect, but before this, I didn't see nothing...

I do the next instructions for each frame:


qimg = QImage(data, img_w, img_h, QImage::Format_RGB32);
Label->setPixmap(QPixmap::fromImage(qimg));

aamer4yu
1st April 2008, 16:40
It seems u are loading and displaying only the last image.
To show movie, load the frames one by one in a timer and display it, that will give the effect of movie

Hope I am making sense :)

jpn
1st April 2008, 16:54
Also, you cannot just set the images in a busy loop. You have to let the application process its events to let the label receive update events. You could change images with help of QTimer (or alternatively you can call QCoreApplication::processEvents() during every loop iteration which is a bit uglier approach).

wysota
1st April 2008, 16:55
When do you change frames? Can we see a larger portion of code?

perseo
1st April 2008, 16:59
Yes... this code works, because I probe with sdl surfaces and i saw the video


while ( (av_read_frame(pFormatCtx_l, &packet_l)>=0) && (av_read_frame(pFormatCtx_r, &packet_r)>=0) ) {

if ( (packet_l.stream_index == videoStream_l) && (packet_r.stream_index == videoStream_r) ) {
// Decode video frame
avcodec_decode_video(pCodecCtx_l, pFrame_l, &frameFinished_l, packet_l.data, packet_l.size);
avcodec_decode_video(pCodecCtx_r, pFrame_r, &frameFinished_r, packet_r.data, packet_r.size);
// Did we get a video frame?
if ( (frameFinished_l) && (frameFinished_r) )
{
img_convert( (AVPicture *) pFrameRGB_l, PIX_FMT_BGR24, (AVPicture*)pFrame_l,
pCodecCtx_l->pix_fmt, pCodecCtx_l->width, pCodecCtx_l->height);
img_convert( (AVPicture *) pFrameRGB_r, PIX_FMT_BGR24, (AVPicture*)pFrame_r,
pCodecCtx_r->pix_fmt, pCodecCtx_r->width, pCodecCtx_r->height);

// Write pixel data
for(ay=0; ay<img_h; ay++)
{
memcpy(aux_l, pFrameRGB_l->data[0]+ay*pFrameRGB_l->linesize[0], ancho);
memcpy(aux_r, pFrameRGB_r->data[0]+ay*pFrameRGB_r->linesize[0], ancho);
// incrementar data_l, data_r para recorrer la imagen nueva e irla generando
aux_l += ancho;
aux_r += ancho;
}

img_raw_set_data (img_l, data_l);
img_raw_set_data (img_r, data_r);

data32_l = RGB24toARGB(img_l);
data32_r = RGB24toARGB(img_r);

qimg_l = QImage(data32_l, img_w, img_h, QImage::Format_RGB32);
qimg_r = QImage(data32_r, img_w, img_h, QImage::Format_RGB32);

leftLabel->setPixmap(QPixmap::fromImage(qimg_l));
rightLabel->setPixmap(QPixmap::fromImage(qimg_r));

}
aux_l = data_l;
aux_r = data_r;
}

wysota
1st April 2008, 17:05
It's a busy loop, so it won't work. You have to process events somewhere in between like jpn suggested.

perseo
1st April 2008, 22:43
I tried to introduce one timer and now i have one problem when i run the program:


private slots:
void updateLabel(unsigned char *data32_l, unsigned char *data32_r);

///////
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateLabel(data32_l,data32_r)));
timer->start();

and the function updateLabel is:

void FormMain::updateLabel(unsigned char *data32_l, unsigned char *data32_r)
{
timer->stop();
qimg_l = QImage(data32_l, img_w, img_h, QImage::Format_RGB32);
qimg_r = QImage(data32_r, img_w, img_h, QImage::Format_RGB32);

leftLabel->setPixmap(QPixmap::fromImage(qimg_l));
rightLabel->setPixmap(QPixmap::fromImage(qimg_r));
}

When i run the program i have this:

Object::connect: No such slot FormMain::updateLabel(data32_l,data32_r)
Object::connect: (receiver name: 'FormMainInterf')

I need help!

Thanks!

pherthyl
2nd April 2008, 00:06
connect(timer, SIGNAL(timeout()), this, SLOT(updateLabel(data32_l,data32_r)));


That code makes no sense. You're hooking up timeout() to a slot expecting arguments. Where do you think this data is going to come from? Also you have to give connect the types of the arguments, not the names. So unsigned char* instead of data32_l.

perseo
2nd April 2008, 13:12
Thank you very much to all, now my code works.
I use one timer.

bmn
20th May 2008, 13:29
I was able to load the sequence of frames into the label widget but having trouble with timing of the frames. It is displaying only the last frame of the file.