Giter Club home page Giter Club logo

pyav's Introduction

PyAV

GitHub Test Status Gitter Chat Documentation
Python Package Index Conda Forge

PyAV is a Pythonic binding for the FFmpeg libraries. We aim to provide all of the power and control of the underlying library, but manage the gritty details as much as possible.

PyAV is for direct and precise access to your media via containers, streams, packets, codecs, and frames. It exposes a few transformations of that data, and helps you get your data to/from other packages (e.g. Numpy and Pillow).

This power does come with some responsibility as working with media is horrendously complicated and PyAV can't abstract it away or make all the best decisions for you. If the ffmpeg command does the job without you bending over backwards, PyAV is likely going to be more of a hindrance than a help.

But where you can't work without it, PyAV is a critical tool.

Installation

Due to the complexity of the dependencies, PyAV is not always the easiest Python package to install from source. Since release 8.0.0 binary wheels are provided on PyPI for Linux, Mac and Windows linked against a modern FFmpeg. You can install these wheels by running:

pip install av

If you want to use your existing FFmpeg, the source version of PyAV is on PyPI too:

pip install av --no-binary av

Installing from source is not supported on Windows.

Alternative installation methods

Another way of installing PyAV is via conda-forge:

conda install av -c conda-forge

See the Conda install docs to get started with (mini)Conda.

And if you want to build from the absolute source (POSIX only):

git clone https://github.com/PyAV-Org/PyAV.git
cd PyAV
source scripts/activate.sh

# Either install the testing dependencies:
pip install --upgrade -r tests/requirements.txt
# or have it all, including FFmpeg, built/installed for you:
./scripts/build-deps

# Build PyAV.
make
pip install .

Have fun, read the docs, come chat with us, and good luck!

pyav's People

Contributors

adavoudi avatar billyshambrook avatar bryant1410 avatar caspervdw avatar corco avatar crackwitz avatar danielballan avatar daveisfera avatar heni avatar hmaarrfk avatar jlaine avatar joeschiff avatar laggykiller avatar markreidvfx avatar mephi42 avatar mikeboers avatar mildsunrise avatar mkassner avatar moi90 avatar papr avatar philipnbbc avatar radek-senfeld avatar skeskinen avatar skirsdeda avatar tacaswell avatar uvjustin avatar vidartf avatar willpatera avatar wyattblue avatar xxr3376 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyav's Issues

Problems with international characters in metadata

I've built PyAV for python 3, and it works fine, except that it fails on reading metadata from files, if they contain unicode/international (I'm not sure) characters. I.e. I had file with title for audio channel with russian letters, and got exception:

"UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)"

I fixed that by changing the avdict_to_dict so that it returns bytebuffers instead of strings as values:

cdef dict avdict_to_dict(lib.AVDictionary *input):

    cdef lib.AVDictionaryEntry *element = NULL
    cdef dict output = {}
    cdef bytes value
    while True:
        element = lib.av_dict_get(input, "", element, lib.AV_DICT_IGNORE_SUFFIX)
        if element == NULL:
            break
        value = element.value
        output[element.key] = value
    return output

Maybe you'll find some other, more nicer way, but I'm not sure if there is a way to determine right encoding.

rtsp support

Hi,

Tried using the most recent PyAV just to get stream information from a RTSP stream. Does the library lack support?

Error when trying av.open on a rtsp stream:

No handlers could be found for logger "libav.rtsp"

Thanks

Missing macro

I tried buliding PyAv on linux and get this:

build/av/utils.c: In function ‘__pyx_f_2av_5utils_err_check’:
build/av/utils.c:1041:32: error: ‘AV_ERROR_MAX_STRING_SIZE’ undeclared (first use in this function)
build/av/utils.c:1041:32: note: each undeclared identifier is reported only once for each function it appears in
error: command 'gcc' failed with exit status 1

building it against ffmpeg-1.0

Python3 install

