Hi,
I'm having some problems with libavcodec.
First of all, it looks that the include path for avcodec.h has at least
three possibilities,
depending on the version:
ffmpeg/avcodec.h (ubuntu intrepid)
libavcodec/avcodec.h (ubuntu jaunty)
ffmpeg/libavcodec/avcodec.h (debian Squeeze)
I can check for all of them on my configure script, but it would be much
easier if the
include path could be set with 'pkg-config --cflags'.
Now for my second (and major) problem.
In my application I'm encoding live streams from a webcam.
Users can currently choose from 3 libavcodec codecs (mpegvideo1, flv1
and wmv1).
All codecs work just fine, but after I use any of the codecs for
encoding a video clip,
if I then choose a different codec, the second video clip will have some
image corruption
at the beginning (grey screen/blocks).
After this, if I reset the video codec to the original one, the video
clip will be fine again.
So basically It just works well for the first codec we use for encoding.
I'm closing the codec and cleaning all encoding data as soon as the
video capture stops,
so I can't understand what's causing this corruption.
This is my clean function:
//--------------------------------------------------------
void clean_lavc (void* arg)
{
struct lavcData** data= (struct lavcData**) arg;
if(*data)
{
avcodec_flush_buffers((*data)->codec_context);
//close codec
avcodec_close((*data)->codec_context);
//free codec context
g_free((*data)->codec_context);
(*data)->codec_context = NULL;
g_free((*data)->tmpbuf); //yuv420p buffer
g_free((*data)->outbuf); //output buffer from encoder
g_free((*data)->picture); //AVFrame
g_free(*data);
*data = NULL;
}
//----------------------------------------------------------
and codec initialization (mpegvideo1 in this case):
//-----------------------------------------------------------
struct lavcData* init_mpeg (int width, int height, int fps)
{
//allocate
struct lavcData* data = g_new0(struct lavcData, 1);
data->codec_context = NULL;
data->codec_context = avcodec_alloc_context();
// find the mpeg video encoder
data->codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
if (!data->codec)
{
fprintf(stderr, "mpeg codec not found\n");
return(NULL);
}
//alloc picture
data->picture= avcodec_alloc_frame();
// setting some codec_context parameters
.............//............
.............//............
//get the codec
if (avcodec_open(data->codec_context, data->codec) < 0)
{
fprintf(stderr, "could not open codec\n");
return(NULL);
}
//alloc tmpbuff (yuv420p)
data->tmpbuf = g_new0(BYTE, (width*height*3)/2);
//alloc outbuf
data->outbuf_size = 240000;
data->outbuf = g_new0(BYTE, data->outbuf_size);
return(data);
}
//----------------------------------------------------------------
Before I enter the video grab loop I call for avcodec_init() and
avcodec_register_all()
For the rest I just use avcodec_encode_video for encoding the video frame.
I use my own avi muxer and twolame for encoding audio.
Am I missing something here ?
I feel like I need to reset something, but I don't know what.
Best regards,
Paulo
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user