PyAV | Pythonic bindings for FFmpeg 's libraries | Video Utils library

 by   PyAV-Org Python Version: Current License: BSD-3-Clause

kandi X-RAY | PyAV Summary

kandi X-RAY | PyAV Summary

PyAV is a Python library typically used in Video, Video Utils applications. PyAV has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install PyAV' or download it from GitHub, PyPI.
[GitHub Test Status][github-tests-badge]][github-tests] \ [Gitter Chat][gitter-badge]][gitter] [Documentation][docs-badge]][docs] \ [GitHub][github-badge]][github] [Python Package Index][pypi-badge]][pypi] [Conda Forge][conda-badge]][conda]. PyAV is a Pythonic binding for the [FFmpeg][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.

            kandi-support Support

              PyAV has a medium active ecosystem.
              It has 1253 star(s) with 236 fork(s). There are 60 watchers for this library.
              It had no major release in the last 6 months.
              There are 132 open issues and 417 have been closed. On average issues are closed in 154 days. There are 33 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of PyAV is current.

            kandi-Quality Quality

              PyAV has 0 bugs and 0 code smells.

            kandi-Security Security

              PyAV has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              PyAV code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              PyAV is licensed under the BSD-3-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              PyAV releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              It has 5664 lines of code, 393 functions and 80 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed PyAV and discovered the below as its top functions. This is intended to give you an instant insight into PyAV implemented functionality, and help decide if they suit your requirements.
            • Set the file
            • Get the number of frames in the stream
            • Return the FPS rate for a given stream
            • Get a frame from the stream
            • Yield frames from the stream
            • Main entrypoint
            • Load an entrypoint
            • Try to get configuration from pkg - config
            • Parse cflags
            • Visit CVarDef node
            • Record an event
            • Return the number of frames in a stream
            • Download a fate
            • Iterate over frames in a video
            • Download the curated dataset
            • Overrides drop event
            • Print data for a frame
            • Print the frame to stdout
            • Setup the extension
            • Overrides key press event
            • Requests a time for a given frame
            • Returns the name of the platform
            • Request a frame ready to be displayed
            • Get an audio frame
            • Get configuration from the given directory
            • Extracts XML files
            Get all kandi verified functions for this library.

            PyAV Key Features

            Pythonic bindings for FFmpeg's libraries.

            PyAV Examples and Code Snippets

            NVENC H.264 Video Reader,Example usage
            Pythondot img1Lines of Code : 17dot img1no licencesLicense : No License
            copy iconCopy
            from GPUVideoReader import GPUVideoReader
            import cv2
            cv2.namedWindow('FRAME', cv2.WINDOW_NORMAL)
            reader = GPUVideoReader("h264videofileorrtspstream")
            ret = True
            while ret:
                ret, frame =
                if not ret:
            NVENC H.264 Video Reader,Run
            Pythondot img2Lines of Code : 9dot img2no licencesLicense : No License
            copy iconCopy
            # Allow connections to x server
            xhost +
            # Open a bash in container
            docker run -it --rm -v $(pwd):/app/home -e DISPLAY=$DISPLAY -e QT_X11_NO_MITSHM=1 \
                -v /tmp/.X11-unix:/tmp/.X11-unix pyav-build /bin/bash
            # In container at this point
            python exa  
            SlowFast Feature Extractor,Install requirements
            Pythondot img3Lines of Code : 8dot img3License : Permissive (MIT)
            copy iconCopy
            conda create -n "slowfast" python=3.7
            pip install 'git+'
            pip install simplejson av psutil opencv-python tensorboard moviepy cython
            python -m pip install 'git+  
            gluon-cv - decord loader
            Pythondot img4Lines of Code : 38dot img4License : Non-SPDX (Apache License 2.0)
            copy iconCopy
            """10. Introducing Decord: an efficient video reader
            Training deep neural networks on videos is very time consuming. For example, training a state-of-the-art SlowFast network
            on Kinetics400 datase  
            Regex match braces/brackets/parentheses
            Pythondot img5Lines of Code : 5dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import re
            pattern = r"\[([^\[\]()]+?)\]|\(([^\[\]()]+?)\)|\{([^\[\]()]+?)\}"
            temp = [(m.start(0), m.end(0)) for m in re.finditer(pattern, ' {kromosom} består av en DNA-molekyl och {protein}. En DNA-molek')]
            print(temp) #[(1, 11), (41, 50)]
            PyAV inconsistency when parsing packets from h264 frames
            Pythondot img6Lines of Code : 49dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                while (ret >= 0) {
                    ret = avcodec_receive_frame(dec_ctx, frame);
                    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                while (ret >= 0) {
                    ret = avcodec_receive_f
            Make a new dataset from from average of subsets of another data set with pandas
            Pythondot img7Lines of Code : 8dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # Modify the period column to an actual datetime
            df['period'] = pd.to_datetime(df.period.str.replace('M','',regex=False) + '01', 
            # Convert the price to a float
            df['price'] = df.price.str.repla
            Make a new dataset from from average of subsets of another data set with pandas
            Pythondot img8Lines of Code : 25dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            df = pd.read_excel('BensinPris.xlsx')
            df_avg = (
                df.groupby(df['ÅrMåned'].str[:4].astype(int))['Priser (kr per liter)'].mean()
                  .round(2).rename_axis('Year').rename('Average bensin price').reset_index()
            # Output
            Slow dnf to cnf in pycosat
            Pythondot img9Lines of Code : 278dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # Uses pseudo-namespacing to avoid collisions.
            _EXT_SUFFIX = "___"
            _NEXT_EXT_INDEX = 0
            def is_ext_var(element) -> bool:
                return element.endswith(_EXT_SUFFIX)
            def ext_var() -> str:
                global _NEXT_EXT_INDEX
                ext_index = _NE
            Capture first image from h.264 video streaming using websocket - Python
            Pythondot img10Lines of Code : 26dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pip install av
            import av
            # Feed in your raw bytes from socket
            def decode(raw_bytes: bytes):
                code_ctx = av.CodecContext.create("h264", "r")
                packets = code_ctx.parse(raw_bytes)
                for i, packet in enumerate

            Community Discussions


            PyAV inconsistency when parsing packets from h264 frames
            Asked 2022-Apr-03 at 18:05

            When producing H.264 frames and decoding them using pyAV, packets are parsed from frames only when invoking the parse methods twice.

            Consider the following test H.264 input, created using:

            ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 -f image2 -vcodec libx264 -bsf h264_mp4toannexb -force_key_frames source -x264-params keyint=1:scenecut=0 "frame-%4d.h264"

            Now, using pyAV to parse the first frame:



            Answered 2022-Apr-03 at 18:05

            This is an expected PyAV behavior. Not only, it is an expected behavior of the underlying libav. One packet does not guarantee a frame, and multiple packets may be needed before producing a frame. This is apparent in FFmpeg's video decoder example:



            ffprobe - shuffled frame metadata
            Asked 2021-Dec-22 at 04:41

            I'm using mkvmerge to combine a mp4 CFR video with a text file containing VFR timestamps. The command used was



            Answered 2021-Dec-22 at 04:41

            If the video stream has B-frames then future P-frames which act as reference for B-frames are encoded first and stored in that order. They are reordered after decoding.

            For ffprobe, the entries in packet are arranged in decode or storage order. In frames, they are decoded and arranged in presentation order.



            pyav / Libav / ffmpeg disable B frames
            Asked 2021-May-20 at 04:04

            I am using pyav (python wrapper for libav) to ingest an H264 video stream. Is there an option to disable B-frames? I think the same question would apply to libav and ffmpeg.



            Answered 2021-May-20 at 04:04

            The skip_frame option of the codeccontext should be set with value bidir or constant AVDISCARD_BIDIR (if assigning directly) to skip bidirectional frames.



            PyAv specify used codec
            Asked 2020-Sep-07 at 07:20

            When PyAv is used to open the alsa audio device. How I can specify used codec and not the ffmpeg default one because that is wrong. By default it will use pcm_s16le and I need to use pcm_s32le. I can record from my device with following ffmpeg command:



            Answered 2020-Sep-07 at 07:20

            I'll answer my own question because I figured it out. I read ffmpeg source code and saw that when using alsa audio device and codec is not specified ffmpeg will default to use signed 16-bit pcm samples. Code here. By further exploring the source code the codec value comes from AVFormatContext::audio_codec_id struct field.

            Now figuring out that PyAV using Cython to use FFmpeg and by reading PyAV source code of Container class I noticed it holds AVFormatContext in it's self.ptr variable. Then reading InputContainer source code and especially before calling avformat_open_input function to open the alsa device. Specifying the used audio codec is not supported by PyAV.

            I forked the library and ended quickly hacking the solution for me. Now the question is would it be possible to add this feature to PyAV to force the codec used for the audio? In this case when the device is using pcm samples and relying ffmpeg to use choose the default one it will always use 16-bit samples and in my case I needed to use 32-bit samples.

            Hopefully this helps someone and save them the trouble I went through :) I also posted this same answer for PyAV issue here.



            Heroku fails to install av (pyav)
            Asked 2020-Aug-26 at 09:08

            I have been trying to set up my Python web app that uses opencv, tensorflow and av modules but keeps failing. I have tried using the Aptfile to install several Ubuntu libraries (libsm6, libxrender1, etc.) and the install still fails.

            After failing the install, the heroku server resolves to building the av module from source which fails as well, with gcc failing here:



            Answered 2020-Aug-26 at 09:08

            Turns out Heroku works better using requirements.txt than Pipfile. After changing the install file, the deployment process went fine.



            PyAV not installed error but it's installed (GoogleColab)
            Asked 2020-May-09 at 12:00

            I am trying to import the ucf101 dataset using



            Answered 2020-May-09 at 12:00

            After you install av with


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install PyAV

            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][pypi] for Linux, Mac and Windows linked against a modern FFmpeg. You can install these wheels by running:.
            Another way of installing PyAV is via [conda-forge][conda-forge]:. See the [Conda quick install][conda-install] docs to get started with (mini)Conda.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone PyAV-Org/PyAV

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link