I tried to install with python3.4 on debian (testing) but the setup failed to detect the libraries
I think the problem comes from the line 39 in setup.py:

for chunk in str(raw_config).strip().split():

the type of raw_config is bytes and str(raw_config) doesn't return the same thing with python3 or python2

Python 2

str(b'test') # Ouput : "test"

Python 3

str(b'test') # Output : "b'test'"

I fixed this by replacing the line 39 with

for chunk in raw_config.decode().strip().split():

The great reorganization

I'm splitting the base/audio/video/subtitle classes into their own modules, and can't decide how to compose the new files.

Option 1: by stream/frame

    av/
        stream/
            base
            audio
            video
        frame/
            base
            audio
            video

Option 2: by audio/video

    av/
        base/
            stream
            frame
        audio/
            stream
            frame
        video/
            stream
            frame

@markreidvfx, any idea as to which is better in the grand scheme of the universe? I'm leaning towards av.{base,audio,video}.{stream,frame}.

Codec works in command-line ffmpeg but is not found by PyAV.

PyAV may not be recognizing all the available codecs. This has me stumped -- any insights are appreciated.

This FFmpeg command works as expected:

ffmpeg -i foo.mov -c:v libvpx foo.webm

but PyAV can't find that libvpx codec:

In [1]: import av

In [2]: output = av.open('foo.webm', 'w')

In [3]: stream = output.add_stream(b'libvpx', 30)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-1375cc77bb95> in <module>()
----> 1 stream = output.add_stream('libvpx', 30.)

/home/dallan/PyAV/av/container.so in av.container.OutputContainer.add_stream (/home/dallan/PyAV/src/av/container.c:4486)()

/home/dallan/PyAV/av/container.so in av.container.OutputContainer.add_stream (/home/dallan/PyAV/src/av/container.c:4010)()

ValueError: unknown encoding codec: 'libvpx'

Incidentally, the above works fine on my OSX installation, but not on my 12.04 installation. I don't think this has anything to do with the architectures per say; it merely shows that this can and should work.

variable frame rate video

Hi,

First of, this project is fantastic, we had be searching for useable ffmpeg python bindings for a while now. Really enjoying PyAV.

We want to record video from a live source and use recording timestamps at pts for each frame since the source may change frame rate.

Looking at video/stream.pyx L116-L120 i can see that frame.pts gets scaled. But frame.time_base is always 0/0 thus creating non-sensical pts. I cannot figure out how to set frame.time_base, before I add this as a variable I wanted to better understand your motivation for the above mentioned lines.

I guess the question comes down to understanding the input args for lib.av_rescale_q.

Could you give me a pointer?

thanks!

File size >=2**31 wraps around

Reported via an email.


So, I'm not sure if this is a ffmpeg issue or a PyAV issue, but if you
have a file size this is >=2**31, you'll get the wrong value.. either
you'll get a size too small, or a negative number...

For example:

os.stat(fname)
posix.stat_result(st_mode=33060, st_ino=38303595, st_dev=234881028L, st_nlink=1, st_uid=502, st_gid=20, st_size=8163995316, st_atime=1412451616, st_mtime=1411500234, st_ctime=1411500234)
f = av.open(fname)
print f.size
-425939276
print f.size + 2**32 + 2**32
8163995316

so, this was built on MacOSX 10.7.5...

Mutable formats, or set on first encode?

In order to satisfy #64, I'd like to iron out some of the API with regard to audio/video format objects, as they are in an inconsistent and incomplete state.

Currently, there is are AudioFormat and VideoFormat classes (along with AudioLayout, which is a little different) that encapsulate several aspects of their respective streams. For video, that includes width, height, and pixel format. For audio, that is the number of channels and sample format.

For video, you set width, height, and pix_fmt on the VideoStream, which rebuilds the attached VideoFormat. For audio, there are not yet any such controls.

