It'd be nice to be able to add random access to the API here. The following works for my configuration, but I'm not submitting it as a PR because:
it has an off-by-factor-of-two error in the conversion from time (in seconds) to the integer time that I couldn't track down. (found it)
I'm uncertain how to verify that it will work in all your supported configurations.
It's blind monkey-see-monkey-do code based upon seekstart; I don't know what these things are actually doing.
Feel free to use this (or not) however you see fit.
function Base.seek(s::VideoIO.VideoReader, time, video_stream=1)
pCodecContext = s.pVideoCodecContext
seek(s.avin, time, video_stream)
VideoIO.avcodec_flush_buffers(pCodecContext)
s
end
function Base.seek(avin::VideoIO.AVInput, time, video_stream = 1)
# AVFormatContext
fc = avin.apFormatContext[1]
# Get stream information
stream_info = avin.video_info[video_stream]
seek_stream_index = stream_info.stream_index0
stream = stream_info.stream
time_base = stream_info.codec_ctx.time_base
ticks_per_frame = stream_info.codec_ctx.ticks_per_frame
# Seek
ret = VideoIO.av_seek_frame(fc, seek_stream_index, convert(Int, div(time*time_base.den, time_base.num*ticks_per_frame)), VideoIO.AVSEEK_FLAG_ANY)
ret < 0 && throw(ErrorException("Could not seek to start of stream"))
return avin
end
It'd be nice to be able to add random access to the API here. The following works for my configuration, but I'm not submitting it as a PR because:
it has an off-by-factor-of-two error in the conversion from time (in seconds) to the integer time that I couldn't track down.(found it)seekstart
; I don't know what these things are actually doing.Feel free to use this (or not) however you see fit.