简体   繁体   中英

Python av play file in infinite loop

Using https://pypi.org/project/av/ trying to open file for infinite playback. But the cycle ends with the last frame.

After searching and reading manuals, test code looks as follows:

(Note: these options are expected to be passed down to aiortc.contrib.media.MediaPlayer and work similarly):

import av
av.open(file="file.mp4", options={"fflags": "+genpts", "loop": "-1"})
for frame in media.decode():
    print(frame)

Question: What should be the options (and if it is possible) to play file in infinite loop? (NOT just once)

According to the documentation , you create a MediaPlayer using the parameter loop=True

from aiortc.contrib.media import MediaPlayer

player = MediaPlayer(file="file.mp4", options={"fflags": "+genpts"}, loop=True)

You don't need to call PyAV yourself. It is done in MediaPlayer (see source code ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM