On date Saturday 2009-01-10 02:45:14 +0200, Bogdan Coanda encoded:
> Hi,
>
> I'm trying to develop a project using the ffmpeg library, and while just
> about all is fine and well, I read and understood and applied most tutorials
> found, especially the one at http://www.dranger.com/ffmpeg/tutorial01.html,
> I have the following problem I can't find a way to bypass.
>
> because I need to speed up as much as I can the parsing of the video file, I
> have one thread that deals with av_read_frame and avcodec_decode_video, and
> when a frame is obtained, it is fed into a queue thatis watched by another
> thread which does the actual displaying, or any algorithm I want to test on
> the frames received.
>
> basically, the first thread's code is:
>
> AVPacket *packet = (AVPacket*)av_mallocz(sizeof(AVPacket));
> av_new_packet(packet, streamFormatCtx->packet_size);
>
> while(av_read_frame(streamFormatCtx, packet) >= 0)
> {
> if(packet->stream_index == videoStreamNo)
> {
> AVFrame *currentFrame = avcodec_alloc_frame();
>
> avcodec_decode_video(videoCodecCtx, currentFrame, &isFrameFinished,
> packet->data, packet->size);
>
> if(isFrameFinished != 0)
if(isFrameFinished)
is simpler and more readable.
> {
> VideoFrameQueue_enqueue(currentFrame);
> frameNo += 1;
> }
> }
>
> av_free_packet(packet);
> av_new_packet(packet, streamFormatCtx->packet_size);
> }
>
>
> The problem at hand is that even if I try to give avcodec_decode_video fresh
> pointers every time (currentFrame and packet), after avcodec_decode_video
> executes, *I always get the same pointers inside currentFrame->data*, which
> esentially means I can't save any array of frames as they will all have the
> same content.
>
> Can anybody tell me if there is any "clean" way to tell the library to give
> me new pointers for currentFrame->data ?
I'm not completely sure, but I think that no there aren't,
avcodec_decode_video() will fill the AVFrame with pointers to an
internal buffer containing the decoded data, this may be reused to
decode other frames (for example if it is an I-frame), and so this
buffer belongs to the decoder thread context, so you shouldn't pass
them around to other threads.
The only thing you can do is to dup the AVPicture/AVFrame data and
just pass this copy to the other thread.
> Took me about a day and a half to figure what was happening, and although
> (now that I know), I cant just copy the given data arrays into fresh
> pointers for the queue, I need to make this as fast as possible...
>
> With Respect,
Regards.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user