I have a problem that when playing a video with pyglet apparently the beginning and the end of the stream is not handled correctly. The player ignores the first keyframe and thus shows glitches images until the it finds the second keyframe. Likewise the on_eos-event is not fire but python chrashes because it apparently tries to load more frames.
import pyglet
vidPath = "test.mp4"
window = pyglet.window.Window()
player = pyglet.media.Player()
source = pyglet.media.load(vidPath)
player.queue(source)
player.play()
@player.event
def on_eos():
print('video end')
@window.event
def on_draw():
window.clear()
if player.source and player.source.video_format:
player.get_texture().blit(0, 0)
pyglet.app.run()
I am using Python 3.4.3, pyglet 1.2.4 and AVbin 10 on OSX 10.11.3.
Trying the same code and videos on Ubuntu I get the same problems and the following errors on start:
Non-reference picture received and no reference available
[h264 @ 0x3386700] decode_slice_header error
Non-reference picture received and no reference available
[h264 @ 0x33880e0] decode_slice_header error
Non-reference picture received and no reference available
[h264 @ 0x3388520] decode_slice_header error
[h264 @ 0x3388a80] illegal short term buffer state detected
Non-reference picture received and no reference available
[h264 @ 0x3388a80] decode_slice_header error
[h264 @ 0x338c2e0] reference picture missing during reorder
[h264 @ 0x338c2e0] reference picture missing during reorder
[h264 @ 0x338c2e0] reference picture missing during reorder
and these once the video has reached the end:
[h264 @ 0x23bde00] no frame!
[h264 @ 0x23bf7e0] AVC: nal size 0
[h264 @ 0x23bf7e0] AVC: nal size 0
[h264 @ 0x23bf7e0] no frame!
[h264 @ 0x23bfc20] AVC: nal size 0
[h264 @ 0x23bfc20] AVC: nal size 0
Any ideas what is the problem here? I have some videos that start correctly but the end is never recognized.
I've also run into the problem with the beginnings of files being glitchy when played through pyglet. I "fixed" it by re-encoding and force-adding a few extra keyframes at the start of the file:
avconv -i glitchy-file.mp4 -force_key_frames 0.01,0.02,0.03 \
-c:v h264 -c:a copy not-glitchy-file.mp4
This approach should work with suitably recent versions of ffmpeg too (just replace avconv
with ffmpeg
). I've only tested it with h264-encoded video streams, on linux, with avbin10, and libav built locally from their git master branch.
It is a hack, not a solution, since it doesn't tell you why pyglet is ignoring keyframes early in the stream, nor does it cause pyglet to read them correctly. But it makes the problem go away.
来源:https://stackoverflow.com/questions/34922943/pyglet-avbin-misses-beginning-and-end-of-video