PyAV-Org/PyAV

Segfault trying to grab a single frame

Closed this issue · 3 comments

Hi Mike,

(From Issue #60)

I revisited this but am getting a segmentation fault from this code:

#!/usr/bin/python
import av
import logging
from PIL import Image

logging.basicConfig(level=logging.DEBUG)

rtmpurl = 'rtmpurl'

def frame_iter(video):
    count = 0
    aframes = 1
    video = av.open(video)
    streams = [s for s in video.streams if s.type == b'video']
    streams = [streams[0]]
    for packet in video.demux(streams):
        for frame in packet.decode():
            yield frame
            return

s = list(frame_iter(rtmpurl))
s = s[0]
print s.height
plane = s.planes[0]
print plane
print type(plane)
print plane.line_size
plane = plane.to_bytes()
print plane

I ran python inside gdb and it looks like the error is:

<av.VideoPlane at 0x7fffe972a808>
<type 'av.video.plane.VideoPlane'>
960
[Thread 0x7fffddb02700 (LWP 28530) exited]

Program received signal SIGSEGV, Segmentation fault.
__memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:33
33      ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S: No such file or directory.

Seems like this is a 'known' libav bug per:
https://trac.videolan.org/vlc/ticket/11450

Is there a way around this?

I'm not entirely sure I see the connection to the linked LibAV bug, except for the same _memcpy_sse2_unaligned being used.

Do you get the same issue if you use the buffer interface of the VideoPlane object?

So instead of converting the whole thing to bytes, can you pick some data out of it, e.g.:

>>> buffer(plane)[0]

If I followed it correctly,

<av.VideoPlane at 0x7fffe9727938>
<type 'av.video.plane.VideoPlane'>
960

Program received signal SIGSEGV, Segmentation fault.
0x00000000004ab598 in PyString_FromStringAndSize ()

Modified the bottom of the code above with:

s = list(frame_iter(rtmpurl))
s = s[0]
plane = s.planes[0]
print plane
print type(plane)
print plane.line_size
test = buffer(plane)[0]
print test