DivX Decoding Problems

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

DivX Decoding Problems

Konstantin Gorskov
Hi! I'm using ffmpeg libs ported for WINCE and video file, encoded with PocketDivXEncoder 0.36
Audio decodes and plays fine. But when it comes to video, this is what I get:

first loop: pkt-size = 78, pkt->data = "blablablalblalala";
second loop: pkt-size = 78, pkt->data = "blablablalblalala";
third loop: pkt-size = 79, pkt->data = "blablablalblalala";
fourth loop: pkt-size = 3780, pkt->data = "0 ''"; - CRASH

Thats is part if the code, which never reaches "frameFinished":

                        while(av_read_frame(ic, pkt)>=0)
                        {
                                                                                // Decode video frame

                                        avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                                                pkt->data, pkt->size);
                               
                                                                                 //Did we get a video frame?
                                        if(frameFinished)
                                        {
                                        //write to file
                                               
                                        }
                                        av_free_packet(pkt);
                                }

It works, for sample, if I decode mpeg2 video (video is somehow consists of 3 streched frames in one but well anyway), but DivX encoded video crashes on third loop with this output:

Data Abort: Thread=95c01400 Proc=8c247700 'ffdecode.exe'
AKY=00010001 PC=014c9a68 RA=014d9ae4 BVA=203ad5c4 FSR=00000405
Unhandled exception at 0x014c9a68 in ffdecode.exe: 0xC0000005: Access violation reading location 0x003ad5c4.


Any suggestions what am I doing wrong?


_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: DivX Decoding Problems

Michael Conrad-6
Just to cover the obvious... you aren't passing audio (or subtitle)  
packets to the video decoder are you?

On Sat, 07 Jun 2008 11:38:55 -0400, Konstantin Gorskov  
<[hidden email]> wrote:

> Hi! I'm using ffmpeg libs ported for WINCE and video file, encoded with  
> PocketDivXEncoder 0.36
> Audio decodes and plays fine. But when it comes to video, this is what I  
> get:
>
> first loop: pkt-size = 78, pkt->data = "blablablalblalala";
> second loop: pkt-size = 78, pkt->data = "blablablalblalala";
> third loop: pkt-size = 79, pkt->data = "blablablalblalala";
> fourth loop: pkt-size = 3780, pkt->data = "0 ''"; - CRASH
>
> Thats is part if the code, which never reaches "frameFinished":
>
> while(av_read_frame(ic, pkt)>=0)
> {
> // Decode video frame
>
> avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
> pkt->data, pkt->size);
>
> //Did we get a video frame?
> if(frameFinished)
>                                         {
>                                         //write to file
>
> }
> av_free_packet(pkt);
> }
>
> It works, for sample, if I decode mpeg2 video (video is somehow consists  
> of 3 streched frames in one but well anyway), but DivX encoded video  
> crashes on third loop with this output:
>
> Data Abort: Thread=95c01400 Proc=8c247700 'ffdecode.exe'
> AKY=00010001 PC=014c9a68 RA=014d9ae4 BVA=203ad5c4 FSR=00000405
> Unhandled exception at 0x014c9a68 in ffdecode.exe: 0xC0000005: Access  
> violation reading location 0x003ad5c4.
>
>
> Any suggestions what am I doing wrong?
>
>
> _______________________________________________
> libav-user mailing list
> [hidden email]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: DivX Decoding Problems

Konstantin Gorskov

> Just to cover the obvious... you aren't passing audio (or subtitle)  
> packets to the video decoder are you?
>
No, here is more of the code :

                else if (pkt->stream_index == is->video_stream) {

            AVCodecContext *pCodecCtx = ic->streams[pkt->stream_index]->codec;
                        pFrame=avcodec_alloc_frame();
                        pFrameRGB=avcodec_alloc_frame();
            if(pFrameRGB==NULL)
            return -1;
                        numBytes=avpicture_get_size(PIX_FMT_RGB24, 320,
                              240);
            buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
                                                avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
                                320, 240);
