CAN I demux or decode container at native frame rate?
Overview
When I read the local video file and get its' packets, the packets will be loaded in very quickly. Can I make it loaded at a fixed rate like “ffmpeg -re” ?
The simple read code is like:
import time
import av
import av.datasets
video_file_path = './local_file.mp4'
video_file_path = 'rtmp://localhost:1935/live/livestream'
container = av.open(str(video_file_path), 'r')
begin_time = time.time()
for index, frame in enumerate(container.decode(video=0)):
print(f"dts = {frame.dts}, pts={frame.pts}, frame={frame.index}, "
f"time={frame.time:2.2f}, readtime={time.time()-begin_time}")
Expected behavior
The read time is approximately equal to the frame.time like reading the rtmp media:
dts = 16410, pts=16410, frame=409, time=16.41, readtime=15.198821067810059
dts = 16450, pts=16450, frame=410, time=16.45, readtime=15.20190691947937
dts = 16490, pts=16490, frame=411, time=16.49, readtime=15.209179162979126
dts = 16530, pts=16530, frame=412, time=16.53, readtime=15.211419105529785
dts = 16570, pts=16570, frame=413, time=16.57, readtime=15.234949111938477
Actual behavior
The read time is much too less than the frame.time
dts = 147456, pts=147456, frame=288, time=11.52, readtime=0.7378249168395996
dts = 147968, pts=147968, frame=289, time=11.56, readtime=0.7406580448150635
dts = 148480, pts=148480, frame=290, time=11.60, readtime=0.7432849407196045
dts = 148992, pts=148992, frame=291, time=11.64, readtime=0.7457869052886963
dts = 149504, pts=149504, frame=292, time=11.68, readtime=0.7484250068664551
dts = 150016, pts=150016, frame=293, time=11.72, readtime=0.7512478828430176
Investigation
I tried to add {"-readrate": "1"} options to parameter options or container_options of av.open, but it doesn't work.
Research
I have done the following:
-
Checked the PyAV documentation -
Searched on Google -
Searched on Stack Overflow -
Looked through old GitHub issues -
Asked on PyAV Gitter -
... and waited 72 hours for a response.
Additional context
{{ Add any other context about the problem here. }}