I see 3 options:

  1. We could make the various format objects mutable, so that you would stream.format.width = 1920 and that would propagate, but that may introduce odd behaviour.
  2. We have setable attributes on the stream, which rebuild the immutable format descriptors (this is what the video classes currently do).
  3. The stream adopts the format from the first frame that is encoded, so you don't even bother setting them on the stream itself, and just jam frames into it. (This would change behaviour of resampling video/audio frames that do not match, but a freeze_format method could lock that down before the first frame.)

Does anyone have any strong feelings about these options?

Deprecated struct members in unstable Libav builds (e.g. AVStream.r_frame_rate)

Greetings,

I've attempted to install PyAV with pip as well as compile it from source and I get the following errors.

building 'av.video.stream' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_AVFORMAT_CLOSE_INPUT=1 -Iinclude -I/usr/include/python2.7 -Ibuild/temp.linux-x86_64-2.7/include -c /home/nomad/build/av/src/av/video/stream.c -o build/temp.linux-x86_64-2.7/home/nomad/build/av/src/av/video/stream.o

/home/nomad/build/av/src/av/video/stream.c: In function ‘__pyx_pf_2av_5video_6stream_11VideoStream_12guessed_rate___get__’:

/home/nomad/build/av/src/av/video/stream.c:2549:90: error: ‘struct AVStream’ has no member named ‘r_frame_rate’

error: command 'gcc' failed with exit status 1
Downloading/unpacking av
  Running setup.py egg_info for package av
    Could not find ['avcodec', 'avutil', 'avcodec'] with ctypes.util.find_library
    Could not find ['avformat'] with ctypes.util.find_library
    Could not find ['avutil'] with ctypes.util.find_library

I'm assuming I'm missing a dependency or something, but to the best of my knowledge, I have all of the correct development packages for the dependencies listed in the wiki. Any and all help is appreciated.

Exception at shutdown

I spent a quite a few hours hitting my head on this one.

For some reason, calling lib.avformat_close_input (in av.context.ContextProxy.__dealloc__) sets up conditions such that a weakrefset somehow related to the UserDict that is os.environ calls a None object during shutdown:

Exception TypeError: "'NoneType' object is not callable" in <function _remove at 0x102ac6410> ignored