i=0;
                        while(av_read_frame(ic, pkt)>=0)
                        {
                                                                                // Decode video frame

                                        avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                                                pkt->data, pkt->size);
                               
                                                                                 //Did we get a video frame?
                                        if(frameFinished) {
                                                 //Convert the image from its native format to RGB
                                        // img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
                                                        //(AVPicture*)pFrame, pCodecCtx->pix_fmt, &pCodecCtx->width,
                                                        //pCodecCtx->height);
                                                 //Save the frame to disk
                                                if(++i>=5)
                                                {
                                                        SaveFrame2(pFrame, pCodecCtx->width, pCodecCtx->height, i);
                                                }
                                        }
                                        av_free_packet(pkt);
                                }



As You can see, I'm working with video stream. Audio is decoded before, and I can hear a bit of it playing before crash. No subtitles are present.
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Output pFrame pixel by pixel

Konstantin Gorskov
In reply to this post by Michael Conrad-6
Hi! I can not understand this part of code:
    for(int y=0; y<240; y++)
    //fwrite(pFrame->data[0]+y*pFrameRGB->linesize[0], 1, 320*3, bufptr);

I know, it outputs image file with frame. But, for sample, what linesize[0] is there for? And why there is only 240 output steps? Not 240*320?. Is there a way to access every pixel as I need in my program? Put it one by one.
If I understand correct, all pixel data are stored here, at data[0]? Can I, for sample, access pixel number 32 in a row?

Regards,
Konstantin.
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

swscale's license

Thomas Rehaag
Hello,

I've tried to configure ffmpeg with:
./configure --enable-shared --disable-static --enable-memalign-hack
--disable-gpl --enable-swscale

But I was told:
"The software scaler is under GPL and --enable-gpl is not specified."

The first lines of swscale.h tell something different:

 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either

So can annybody please point me to the truth about the license of
swscale?
And if it's really GPL, is there any way to get back img_convert?

Best Regards,

Thomas
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: Output pFrame pixel by pixel

Michael Conrad-6
In reply to this post by Konstantin Gorskov
On Mon, 09 Jun 2008 13:57:45 -0400, Konstantin Gorskov  
<[hidden email]> wrote:
> Hi! I can not understand this part of code:
>     for(int y=0; y<240; y++)
>     //fwrite(pFrame->data[0]+y*pFrameRGB->linesize[0], 1, 320*3, bufptr);
>
> I know, it outputs image file with frame. But, for sample, what  
> linesize[0] is there for?

Imagine this: you have an image which is 11 pixels wide and 5 pixels tall,  
1 byte per pixel.  In order to copy the frame using SSE2 instructions, the  
row length must be a multiple of 16.  So for this example, libraries like  
ffmpeg would allocate 16x5 bytes.

PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....
PPPPPPPPPPP.....

So:
   frame->w == 11
   frame->h == 5
   frame->linesize[0] == 16

But, when saving to disk, you don't want to waste space, so you get rid of  
the padding:
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP
PPPPPPPPPPP

> Can I, for sample, access pixel number 32 in a row?

So, to access pixel (column,row) in a packed image which was saved to  
disk, you use
   pixel= data[ row * width + column ];
but for image frames with padding, you need
   pixel= frame->data[0][ row * frame->linesize[0] + column ];

> And why there is only 240 output steps? Not 240*320?

fwrite copies a block of data, not just one pixel.  Also, the *only*  
reason fwrite was called more than once was to skip the padding.  **If  
there was no padding**, the entire frame could be copied with
   fwrite(frame->data[0], 1, 320*240*3, file)

> If I understand correct, all pixel data are stored here, at data[0]?

Yes.  For RGB, all data is in plane 0.  In some formats, however, the  
colors are in separate "planes"  ("planar RGB", "planar YUV", etc).  For  
these, plane N is data[N] with a width of linesize[N].

Hope that helps ;-)
-Mike
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: DivX Decoding Problems

Michael Conrad-6
In reply to this post by Konstantin Gorskov
On Sat, 07 Jun 2008 13:47:14 -0400, Konstantin Gorskov  
<[hidden email]> wrote:

