Hi everyone!
Im starting to program with libavcodec and the other libraries.
I made a little program that changes the red component of the pixels of every
frame in a video file. I don´t get errors in the compilation, but when I try to 
execute
the program, it fails.
If I debug the program, I can see the error is in the function av_write_frame, 
but I
don´t know what I´m doing wrong...

This is a part of my code:
<code>
AVFormatContext *pFormatCtx;
AVFormatContext *pFormatCtxOut;
AVCodecContext  *pCodecCtx;
AVCodec             *pCodec;
AVFrame             *pFrame; 
AVFrame             *pFrameRGB;
AVPacket              packet;
int                        frameFinished;
int                        numBytes;
uint8_t                 *buffer;
...

pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
    if(pCodec==NULL)
        return -1; 

if(avcodec_open(pCodecCtx, pCodec)<0)
        return -1; 

 pFrame=avcodec_alloc_frame();

 pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL)
        return -1;

numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
        pCodecCtx->height);
buffer=new uint8_t[numBytes];

avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
        pCodecCtx->width, pCodecCtx->height);
            
while(av_read_frame(pFormatCtx, &packet)>=0)
    {
        if(packet.stream_index==videoStream)
        {
            avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, 
                packet.data, packet.size);
            
            if(frameFinished)
            {
                img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24, 
                    (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width, 
                    pCodecCtx->height);

                for(i=0; i<pFrameRGB->linesize[0]; i++){
                    if ((i%3)==0){
                        pFrameRGB->data[0][i] = 50;
                    }
                }
                img_convert((AVPicture *)pFrame, pCodecCtx->pix_fmt, 
                    (AVPicture*)pFrameRGB, PIX_FMT_RGB24, pCodecCtx->width, 
                    pCodecCtx->height);
                
                avcodec_encode_video(pCodecCtx,packet.data,packet.size,pFrame);
            }

            if(av_write_frame(pFormatCtxOut,&packet) < 0){
                printf("Error\n");
                return -1;
            }
        }
</code>

The message "Error" doesn´t appear in the standard output...

Can you tell me what  is wrong?
Sorry for my english and thanks!!! 

_________________________________________________________________
Tecnología, moda, motor, viajes,…suscríbete a nuestros boletines para estar 
siempre a la última
Guapos y guapas, clips musicales y estrenos de cine. 
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to