<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt;4.1.2-1</li>
<li>Operating System / Platform =&gt; Linux (Arch)</li>
<li>Compiler =&gt; gcc (but not relevant)</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">cap=cv2.VideoCapture (this is python 3 code!)<br>
cap.get(cv2.CAP_PROP_POS_MSEC) does not work, if not cap.read has been called before.<br>
The current version does not seem to read the position in milliseconds, if a cap.read() has not been issued before the query. It works in Version 4.1.1-1</p>
<h5 dir="auto">Steps to reproduce</h5>

<p dir="auto">This python3 code shows the problem:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import cv2

cap=cv2.VideoCapture(&quot;set/your/file/here&quot;)
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
cnt = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print(&quot;Opencv width %d frames %d&quot;%(w,cnt))

cap.read()
ts= cap.get(cv2.CAP_PROP_POS_MSEC)
print(&quot;ts @ frame 0 after read %.3f&quot;%ts)

#set pos
cap.set(cv2.CAP_PROP_POS_FRAMES,5)
ts= cap.get(cv2.CAP_PROP_POS_MSEC)
print(&quot;ts @ frame 5 after setPos %.3f&quot;%ts)

ret,frame=cap.retrieve()
ts= cap.get(cv2.CAP_PROP_POS_MSEC)
print(&quot;ts @ frame 5 after retrieve %.3f&quot;%ts)

ret,frame=cap.read()
ts= cap.get(cv2.CAP_PROP_POS_MSEC)
print(&quot;ts @ frame 5 after read %.3f&quot;%ts)

cap.release()

if __name__ == '__main__':
    pass"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">cv2</span>

<span class="pl-s1">cap</span><span class="pl-c1">=</span><span class="pl-s1">cv2</span>.<span class="pl-v">VideoCapture</span>(<span class="pl-s">"set/your/file/here"</span>)
<span class="pl-s1">w</span> <span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_FRAME_WIDTH</span>)
<span class="pl-s1">cnt</span> <span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_FRAME_COUNT</span>)
<span class="pl-en">print</span>(<span class="pl-s">"Opencv width %d frames %d"</span><span class="pl-c1">%</span>(<span class="pl-s1">w</span>,<span class="pl-s1">cnt</span>))

<span class="pl-s1">cap</span>.<span class="pl-en">read</span>()
<span class="pl-s1">ts</span><span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_POS_MSEC</span>)
<span class="pl-en">print</span>(<span class="pl-s">"ts @ frame 0 after read %.3f"</span><span class="pl-c1">%</span><span class="pl-s1">ts</span>)

<span class="pl-c">#set pos</span>
<span class="pl-s1">cap</span>.<span class="pl-en">set</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_POS_FRAMES</span>,<span class="pl-c1">5</span>)
<span class="pl-s1">ts</span><span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_POS_MSEC</span>)
<span class="pl-en">print</span>(<span class="pl-s">"ts @ frame 5 after setPos %.3f"</span><span class="pl-c1">%</span><span class="pl-s1">ts</span>)

<span class="pl-s1">ret</span>,<span class="pl-s1">frame</span><span class="pl-c1">=</span><span class="pl-s1">cap</span>.<span class="pl-en">retrieve</span>()
<span class="pl-s1">ts</span><span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_POS_MSEC</span>)
<span class="pl-en">print</span>(<span class="pl-s">"ts @ frame 5 after retrieve %.3f"</span><span class="pl-c1">%</span><span class="pl-s1">ts</span>)

<span class="pl-s1">ret</span>,<span class="pl-s1">frame</span><span class="pl-c1">=</span><span class="pl-s1">cap</span>.<span class="pl-en">read</span>()
<span class="pl-s1">ts</span><span class="pl-c1">=</span> <span class="pl-s1">cap</span>.<span class="pl-en">get</span>(<span class="pl-s1">cv2</span>.<span class="pl-v">CAP_PROP_POS_MSEC</span>)
<span class="pl-en">print</span>(<span class="pl-s">"ts @ frame 5 after read %.3f"</span><span class="pl-c1">%</span><span class="pl-s1">ts</span>)

<span class="pl-s1">cap</span>.<span class="pl-en">release</span>()

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-k">pass</span></pre></div>
<p dir="auto">Result for Version 4.1.2-1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Opencv width 720 frames 9000
ts @ frame 0 after read 0.000
ts @ frame 5 after setPos -2969.967
ts @ frame 5 after retrieve -2969.967
ts @ frame 5 after read 520.000"><pre class="notranslate"><code class="notranslate">Opencv width 720 frames 9000
ts @ frame 0 after read 0.000
ts @ frame 5 after setPos -2969.967
ts @ frame 5 after retrieve -2969.967
ts @ frame 5 after read 520.000
</code></pre></div>
<p dir="auto">Result for Version 4.1.1-1:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Opencv width 720 frames 9000
ts @ frame 0 after read 40.000
ts @ frame 5 after setPos 480.000
ts @ frame 5 after retrieve 480.000
ts @ frame 5 after read 520.000"><pre class="notranslate"><code class="notranslate">Opencv width 720 frames 9000
ts @ frame 0 after read 40.000
ts @ frame 5 after setPos 480.000
ts @ frame 5 after retrieve 480.000
ts @ frame 5 after read 520.000
</code></pre></div>
<p dir="auto">Transferred from <a href="http://code.opencv.org/issues/3006" rel="nofollow">http://code.opencv.org/issues/3006</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="|| Hans Meine on 2013-05-03 10:57
|| Priority: Normal
|| Affected: branch 'master' (2.4.9)
|| Category: highgui-camera
|| Tracker: Bug
|| Difficulty: None
|| PR: 
|| Platform: None / None"><pre class="notranslate"><code class="notranslate">|| Hans Meine on 2013-05-03 10:57
|| Priority: Normal
|| Affected: branch 'master' (2.4.9)
|| Category: highgui-camera
|| Tracker: Bug
|| Difficulty: None
|| PR: 
|| Platform: None / None
</code></pre></div>
<h2 dir="auto">libv4l capturing backend diverged from v4l backend</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Currently, we have cap_v4l.cpp and cap_libv4l.cpp with a lot of duplicated code, but also some unwanted differences.

For instance, the recent addition of CV_CAP_PROP_POS_MSEC support to the v4l backend was not merged to the libv4l backend.

Do we really want to maintain both completely separately?"><pre class="notranslate"><code class="notranslate">Currently, we have cap_v4l.cpp and cap_libv4l.cpp with a lot of duplicated code, but also some unwanted differences.

For instance, the recent addition of CV_CAP_PROP_POS_MSEC support to the v4l backend was not merged to the libv4l backend.

Do we really want to maintain both completely separately?
</code></pre></div>
<h2 dir="auto">History</h2>