LAVFilters icon indicating copy to clipboard operation
LAVFilters copied to clipboard

Support for seeking by frame via ConvertTimeFormat

Open berndfuhrmann opened this issue 2 years ago • 1 comments

It would be helpful to have frame-based seeking in the LAV demuxer. I need it specifically for MP4. I saw https://github.com/Nevcairiel/LAVFilters/issues/338 and wondered, if it would be possible to use FFMPEG to seek to the right frame, maybe by using libavformat av_index_search_timestamp. Fully supporting frames in SetTimeFormat could be a bit much to ask. But maybe adding support for ConvertTimeFormat would be less work. IMHO it would just be a call to FFMPEG and if in luck, a result is returned, if not, an error is returned. That could make frame-based seeking doable for some applications.

I hope I understand DirectShow correct there, but it seems IsFormatSupported would then still label frames as unsupported format. It would just happen to work in ConvertTimeFormat, if conditions are right.

Do you think that approach makes sense? If you think that is acceptable, I could try to make a PR.

Thanks in advance for considering!

berndfuhrmann avatar Dec 21 '22 14:12 berndfuhrmann

Converting from timestamp to frame number or vice-versa will never be very accurate due to rounding errors, gaps, or even variable frame rate. But I guess you could do something like this: seek_time = start_time + (frame_number + 0.5) * frame_rate (the +0.5 is to calculate the time in middle of start and end of frame, so least chance of getting wrong one)

For frame by frame playback you can also use this: https://learn.microsoft.com/en-us/windows/win32/api/strmif/nn-strmif-ivideoframestep

clsid2 avatar Dec 21 '22 14:12 clsid2