okay I could use some tools like valgrind, but first I wanted to understand what is goigng on here.
Also I cannot test every case with valgrind as this code should work with different versions of ffmpeg and various kind of videos.
But anyway thanks for this idea, I might use it after I (might) figured out how to fix this bug correctly
My main question is: why / how does
av_free_packet (&packet);
impact
the AVFrame picture (set here: avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);)? And why is this only the case for a raw video input?
If I find out why this is the case I hope to be able to fix this without introducing a memory leak (or you can tell me that I am completly going in the wrong direction).
Gesendet: Donnerstag, 05. März 2015 um 14:57 Uhr
Von: poste9 <[email protected]>
An: "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <[email protected]>
Betreff: Re: [Libav-user] OpenCV VideoCapture FFmpeg Module Bug on Linux using Video without a Codec
Von: poste9 <[email protected]>
An: "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <[email protected]>
Betreff: Re: [Libav-user] OpenCV VideoCapture FFmpeg Module Bug on Linux using Video without a Codec
use valgrind
2015-03-05 10:50 GMT-03:00 Johannes Rehm <[email protected]>:
So this is the function where the error happens (look for av_free_packet (&packet);):bool CvCapture_FFMPEG::grabFrame()
{
bool valid = false;
int got_picture;int count_errs = 0;
const int max_number_of_attempts = 1 << 9;if( !ic || !video_st ) return false;if( ic->streams[video_stream]->nb_frames > 0 &&
frame_number > ic->streams[video_stream]->nb_frames )
return false;av_free_packet (&packet);picture_pts = AV_NOPTS_VALUE_;// get the next frame
while (!valid)
{
int ret = av_read_frame(ic, &packet);
if (ret == AVERROR(EAGAIN)) continue;/* else if (ret < 0) break; */if( packet.stream_index != video_stream )
{
av_free_packet (&packet);
count_errs++;
if (count_errs > max_number_of_attempts)
break;
continue;
}// Decode video frame
#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0)
avcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);
#elif LIBAVFORMAT_BUILD > 4628
avcodec_decode_video(video_st->codec,
picture, &got_picture,
packet.data, packet.size);
#else
avcodec_decode_video(&video_st->codec,
picture, &got_picture,
packet.data, packet.size);
#endif// Did we get a video frame?
if(got_picture)
{
//picture_pts = picture->best_effort_timestamp;
if( picture_pts == AV_NOPTS_VALUE_ )
picture_pts = packet.pts != AV_NOPTS_VALUE_ && packet.pts != 0 ? packet.pts : packet.dts;
frame_number++;
valid = true;
}
else
{
count_errs++;
if (count_errs > max_number_of_attempts)
break;
}//I need to comment out the following line to prevent an segmentation fault when processing a raw video file without a codec:av_free_packet (&packet);
}if( valid && first_frame_number < 0 )
first_frame_number = dts_to_frame_number(picture_pts);// return if we have a new picture or not
return valid;
}I am not even sure if there will be a memory leak if I delete av_free_packet (&packet);But they might put this command for a reason and I do not want to create a new bug.Sorry for asking such a basic question: do you know how I can verify that there will be no memory leak (with or without adding av_init_packet before)?Gesendet: Donnerstag, 05. März 2015 um 14:22 Uhr
Von: "Rafael Lúcio" <[email protected]>
An: "This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter." <[email protected]>
Betreff: Re: [Libav-user] OpenCV VideoCapture FFmpeg Module Bug on Linux using Video without a CodecI'm not an expert but maybe I can give u a simpler solution.... just ignore if I'm talking nonsense stuffs..maybe if u just av_init_packet before av_free_packet your problem is solved and you don't have memory leak.I haven't tested this theory, its just an idea._______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user2015-03-05 8:30 GMT-03:00 Johannes Rehm <[email protected]>:Hi All,there is a known bug in the VideoCapture ffmpeg module of OpenCV. It occurs while loading videos without a codec:I had some time now to debug this bug and found the issue in:CvCapture_FFMPEG::grabFrame()In the functionavcodec_decode_video2(video_st->codec, picture, &got_picture, &packet);the AVFrame picture get set. But afterav_free_packet (&packet);I get: "error: Cannot access memory at address..." for picture.data[0] which leads to a segmentation fault later in the function sws_scale().I can encode this video with a video codec using ffmpeg or whatever and I get no segmentation fault (memory in picture.data[0] can still be accessed).Of course there is an easy fix for this bug: Simply comment out / deleteav_free_packet (&packet);This is working fine for me. Now I can process videos with and without codecs. But I am not sure if this will lead to memory issues if av_free_packet gets not called. Is there anybody who is familiar with the FFmpeg interface of OpenCV and can help me here?Thanks a lot!Best regards,Johannes Rehm
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user
-------------------------------------------------------------------Rafael Lúcio
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user
_______________________________________________ Libav-user mailing list [email protected] http://ffmpeg.org/mailman/listinfo/libav-user
