|
From: Sven A. <sv...@gm...> - 2007-06-03 12:14:43
|
Hi Anand,
i understand your frustration. In the beginning to programm such stuff i was
often frustated too.
I can describe you my solution.
In my application i developed a cut program, that worked only with I-Frames.
But with a little modification it worked with every kind of image-types.
For the libmpeg2 is it really important to send not only some "packets" to the
Lib. You have to send a sequence header followed by an i-frame, and so far,
if you want to decode the rest of your pictures, you have to send a p-frame
after the i-frame, and at least all your b-frames, to deode your pictures
correctly.
I do it in a following way:
In buffer i put in a sequence-header and an i-frame
The Decoding Process:
while (parsing)
{
int state = mpeg2_parse(mDecoder);
switch (state)
{
case STATE_BUFFER:
mpeg2_buffer(mDecoder, buffer, &buffer[blength]);
break;
case STATE_SEQUENCE:
mpeg2_convert(mDecoder, mpeg2convert_rgb24, NULL);
pixel = mInfo->sequence->width * mInfo->sequence->height;
for( int i=0; i<3; i++)
{
framebuffer[i][0] = new uint8_t[3*pixel+1];
framebuffer[i][1] = framebuffer[i][2] = NULL;
if (!framebuffer[i][0])
{
exit(0);
}
mpeg2_set_buf(mDecoder, framebuffer[i], NULL);
}
break;
case STATE_SLICE:
case STATE_END: if (mInfo->display_fbuf)
{
//cout << "Dekodiere I-Frame: " << endl;
flength = 3*pixel + 15;
frame = new uint8_t[flength+1];
// Buffer vorbereiten
memset(frame, '\0', flength);
// Bildheader
sprintf((char*)frame,"P6\n%d %d\n255\n", mInfo->sequence->width,
mInfo->sequence->height);
// dekodierten Bildinhalt kopieren
memcpy(&frame[15],mInfo->display_fbuf->buf[0], flength);
parsing = false;
}
break;
}
Hope it helps a little bit.
regards,
sven
PS: You can test alternativly the ffmpeg lib. There you can a beautyful
example under libavcodec/apiexampe.c. Check it out, maybe you have more luck
with that library it connection with your application.
Am Freitag 01 Juni 2007 17:44 schrieb anand meher:
> hi everyone,
>
> i am using mpeg2dec.c program of libmpeg2.i have modified
> it in a such a way that it can accept input on a udp port. I am using a
> transport stream as an input. i am hardcoding the pid of the video as of
> now. I am demuxing and then sending the packets to the decoder.But when i
> save the images in a .ppm format i am seeing blocks in the .ppm frames .
> can anyone help me with this problem?
>
> regards
> anand.
|