Problem of decoding h264 video with ffmpeg (Patch #1223)
Description
The new release of 2.3 got problem of decoding h264 video with ffmpeg.
The decoded video loses about first 3 seconds, which means the ffmpeg decodes from the middle.
There is no problem if I roll back to OpenCV 2.2.
History
Updated by Vadim Pisarevsky over 13 years ago
try the just released OpenCV 2.3.1. Probably, the problem is solved there.
Updated by ZhiHeng NIU over 13 years ago
I just tried SVN version of OpenCV 2.3.2 (Aug 18,2011). The same problem remains. When I roll back to OpenCV 2.2 DLLs, it is fine.
My code:
int main(int argc, char** argv)
{
string avipath1("..\\video\\video1.avi");
string avipath2("..\\video\\video2.avi");
VideoCapture cap1(avipath1),cap2(avipath2);
int w1,w2,h1,h2,w,h;
Mat image1,image2,image,subimage;
cap1>>image1;
cap2>>image2;
w1 = image1.cols;
h1 = image1.rows;
w2 = image2.cols;
h2 = image2.rows;
assert(w1==w2 && h1==h2);
w = w1 + w2;
h = h1;
VideoWriter writer("..\\output\\result.avi",CV_FOURCC('M','J','P','G'),30,Size(w,h));
image.create(h,w,CV_8UC3);
while(!image1.empty() && !image2.empty())
{
Mat roi1(image,Rect(0,0,w1,h1));
image1.copyTo(roi1);
Mat roi2(image,Rect(w1,0,w2,h2));
image2.copyTo(roi2);
imshow("Playing...",image);
waitKey(10);
writer << image;
cap1>>image1;
cap2>>image2;
}
cap1.release();
cap2.release();
return 0;
}
Updated by ZhiHeng NIU about 13 years ago
I fixed the problem for my case. However I am not sure whether it could cause new problems.
[Simple Explanation]
1) In line 589 of cap_ffmpeg_impl.hpp, change "av_seek_frame(ic, video_stream, ts, flags);" back to "av_seek_frame(ic, video_stream, ts, 0);"
2) Follow instruction of ".\3rdparty\ffmpeg\readme.txt" and recompile the opencv_ffmpeg.dll.
[Detailed Explanation]
1) When I did the grab() for the first time and checked the frame number by using get(CV_CAP_PROP_POS_FRAMES), surprisingly it didn't give me 0 or 1 but a number more than that.
2) I tried to set the frame back to the begining by using set(CV_CAP_PROP_POS_FRAMES,1.0). But it gave me a waining message and failed to seek back.
3) I searched from web and found some similar defects as #1419, #1335 and #120.
4) Someone says the last parameter of av_seek_frame() caused the problems.
5) In line 589 of cap_ffmpeg_impl.hpp (in CvCapture_FFMPEG::open()), changing it to be 0 (as in OpenCV220) fixed the prolem of starting from half way.
6) In line 837 of cap_ffmpeg_impl.hpp (in CvCapture_FFMPEG::setProperty()), changing it to be AVSEEK_FLAG_ANY fixed the prolem of not being able to seek to cerntain position.
7) In order to make the changes effective, It is needed to recompile opencv_ffmpeg.dll by following instruction of ".\3rdparty\ffmpeg\readme.txt".
Updated by Alexander Shishkov about 13 years ago
- Description changed from The new release of 2.3 got problem of decoding h264 video with ffmpeg. The d... to The new release of 2.3 got problem of decoding h264 video with ffmpeg. The d... More
Updated by Alexander Shishkov almost 13 years ago
- Tracker changed from Bug to Patch
- Priority changed from High to Normal
- Target version deleted ()
Updated by Alexander Shishkov almost 13 years ago
- Priority changed from Normal to High
Updated by Alexander Shishkov almost 13 years ago
- Assignee deleted (
Vadim Pisarevsky)
Updated by Alexander Shishkov almost 13 years ago
- Target version deleted ()
Updated by Andrey Morozov almost 13 years ago
- Target version set to 2.4.0
Updated by ZhiHeng NIU almost 13 years ago
Good work, you guys!
I have just tried the svn version of #8085. In this version the problem has been fixed. Thank you!
Look forward to the final release of OpenCV2.4.
Updated by Alexander Reshetnikov almost 13 years ago
- Status changed from Open to Done
- Priority changed from High to Normal
- Assignee set to Alexander Reshetnikov
Updated by Andrey Kamaev over 12 years ago
- Category changed from highgui-images to highgui-video