CvCapture_FFMPEG::setProperty( int property_id, double value ) incorrect + FIX (Bug #120)
Description
CvCapture_FFMPEG::setProperty( int property_id, double value )
is incorrect.
av_seek_frame
" incorrectly because:
- it give it wrong parameters
av_seek_frame
return only key frames, and so you can not use setProperty function to set the capture to a non-key frame.
FIX:¶
i written a function that seek for the nearest key frame and from there it grab frames until it reach the desired frame.
1#DEFINE SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER
2bool seekKeyAndRunOverFrames(int framenumber)
3{
4 int ret;
5 if (framenumber > video_st->cur_dts-1)
6 {
7 if (framenumber-(video_st->cur_dts-1) > SHORTER_DISTANCE_FOR_SEEK_TO_MAKE_IT_FASTER) {
8 ret=av_seek_frame(ic, video_stream, framenumber, 1);
9 assert(ret>=0);
10 if(ret<0)
11 return false;
12 }
13 grabFrame();
14 while ((video_st->cur_dts-1) < framenumber)
15 if ( !grabFrame() ) return false;
16 }
17 else if ( framenumber < (video_st->cur_dts-1) )
18 {
19 ret=av_seek_frame(ic, video_stream, framenumber, 1);
20 assert(ret>=0);
21 if(ret<0)
22 return false;
23 grabFrame();
24 while ((video_st->cur_dts-1) < framenumber )
25 if ( !grabFrame() ) return false;
26 }
27 return(true);
28}
and it is called by setProperty
:
1bool CvCapture_FFMPEG::setProperty( int property_id, double value )
2{
3 if( !video_st ) return false;
4 int ret;
5 int framenumber;
6 AVRational time_base;
7 switch( property_id )
8 {
9 case CV_CAP_PROP_POS_FRAMES:
10 framenumber=(int)value;
11 return seekKeyAndRunOverFrames(framenumber);
12 break;
13
14 case CV_CAP_PROP_POS_MSEC:
15 framenumber=value/(1000.0f * av_q2d (video_st->time_base));
16 return seekKeyAndRunOverFrames(framenumber);
17 break;
18
19 default:
20 return false;
21 }
22
23 return false;
24}
CV_CAP_PROP_POS_RATIO
should throw an "not implemented" exception as for many captures we can not get the correct number of frames per stream.
Associated revisions
Merge pull request #120 from NikoKJ:ocl2.4.3
Merge pull request #120 from ilya-lavrenov:tapi_precornerdetect
History
Updated by [email protected] - over 14 years ago
I can confirm that this patch (with the minor modifications that I made to it to make OpenCV compile with it) fixes the longstanding CV_CAP_PROP_POS
bug for me.
Updated by Victor Eruhimov over 14 years ago
- Status deleted (
Open)
Updated by Furqan Khan over 13 years ago
I spent quite some time getting around this issue and tried integrating different ffmpeg versions with OpenCV. Finally, the solution suggested here worked for me. Although Ticket #871 was also raised about the same issue, however, the patch suggested there (which is now part of the latest OpenCV release) didn't work for me.
- Status set to Done
- (deleted custom field) set to fixed
Updated by Furqan Khan over 13 years ago
I spent quite some time getting around this issue and tried integrating different ffmpeg versions with OpenCV. Finally, the solution suggested here worked for me. Although Ticket #871 was also raised about the same issue, however, the patch suggested there (which is now part of the latest OpenCV release) didn't work for me.
- Status changed from Done to Cancelled
- (deleted custom field) deleted (
fixed)
Updated by Alexander Reshetnikov about 13 years ago
Thanks for the report, amit man! It's used in r7332.
Updated by Andrey Kamaev about 13 years ago
- Status changed from Cancelled to Done
- Target version set to 2.4.0
- Description changed from [[CvCapture]]_FFMPEG::setProperty( int property_id, double value ) is incorre... to @CvCapture_FFMPEG::setProperty( int property_id, double value )@ is incorrect... More
- Assignee changed from Vadim Pisarevsky to Alexander Reshetnikov
Updated by Andrey Kamaev over 12 years ago
- Category changed from highgui-images to highgui-video