However, calling os.environ.__iter__() (and not os.environ.data.__iter__() "fixes" this. Even stranger, os.environ.__iter__() simply calls os.environ.data.__iter__().

I have established that much via debugging CPython with gdb and as much introspection as I can muster from there, and via this fix

I don't even...


If you feel like debugging this some more:

  1. manually compile CPython with no optimization (I edited the Makefile to remove the -O2 flags... shaddup);
  2. install it and Cython;
  3. gdb python and break PyErr_WriteUnraisable;
  4. run -m examples.encode path/to/movie;

The stack looks roughly like:

#0  PyErr_WriteUnraisable (obj=0x1004c6488) at errors.c:649
#1  0x00000001000bb879 in handle_callback (ref=0x100456db8, callback=0x1004c6488) at weakrefobject.c:895
#2  0x00000001000bbc6d in PyObject_ClearWeakRefs (object=0x10046ace8) at weakrefobject.c:976
#3  0x0000000100023707 in class_dealloc (op=0x10046ace8) at classobject.c:193
#4  0x000000010009d34b in tupledealloc (op=0x100467a90) at tupleobject.c:222
#5  0x0000000100023748 in class_dealloc (op=0x10046abb0) at classobject.c:194
#6  0x0000000100025317 in instance_dealloc (inst=0x10046d2d8) at classobject.c:680
#7  0x000000010006c323 in insertdict_by_entry (mp=0x100321910, key=0x1004421e0, hash=-5347984860299468300, ep=0x10084b6e0, value=0x1001fb470) at dictobject.c:519
#8  0x000000010006c530 in insertdict (mp=0x100321910, key=0x1004421e0, hash=-5347984860299468300, value=0x1001fb470) at dictobject.c:556
#9  0x000000010006ce49 in dict_set_item_by_hash_or_entry (op=0x100321910, key=0x1004421e0, hash=-5347984860299468300, ep=0x0, value=0x1001fb470) at dictobject.c:765
#10 0x000000010006d03f in PyDict_SetItem (op=0x100321910, key=0x1004421e0, value=0x1001fb470) at dictobject.c:818
#11 0x0000000100077056 in _PyModule_Clear (m=0x10044f168) at moduleobject.c:138
#12 0x000000010013bfdc in PyImport_Cleanup () at import.c:526
#13 0x00000001001510a9 in Py_Finalize () at pythonrun.c:454
#14 0x000000010017481f in Py_Main (argc=4, argv=0x7fff5fbff650) at main.c:665
#15 0x00000001000012d0 in main (argc=4, argv=0x7fff5fbff650) at python.c:23

It seems to be dealing with weakrefs on the _Environ that is os.environ.

We need tests!

We can use testsrc to generate footage. filter guide

 ffmpeg -y -f lavfi -i testsrc -frames:v 48 test_video.avi
 ffmpeg -y -f lavfi -i aevalsrc="sin(420*2*PI*t):cos(430*2*PI*t)::s=4800:d=2" test_audio.wav

Just not sure of what the syntax is for avconv. Libav doesn't seem to have -f lavfi or aevalsrc

avconv -filter_complex 'testsrc' -t 5 test_video.avi

Memory Leaks

Greetings,

I've been noticing lots of memory leaks with PyAV when opening videos. I've spent the good part of a day making sure I had none in my code before posting an issue, but I have a program that processes lots of video continuously using PyAV and I have noticed an increase in memory usage over the course of an hour (10GB). I tested using the pyio branch using the default method for opening files along with the method for opening from a buffer and both resulted in the same issue.

Here are the results from one of my tests. I'm using the resource module to return memory usage before and after two separate instances of video parsing.

----
Memory usage before: 12776 (kb)
No handlers could be found for logger "libav.h264"
Memory usage after: 69584 (kb)
----

----
Memory usage before: 69584 (kb)
Memory usage after: 100072 (kb)
----
 #!/usr/bin/python

import av
import resource

print "\n----"
print 'Memory usage before: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
container = av.open('video.h264', 'r', 'h264')
for packet in container.demux():
        for frame in packet.decode():
                frame.to_image().save('/home/nomad/jpgs/frame-%02d.jpg' % frame.index)
print 'Memory usage after: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
print "----\n"

print "\n----"
print 'Memory usage before: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

container2 = av.open('video.h264', 'r', 'h264')
for packet2 in container2.demux():
        for frame2 in packet2.decode():
                frame2.to_image().save('/home/nomad/jpgs/frame-%02d.jpg' % frame.index)

print 'Memory usage after: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
print "----\n"
nomad@wilson ~ $ ll -h video.h264 
-rw-r--r-- 1 nomad nomad 22M Oct 14 16:26 video.h264

Installing on Windows

Hi,
I would like to use PyAV under Python2.7 on windows.
Can you explain me how I can install the plugin?
(I would like a more recent version than the 0.1.0)
Thank you.
Nico

r_frame_rate error

Hi, I'm not sure if this is related to Issue #52. This is on Debian unstable, latest libav*

src/av/codec.c: In function ‘__pyx_pf_2av_5codec_5Codec_13audio_formats___get__’:
src/av/codec.c:1455:37: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
   __pyx_t_1 = __Pyx_PyInt_From_int(((int)__pyx_v_self->ptr->sample_fmts)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                                     ^
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -O0 -g build/temp.linux-x86_64-2.7/src/av/codec.o -lavcodec -lavdevice -lavformat -lavresample -lavutil -lswscale -o build/lib.linux-x86_64-2.7/av/codec.so
building 'av._core' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -O0 -fPIC -g -Iinclude -I/usr/include/python2.7 -Ibuild/temp.linux-x86_64-2.7/include -c src/av/_core.c -o build/temp.linux-x86_64-2.7/src/av/_core.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -O0 -g build/temp.linux-x86_64-2.7/src/av/_core.o -lavcodec -lavdevice -lavformat -lavresample -lavutil -lswscale -o build/lib.linux-x86_64-2.7/av/_core.so
building 'av.container' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -O0 -fPIC -g -Iinclude -I/usr/include/python2.7 -Ibuild/temp.linux-x86_64-2.7/include -c src/av/container.c -o build/temp.linux-x86_64-2.7/src/av/container.o
src/av/container.c: In function ‘__pyx_pf_2av_9container_14InputContainer___cinit__’:
src/av/container.c:2554:15: warning: assignment from incompatible pointer type
     __pyx_t_8 = __pyx_cur_scope->__pyx_v_self->__pyx_base.format;
               ^
src/av/container.c: In function ‘__pyx_pf_2av_9container_15OutputContainer___cinit__’:
src/av/container.c:4036:15: warning: assignment from incompatible pointer type
     __pyx_t_6 = __pyx_v_self->__pyx_base.format;
               ^
src/av/container.c: In function ‘__pyx_f_2av_9container_15OutputContainer_add_stream’:
src/av/container.c:4325:32: warning: assignment discards ‘const’ qualifier from pointer target type
       __pyx_v_codec_descriptor = avcodec_descriptor_get_by_name(__pyx_t_8);
                                ^
src/av/container.c:4672:43: error: ‘struct AVStream’ has no member named ‘r_frame_rate’
     __pyx_t_11 = __pyx_v_template->_stream->r_frame_rate.num;
                                           ^
src/av/container.c:4673:19: error: ‘struct AVStream’ has no member named ‘r_frame_rate’
     __pyx_v_stream->r_frame_rate.num = __pyx_t_11;
                   ^
src/av/container.c:4682:43: error: ‘struct AVStream’ has no member named ‘r_frame_rate’
     __pyx_t_11 = __pyx_v_template->_stream->r_frame_rate.den;
                                           ^
src/av/container.c:4683:19: error: ‘struct AVStream’ has no member named ‘r_frame_rate’
     __pyx_v_stream->r_frame_rate.den = __pyx_t_11;
                   ^
src/av/container.c:4782:5: warning: ‘pts’ is deprecated (declared at /usr/include/libavformat/avformat.h:719) [-Wdeprecated-declarations]
     __pyx_t_15 = __pyx_v_template->_stream->pts;
     ^
src/av/container.c:4783:5: warning: ‘pts’ is deprecated (declared at /usr/include/libavformat/avformat.h:719) [-Wdeprecated-declarations]
     __pyx_v_stream->pts = __pyx_t_15;
     ^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Makefile:12: recipe for target 'build' failed
make: *** [build] Error 1

Container is not instanceable with unhelpful error

edit: restored by @mikeboers

Python 2.7.9 (default, Dec 19 2014, 18:50:11) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import av
av.container.Container()
Traceback (most recent call last):
File "", line 1, in 
File "av/container.pyx", line 63, in av.container.Container.cinit (src/av/container.c:1906)
def cinit(self, sentinel, name, format_name, options):
TypeError: cinit() takes exactly 4 positional arguments (0 given)

Repackaging without transcoding

I received this via email today.


I'm working on a project and i'm getting to know your PyAV library. I'm really liking it. What i would like to do is a simple video stream copy from one mkv w/ h264 video to a new mkv w/ the same stream without transcoding. I'v tried pulling packets out of the input file and just muxing them into the new file and this works for audio but not video. I've pasted my code below if there is something obvious i'm missing. Any help would be greatly appreciated.

output_video_stream = output_file.add_stream('h264', '23.976')
output_audio_stream = output_file.add_stream('ac3')

frame_count = 0

for packet in input_file.demux([s for s in (input_video_stream, input_audio_stream) if s]):
  if VERBOSE:
    print 'in', packet

  if packet.stream.type == 'video':
    if frame_count % 10 == 0:
      if frame_count:
        print
        print ('%03d:' % frame_count), sys.stdout.write('.'), sys.stdout.flush()
    frame_count += 1

  if VERBOSE:
    print 'OUT', packet
  output_file.mux(packet)

Mutability of first-class Frames

I have been making VideoFrames (and in the future AudioFrames) first-class objects that one can use by themselves.

E.g., if you were so inclined you could use them to perform simple resizing and reformatting of images.

Anyways, nearly everything about a Frame is immutable, except the data itself and a few key attributes (which I'm not actually sure of). The list that I envision includes:

  • the raw buffer;
  • pts;
  • if it is a key frame (although this may be handled elsewhere).

So, do we take the approach where a frame is a buffer, or that it is constant?

(I'm leaning towards a buffer, since that is what everyone does. I ask because in my head I have been somewhat treating it as immutable.)

Maintaining compatibility with LibAV and FFmpeg

I'm starting to hit issues where functions/macros/etc. are either missing or slightly different in FFmpeg vs LibAV. (See #1 for one, and av_frame_get_best_effort_timestamp for another). It seems like we will need a way to have slightly different code for the two libraries.

First, we will need a reliable way to detect which one we are using at compile-time.

Second, we will need a mechanism to emit different code. Possible options include:

  • a normalize_libraries.h which uses some macros to normalize the differences, and provide minimal functions to replace missing ones;
  • Cython macros (see example in first post);
  • ...?

av plane function 'from_ndarray' implementation

During decoding this actually accounts for about 15% of the process cpu time:

# TODO: Use the buffer protocol.
frame.planes[0].update_from_string(array.tostring())

The Python buffer object pointing to the start of the array’s data is simple array.data. I just don't know how hard implementing frame.planes[0].from_buffer would be in order to avoid the copy.

How to grab a screencap of frame 0 from a RTSP video stream

I have a simple script to grab a frame capture of the first frame from a RTSP stream:

import av
from PIL import Image
import sys

s = sys.argv[1]
video = av.open(s)

stream = next(s for s in video.streams if s.type == b'video')
for packet in video.demux(stream):
    for frame in packet.decode():
        img = frame.to_image()
        print type(img)
                break
        break

I am not getting anything but a type 'instance' . Is there a way I can grab the first frame screencap only, then terminate the loop, so the img can be processed outside the code?

Thanks.

Python 3

Things to consider:

  • Names of codecs, formats, layouts, etc. should be native strings, but Cython makes us jump through hoops to get them (str(c_str.decode())).
  • There is no PIL.

Perhaps some handwritten C to deal with conversions to native strings?

const char* str_to_cstr(PyObject *obj) # requires original to stick around?
PyObject* cstr_to_str(const char *str, int size=-1) -> bytes in 2 and str in 3

Missing symbols from libavdevice

From @simora on #49:

>>> from av import open
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "av/__init__.py", line 4, in <module>
    from ._core import time_base
ImportError: av/_core.so: undefined symbol: avdevice_register_all

Buffer protocol assumes single plane

This works fine for packed data (e.g. rgb24), but segfaults on planar data (e.g. yuv420p).

Need to decide if we want to export each plane as their own buffer, or somehow pack them.

Segfault trying to grab a single frame

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?

QuickTime does not like h.264 examples

When the encoding examples use "h264", QuickTime isn't able to play them.

A quick search on the web reveals that there is some trickyness hrere.

Do we need to expose AVProfile to set it to "baseline"?

Issues Encoding to OGG

I've been able to write Cython code that was able to take a PCM float32 data and encode it to WAV and MP3 file. Plays fine.Waveform looks exactly like the original in Audacity.

When I use the same code I wrote to try to encode to OGG (using libvorbis), the resulting OGG file is only like the first 10 seconds of the song of a 3 minute song. No errors.

My code is very similar to the encoding example.

Is there extra logic I need to add for OGG encoding?

OverflowError during packet.decode()

Any idea what's causing this? (Other file formats are working fine on my system.)

In [19]: container = av.open('test-2080_t0001.AVI')

In [20]: packets = container.demux()

In [21]: p = next(packets)

In [22]: p
Out[22]: <av.Packet of <av.VideoStream rawvideo, bgr24 660x492 at 0xaa58252c> at 0xaa5f880c>

In [23]: p.decode()
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-23-5f34859faf09> in <module>()
----> 1 p.decode()

/home/dallan/anaconda/lib/python2.7/site-packages/av/packet.so in av.packet.Packet.decode (/home/dallan/PyAV/src/av/packet.c:1204)()

/home/dallan/anaconda/lib/python2.7/site-packages/av/stream.so in av.stream.Stream.decode (/home/dallan/PyAV/src/av/stream.c:3488)()

/home/dallan/anaconda/lib/python2.7/site-packages/av/video/stream.so in av.video.stream.VideoStream._decode_one (/home/dallan/PyAV/src/av/video/stream.c:1738)()

/home/dallan/anaconda/lib/python2.7/site-packages/av/video/frame.so in av.video.frame.VideoFrame._init_properties (/home/dallan/PyAV/src/av/video/frame.c:1723)()

/home/dallan/anaconda/lib/python2.7/site-packages/av/frame.so in av.frame.Frame._init_planes (/home/dallan/PyAV/src/av/frame.c:1708)()

/home/dallan/anaconda/lib/python2.7/site-packages/av/video/plane.so in av.video.plane.VideoPlane.__cinit__ (/home/dallan/PyAV/src/av/video/plane.c:1347)()

OverflowError: can't convert negative value to size_t

setuptools and cythonize

I've been using a older version of pyav for a while, any reason distutils was changed to setuptools? I couldn't seem to build pyav on my mavericks system the latest master a9cdab7 without reverting setup.py back to distutils. on my system the cythonize function isn't working correctly on setuptools Extensions objects, (setuptools is replacing all the sources .pyx extensions with .c). All the cythonize examples seem to use distutils.

Installing on OSX 10.9

Hello, I'm trying to install this library on Mavricks. Using pip install av, I get the following error:


octopro:PyAV octotod$ pip install av
Downloading/unpacking av
Downloading av-0.1.0.tar.gz (601kB): 601kB downloaded
Running setup.py (path:/private/var/folders/vf/hvj8p44d0ln7tszd1jd4ynl00000gn/T/pip_build_octotod/av/setup.py) egg_info for package av
Traceback (most recent call last):
File "", line 17, in
File "/private/var/folders/vf/hvj8p44d0ln7tszd1jd4ynl00000gn/T/pip_build_octotod/av/setup.py", line 84, in
config = pkg_config(name)
File "/private/var/folders/vf/hvj8p44d0ln7tszd1jd4ynl00000gn/T/pip_build_octotod/av/setup.py", line 15, in pkg_config
proc = Popen(['pkg-config', '--cflags', '--libs', name], stdout=PIPE, stderr=PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in init
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/private/var/folders/vf/hvj8p44d0ln7tszd1jd4ynl00000gn/T/pip_build_octotod/av/setup.py", line 84, in

config = pkg_config(name)

File "/private/var/folders/vf/hvj8p44d0ln7tszd1jd4ynl00000gn/T/pip_build_octotod/av/setup.py", line 15, in pkg_config

proc = Popen(['pkg-config', '--cflags', '--libs', name], stdout=PIPE, stderr=PIPE)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in init

errread, errwrite)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child

raise child_exception

OSError: [Errno 2] No such file or directory

I tried building from source, and had to alter the line:

pip install cython pil

to:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install cython --allow-external pil

However, make gives a similar error to the pip method:


(venv)octopro:PyAV octotod$ make
CFLAGS=-O0 python setup.py build_ext --inplace --debug
Traceback (most recent call last):
File "setup.py", line 51, in
config = pkg_config(name)
File "setup.py", line 30, in pkg_config
proc = Popen(['pkg-config', '--cflags', '--libs', name], stdout=PIPE, stderr=PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in init
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

make: *** [build] Error 1

Installation on Arch Linux

I had Problems installing this on my Arch Linux Laptop.
Adding raw_config = raw_config.decode() and err = err.decode() in line 37 of setup.py fixed that.

Thanks for your work!

frame index of video frame

Since frame.pts is often only by coincidence equal to frame index in video stream (and will ultimately fail with non constant frame rates), I was hoping for frame.index to represent the frame index in the steam.

However, it appears that frame index == encoded frame count on frame creation. This mean that after a seek the index become -at least the way I understand it- false.

Any ideas on how to fix that?

Using PyAV with a video preloaded into a buffer.

Greetings,

Not an issue, but I'm curious if you might know an easy way to use PyAV with a buffer instead of directly from a file. I've looked through the wiki and through a lot of the source code, but I haven't found anything of use. Basically, I have a UDP video transport protocol that I pull in with Python where I sort the network frames and append them to a variable. Once they reach a certain number of network frames, I dump them to an ffmpeg pipe to get encoded. What I would really like to do is pass the variable to PyAV and have it do work on the video. I've read some things on the LibAV/ffmpeg mailing lists and I know that it's relatively simple with libav, but I'm sure its not easily ported to PyAV (at least not for me). I wondered if perhaps you had any ideas. Any and all help is appreciated.

I would also be willing to assist in implementing such a feature, but I'm not anywhere near experienced enough with Cython to do it on my own.

Humanize property names

Working towards to goal of making PyAV more self-descriptive, I think it would be desirable to humanize property names whenever possible.

This will require making video/audio/... specific Codec classes, and perhaps input/output specific Context classes, but that seems like a good idea anyways.

Examples:

  • Codec.pix_fmt -> VideoCodec.format
  • Codec.sample_fmt -> AudioCodec.format
  • VideoFrame.pix_fmt -> VideoFrame.format done

Thoughts?

building on Ubuntu 12.04

On 12.04LTS I cannot resolve all dependencies for installation with just apt-get. I always get an error complaining about audio_fifo.h not being present. I suspect that I was missing libswresample and it seems that libswresample is not available for 12.04.

I can build pyav by building ffmpeg and many of its dependencies from source as shared libs. Since this is actually quite involved I have modified an existing shell script. You can find my version here for referece: https://gist.github.com/mkassner/1caa1b45c19521c884d5

I find this to be a bit crazy and hope that there is a faster way of getting pyav working on 12.04 (on 14.04 APT can be used to resolve all dependencies)

Suggestions?

Installation on Ubuntu 12.04 LTS

Hi. I'm a developer over at PIMS. I would like to use this project and, potentially, contribute to it. But I haven't been able to get started.

I run python setup.py build (I have the current master branch) and I get:

Could not find avcodec with ctypes; looked in:
    libavcodec.so.53
    /usr/local/lib/libavcodec.so.53

Could not find avformat with ctypes; looked in:
    libavformat.so.53
    /usr/local/lib/libavformat.so.53

I'm running Ubuntu 12.04 LTS. If I adopt this for my lab (and maybe as a dependency of our PIMS package) I'll need it to run on the OSX and Windows machines of non-developers. A difficult install on Linux is a not a promising sign, but I think you have the right approach with the project, so I'd like to make it work if I can.

Our best guess is that it has bleeding-edge requirements. Could it potentially be more flexible and rely on LTS versions of libav*? I'm volunteering to help that, if you can provide some initial guidance.

Simplify muxing process

A few thoughts:

  • Context.decode() could demux and decode. Then for frame in ctx.decode(): pass works well.
  • Frame.encode() could be responsible for creating all of the resultant packets and return them in a list, instead of the user being responsible for calling it over and over.
  • Stream.mux() could encode and mux in one step.
  • Context.mux() could encode a Frame with the first matching Stream, then mux it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.