>
>> Just to cover the obvious... you aren't passing audio (or subtitle)
>> packets to the video decoder are you?
>>
> No, here is more of the code :

> else if (pkt->stream_index == is->video_stream) {
[...]
> while(av_read_frame(ic, pkt)>=0)
[...]
>
> As You can see, I'm working with video stream. Audio is decoded before,  
> and I can hear a bit of it playing before crash. No subtitles are  
> present.

Well, not quite.  The stream is a mixture of audio and video packets, in  
no particular sequence.  You test to see that the packet is a video  
packet, but then overwrite that packet with a new packet (which could be  
video OR audio OR subtitle, or other kinds of data even) and then try to  
decode it as if it were video.

av_read_frame gives you the next packet in the stream.  Also, keep in mind  
that the AVPacket object does always not own this data: it is merely a  
struct giving you pointers to data owned by the demuxer.

The code sequence needs to be

    while(av_read_frame(ic, pkt)>=0) {
      if (pkt->stream_index == /*whatever*/) {
      else if (pkt->stream_index == /*whatever*/) {
      else if (pkt->stream_index == /*whatever*/) {
      etc
      av_free_packet(pkt)
    }

and it is up to you to write the code you want to possibly decode it, copy  
the packet to use later, or do whatever with its contents.  But, the above  
sequence must be used.


-Mike
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: swscale's license

Luca Abeni
In reply to this post by Thomas Rehaag
Hi Thomas,

Thomas Rehaag wrote:

> I've tried to configure ffmpeg with:
> ./configure --enable-shared --disable-static --enable-memalign-hack
> --disable-gpl --enable-swscale
>
> But I was told:
> "The software scaler is under GPL and --enable-gpl is not specified."
>
> The first lines of swscale.h tell something different:
>
>  * This file is part of FFmpeg.
>  *
>  * FFmpeg is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU Lesser General Public
>  * License as published by the Free Software Foundation; either
>
> So can annybody please point me to the truth about the license of
> swscale?

If you look at all the files in the libswscale directory, you'll see
that some of them are released under GPL, some other are under LGPL.
As a result, the resulting library is released under GPL, because it
contains GPLed components.

So, both the configure output and the swscale.h header are correct.


> And if it's really GPL, is there any way to get back img_convert?

You don't need it.
Just configure ffmpeg without "--enable-swscale", and you will get
a library released under the LGPL license that implement the swscale
API by using the old image scaler contained in libavcodec.
Since swscale.h's license is LGPL, there is no problem.
If one day the license of swscale will change (I think there is a
gsoc project working on something similar), your program will be ready
to use libswscale without any change in the code.


                                Luca
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: Output pFrame pixel by pixel

Konstantin Gorskov
In reply to this post by Michael Conrad-6


-----Original Message-----
From: "Michael Conrad" <[hidden email]>
To: "Libav* user questions and discussions" <[hidden email]>
Date: Mon, 09 Jun 2008 20:33:35 -0400
Subject: Re: [libav-user] Output pFrame pixel by pixel

>
> On Mon, 09 Jun 2008 13:57:45 -0400, Konstantin Gorskov  
> <[hidden email]> wrote:
> > Hi! I can not understand this part of code:
> >     for(int y=0; y<240; y++)
> >     //fwrite(pFrame->data[0]+y*pFrameRGB->linesize[0], 1, 320*3, bufptr);
> >
> > I know, it outputs image file with frame. But, for sample, what  
> > linesize[0] is there for?
>
> Imagine this: you have an image which is 11 pixels wide and 5 pixels tall,  
> 1 byte per pixel.  In order to copy the frame using SSE2 instructions, the  
> row length must be a multiple of 16.  So for this example, libraries like  
> ffmpeg would allocate 16x5 bytes.
>
> PPPPPPPPPPP.....
> PPPPPPPPPPP.....
> PPPPPPPPPPP.....
> PPPPPPPPPPP.....
> PPPPPPPPPPP.....
>
> So:
>    frame->w == 11
>    frame->h == 5
>    frame->linesize[0] == 16
>
> But, when saving to disk, you don't want to waste space, so you get rid of  
> the padding:
> PPPPPPPPPPP
> PPPPPPPPPPP
> PPPPPPPPPPP
> PPPPPPPPPPP
> PPPPPPPPPPP
>
> > Can I, for sample, access pixel number 32 in a row?
>
> So, to access pixel (column,row) in a packed image which was saved to  
> disk, you use
>    pixel= data[ row * width + column ];
> but for image frames with padding, you need
>    pixel= frame->data[0][ row * frame->linesize[0] + column ];
>
> > And why there is only 240 output steps? Not 240*320?
>
> fwrite copies a block of data, not just one pixel.  Also, the *only*  
> reason fwrite was called more than once was to skip the padding.  **If  
> there was no padding**, the entire frame could be copied with
>    fwrite(frame->data[0], 1, 320*240*3, file)
>
> > If I understand correct, all pixel data are stored here, at data[0]?
>
> Yes.  For RGB, all data is in plane 0.  In some formats, however, the  
> colors are in separate "planes"  ("planar RGB", "planar YUV", etc).  For  
> these, plane N is data[N] with a width of linesize[N].
>
> Hope that helps ;-)
> -Mike
> _______________________________________________
> libav-user mailing list
> [hidden email]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>


 Thanks a lot for two brilliant answers. This will, for sure, help a lot of newbies like me. I really appreciate it.
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: swscale's license

Thomas Rehaag
In reply to this post by Luca Abeni


Luca Abeni schrieb:

>
> Hi Thomas,
>
> Thomas Rehaag wrote:
> > I've tried to configure ffmpeg with:
> > ./configure --enable-shared --disable-static --enable-memalign-hack
> > --disable-gpl --enable-swscale
> >
> > But I was told:
> > "The software scaler is under GPL and --enable-gpl is not specified."
> >
> > The first lines of swscale.h tell something different:
> >
> >  * This file is part of FFmpeg.
> >  *
> >  * FFmpeg is free software; you can redistribute it and/or
> >  * modify it under the terms of the GNU Lesser General Public
> >  * License as published by the Free Software Foundation; either
> >
> > So can annybody please point me to the truth about the license of
> > swscale?
>
> If you look at all the files in the libswscale directory, you'll see
> that some of them are released under GPL, some other are under LGPL.
> As a result, the resulting library is released under GPL, because it
> contains GPLed components.
>
> So, both the configure output and the swscale.h header are correct.
>
> > And if it's really GPL, is there any way to get back img_convert?
>
> You don't need it.
> Just configure ffmpeg without "--enable-swscale", and you will get
> a library released under the LGPL license that implement the swscale
> API by using the old image scaler contained in libavcodec.
> Since swscale.h's license is LGPL, there is no problem.
> If one day the license of swscale will change (I think there is a
> gsoc project working on something similar), your program will be ready
> to use libswscale without any change in the code.
>
>                                 Luca

Thanks a lot. I've seen swscale-0.dll for windows on
http://arrozcru.no-ip.org/ and so I didn't even think of a chance, that
sws_scale could be included in one of the dlls I've compiled.
Now I found it in avcodec.dll at the first view :)

Thomas
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

How to unload ffmpeg properly

Konstantin Gorskov
In reply to this post by Michael Conrad-6
Hi!
 I'm decoding video on Wm2005 device, and I have to fight for every single byte of memory there.
 I need to show video and after this, unload all memory it took complete. This is my steps:

        if (is->audio_stream >= 0)
        {
                stream_component_close(is, is->audio_stream);
        }

        if (is->video_stream >= 0)
        {
                stream_component_close(is, is->video_stream);
        }

        if (is->ic)
        {
                av_close_input_file(is->ic);
                is->ic = NULL; /* safety */
        }
         av_free(audio_bufs);
         av_free(buffer);
         av_free(pFrameRGB);
         av_free(pFrame);


However, about 3,5mb are still being in use. I see, that before video playback starts, there are
avdevice-52.dll, avformat-52, avutil-49 && dllavcodec-51.dll loaded into the memory. Is there function to release them as well? I'm kinda newbie, so all I can assume is that they are taking my precious 3,5 mb.
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user