ffmpeg-python | Python bindings for FFmpeg - with complex filtering support | Video Utils library

 by   kkroening Python Version: 0.2.0 License: Apache-2.0

kandi X-RAY | ffmpeg-python Summary

kandi X-RAY | ffmpeg-python Summary

ffmpeg-python is a Python library typically used in Video, Video Utils applications. ffmpeg-python 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 ffmpeg-python' or download it from GitHub, PyPI.

There are tons of Python FFmpeg wrappers out there but they seem to lack complex filter support. ffmpeg-python works well for simple as well as complex signal graphs.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              ffmpeg-python has a medium active ecosystem.
              It has 8405 star(s) with 821 fork(s). There are 114 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 413 open issues and 225 have been closed. On average issues are closed in 209 days. There are 36 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of ffmpeg-python is 0.2.0

            kandi-Quality Quality

              ffmpeg-python has 0 bugs and 0 code smells.

            kandi-Security Security

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

            kandi-License License

              ffmpeg-python is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              ffmpeg-python 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.
              ffmpeg-python saves you 1885 person hours of effort in developing the same functionality from scratch.
              It has 4204 lines of code, 184 functions and 34 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed ffmpeg-python and discovered the below as its top functions. This is intended to give you an instant insight into ffmpeg-python implemented functionality, and help decide if they suit your requirements.
            • Render a graphviz graph
            • Sort a graph
            • Given an upstream node and a graph return all the outgoing edges
            • Get the color for a node
            • Split an audio file using ffmpeg
            • Create a directory
            • Apply a filter to a stream
            • Get the chunk times in a file
            • Run ffmpeg asynchronously
            • Wrapper for ffmpeg
            • Compile ffmpeg
            • Return the arguments for a given stream specification
            • Describe a audio file
            • Apply color channelmixer
            • Read a single frame as JPEG
            • Set a setpts expression
            • Auxiliary function that yields tqdm progress bar
            • Watch the progress of the progress bar
            • Generate a thumbnail
            • Apply zoomans to stream
            • Apply hue filter
            • Crop a stream
            • Create an input node
            • Run ffprobe on a file
            • Process a single frame
            • Concatenate streams together
            Get all kandi verified functions for this library.

            ffmpeg-python Key Features

            No Key Features are available at this moment for ffmpeg-python.

            ffmpeg-python Examples and Code Snippets

            ffmpeg-python: Python bindings for FFmpeg-Custom Filters
            Pythondot img1Lines of Code : 42dot img1License : Permissive (Apache-2.0)
            copy iconCopy
            stream = ffmpeg.input('dummy.mp4')
            stream = ffmpeg.filter(stream, 'fps', fps=25, round='up')
            stream = ffmpeg.output(stream, 'dummy2.mp4')
            ffmpeg.run(stream)
            
            (
                ffmpeg
                .input('dummy.mp4')
                .filter('fps', fps=25, round='up')
                .output('dum  
            Examples-Tensorflow Streaming
            Pythondot img2Lines of Code : 37dot img2License : Permissive (Apache-2.0)
            copy iconCopy
            process1 = (
                ffmpeg
                .input(in_filename)
                .output('pipe:', format='rawvideo', pix_fmt='rgb24', vframes=8)
                .run_async(pipe_stdout=True)
            )
            
            process2 = (
                ffmpeg
                .input('pipe:', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(w  
            copy iconCopy
            from ffmpeg import video
            
            # 输入视频
            input_file = "demo.mp4"
            
            # 输出视频
            out_file = "demo_out.mp4"
            
            # 图片列表
            img_data = [
                    {
                        "img": "demo1.png",
                        "x": "",
                        "y": "",
                        "str_time": "5",
                        "end_time": "  
            ffmpeg-python - tensorflow stream
            Pythondot img4Lines of Code : 196dot img4License : Non-SPDX (Apache License 2.0)
            copy iconCopy
            '''Example streaming ffmpeg numpy processing.
            
            Demonstrates using ffmpeg to decode video input, process the frames in
            python, and then encode video output using ffmpeg.
            
            This example uses two ffmpeg processes - one to decode the input video
            and one t  
            ffmpeg-python - show progress
            Pythondot img5Lines of Code : 92dot img5License : Non-SPDX (Apache License 2.0)
            copy iconCopy
            #!/usr/bin/env python
            from __future__ import unicode_literals, print_function
            from tqdm import tqdm
            import argparse
            import contextlib
            import ffmpeg
            import gevent
            import gevent.monkey; gevent.monkey.patch_all(thread=False)
            import os
            import shutil
            impo  
            ffmpeg-python - split silence
            Pythondot img6Lines of Code : 75dot img6License : Non-SPDX (Apache License 2.0)
            copy iconCopy
            #!/usr/bin/env python
            from __future__ import unicode_literals
            
            import argparse
            import errno
            import ffmpeg
            import logging
            import os
            import re
            import subprocess
            import sys
            
            
            logging.basicConfig(level=logging.INFO, format='%(message)s')
            logger = logging  
            Problem processing video using opencv in android/python
            Pythondot img7Lines of Code : 3dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ffmpeg -i pvp2.mp4 -vsync cfr pvp2cfr2.mp4
            ffmpeg -i pvp2cfr2.mp4 -filter:v fps=30 pvp2cfr30.mp4
            
            copy iconCopy
            ... 
            
                Metadata:
                  handler_name    : VideoHandler
                  vendor_id       : [0][0][0][0]
              Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
                Metadata:
                  handler_name    : So
            set equal duration to images with ffmpeg python
            Pythondot img9Lines of Code : 18dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ffmpeg \
              -y \
              -i './SARS/SARS.mp3' \
              -pattern_type glob -framerate 0.1 -i './SARS/*.jpg' \
              -vf scale=size=hd1080:force_original_aspect_ratio=increase \
              './SARS/output.mp4'
            
            pip install ffmpegio-core
            
            Controlling buffer size for webcam video capture to file using ffmpeg
            Pythondot img10Lines of Code : 29dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
             process = ffmpeg.run_async(stream, cmd=APPLICATION, pipe_stdin=True, overwrite_output=True, quiet=True)
            
             process.stdin.write('q'.encode("GBK"))
             process.communicate()
            
             process.wait()
            

            Community Discussions

            QUESTION

            Problem processing video using opencv in android/python
            Asked 2022-Apr-08 at 19:33

            I am trying to open a video and using python get a frame array with frame by frame for post-processing.

            I am in android termux, I have ffmpeg and opencv2 installed with python3.

            When I try to open the video with

            ...

            ANSWER

            Answered 2022-Apr-08 at 18:37

            I ended up using ffmpeg instead of opencv. Turns out opencv can't handle vfr mp4 on android and it only supports a very limited set of .avi.

            I was able to use a ffmpeg filter and re-encode the video to a cfr.

            I used a 2 pass transformation to make it a constant 30fps video.

            Source https://stackoverflow.com/questions/71778077

            QUESTION

            Killing a Python process from Node doesn't kill Python's child process (child process being ffmpeg.exe)
            Asked 2022-Apr-03 at 08:53

            I am developing an Electron application. In this application, I am spawning a Python process with a file's path as an argument, and the file itself is then passed to ffmpeg (through the ffmpeg-python module) and then goes through some Tensorflow functions.

            I am trying to handle the case in which the user closes the Electron app while the whole background process is going. From my tests though, it seems like ffmpeg's process stays up no matter what. I'm on Windows and I'm looking at the task manager and I'm not sure what's going on: when closing the Electron app's window, sometimes ffmpeg.exe will be a single process, some other times it will stay in an Electron processes group.

            I have noticed that if I kill Electron's process through closing the window, the python process will also close once ffmpeg has done its work, so I guess this is half-working. The problem is, ffmpeg is doing intensive stuff and if the user needs to close the window, then the ffmpeg process also NEEDS to be killed. But I can't achieve that in any way.

            I have tried a couple things, so I'll paste some code:

            main.js

            ...

            ANSWER

            Answered 2022-Apr-03 at 08:49

            Alright, I was finally able to fix this! Since ffmpeg-python is just a collection of bindings for good old ffmpeg, the executable itself is still at the core of the module. This also means that when ffmpeg is running, a screen similar to this:

            Source https://stackoverflow.com/questions/71715821

            QUESTION

            How to drawtext with a color gradient fill with ffmpeg (ffmpeg-python)? and then mix with music?
            Asked 2022-Feb-19 at 14:56

            I'd like to achieve this result (to place a text with gradint or whatever picture-fill on top of a video): So I decided to make a picture of gradient: and then with chroma-key technique transform it to this (with transparent background): and then place it over the video.

            Here is the code with ffmpeg-python:

            ...

            ANSWER

            Answered 2022-Feb-12 at 13:46

            We may draw the text on black background, and use alphamerge for creating transparent background with colored gradient text.
            Then we can overlay the gradient (with the transparent background) on the input video.

            I don't know if my suggested solution is the most elegant, but it is not lower the brightness of the gradient picture.

            The suggested solution applies the following stages:

            • Define synthetic black video source (1 frame).
            • Draw white text on the black video frame.
            • Add the "white text on black background" as alpha channel of the gradient image.
              Only the white text is opaque, and the black background is fully transparent.
            • Overlay the above frame over the video.

            Start by creating synthetic yellow video file (with sine audio) for testing:

            Source https://stackoverflow.com/questions/71051645

            QUESTION

            Apply custom function on each frame of a video with variable framerate
            Asked 2022-Feb-18 at 11:30

            I'm trying to apply a custom python function on every frame of a video, and create the video with modified frames as output. My input video is a mkv file, with variable framerate, and I'd like to get the same thing as output, so one frame in the input matches one in the output at the exact same time.

            I tried to use this example of ffmpeg-python. However, it seems that the timestamp info are lost in the pipes. The output video has 689 frames when the input only has 300 (the durations also aren't a match, with 27s vs 11s for the input).

            I also tried to first process each frame in my video and save the transformed version as PNGs. Then I "masked" the input video with the processed frames. This seems to be better because the output video has the same 11s duration than the input, but the frame count doesn't match (313 vs 300).

            Code for the python-ffmpeg solution:

            ...

            ANSWER

            Answered 2022-Feb-18 at 11:30

            I'll answer my own question, as I've been able to solve the issue with the help of kesh in the comments.

            There are basically two things:

            • vsync passthrough is required for the input video, to keep the number of frames
            • another external tool (MKVToolNix) has to be used twice to extract timestamps from the initial video and apply them to the output

            Below is the relevant code to perform the whole operation using python and subprocess. You can use the following line on both input and output video to check that the timestamps are indeed the same for each frame: ffprobe -show_entries packet=pts_time,duration_time,stream_index video.mkv

            Source https://stackoverflow.com/questions/71159675

            QUESTION

            How to use multiple map values in ffmpeg-python?
            Asked 2022-Jan-04 at 07:46

            How can I use multiple map values for different resolutions in ffmpeg-python?

            ...

            ANSWER

            Answered 2021-Sep-23 at 11:17

            you can give multiple map values in ffmpeg-python like:

            Source https://stackoverflow.com/questions/69218400

            QUESTION

            Apache mpm event shared memory error - ffmpeg-python Error while opening encoder for output stream #0:1 when accessed by multiple instances
            Asked 2021-Dec-09 at 12:42
            EDIT:

            I kinda figured out, the problem needs to deal with apache mpm event... When I send my request on the first client, my script is getting executed linear. When I send my request from the second client, he is literally starting at that point in the code where the last request currently is. So that might be a problem with shared memory between those threads, but I'm not an apache professional, maybe somebody has an idea?
            I used apache mpm prefork before, so every request is getting his own process and own memory etc., but there was a problem reading jpg files with that one and it worked after I changed apache to mpm event, see the following: https://github.com/python-pillow/Pillow/issues/5834#issue-comment-box

            Inside my VM (running same apache version with mpm event) everything is working fine.

            I've got a python script with flask running via wsgi on an apache2 webserver. Inside of that script I got following lines (458-461):

            ...

            ANSWER

            Answered 2021-Dec-04 at 15:39

            Okay, for the love of God Im done... needed 4 days for that **** to find out, I had an apache mod activated (fcgid) which literally assign every single line of ur code to a single thread... so I deactivated that one and now its working without any issues...

            So in short - what I did:

            Source https://stackoverflow.com/questions/70221356

            QUESTION

            ffmpeg-python take input from x11grab
            Asked 2021-Nov-28 at 20:07

            I am using FFmpeg-python bindings for using FFmpeg. I have to take input from x11grab, for which I already have an equivalent command in shell i.e,

            ffmpeg -nostdin -hide_banner -nostats -loglevel panic -video_size 1920x1080 -r 60 -framerate 30 -f x11grab -i :1 -f alsa -ac 2 -i pulse -preset fast -pix_fmt yuv420p file.mkv &

            I have gone through docs of FFmpeg-Python to create an equivalent command, however, I could not find any example of x11grab in the documentation.

            I wanted to use a binding to make the code more readable, the command works with subprocess.call() / os.system()

            ...

            ANSWER

            Answered 2021-Nov-28 at 20:07

            The syntax resembles the following code sample:

            Source https://stackoverflow.com/questions/70145683

            QUESTION

            How to convert the sample rate with ffmpeg-python
            Asked 2021-Nov-26 at 15:57

            I'm using ffmpeg-python. I would like to change the sample rate of the audio file.

            In ffmpeg-, it seems that you can change the sample rate as follows.

            ...

            ANSWER

            Answered 2021-Nov-26 at 15:57

            I soleved.

            I can set **kwargs like this.

            Source https://stackoverflow.com/questions/70126068

            QUESTION

            ffmpeg reverts to default subtitle font
            Asked 2021-Oct-25 at 21:09

            I'm using ffmpeg-python to burn an SRT into a video file. My code looks something like this:

            ...

            ANSWER

            Answered 2021-Oct-25 at 21:09

            It looks like fonts_dir should include the font file name.

            Instead of fonts_dir = "fonts-main/apache", try:

            Source https://stackoverflow.com/questions/69699369

            QUESTION

            How can I get service_name and program list by ffmpeg-python
            Asked 2021-Oct-09 at 21:17

            I have a ".ts" file. It is the baseband frame of a DVBS signal which have been recorded. It has some Programs and streams. I use FFmpeg to reconstruct the streams. When I use FFmpeg, this context is shown which contains service_name. How I can export a list of Programs (Not streams) and service_names? ffmpeg.exe -i '.\log_dvbs.ts'

            ...

            ANSWER

            Answered 2021-Oct-08 at 16:21

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

            Vulnerabilities

            No vulnerabilities reported

            Install ffmpeg-python

            Flip a video horizontally:.
            The latest version of ffmpeg-python can be acquired via a typical pip install:.
            Convert video to numpy array
            Generate thumbnail for video
            Read raw PCM audio via pipe
            JupyterLab/Notebook stream editor
            Tensorflow/DeepDream streaming

            Support

            Make sure you ran pip install ffmpeg-python and not pip install ffmpeg or pip install python-ffmpeg. Some ffmpeg filters drop audio streams, and care must be taken to preserve the audio in the final output. The .audio and .video operators can be used to reference the audio/video portions of a stream so that they can be processed separately and then re-combined later in the pipeline. This dilemma is intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the way while users may refer to the official ffmpeg documentation as to why certain filters drop audio. As usual, take a look at the examples (Audio/video pipeline in particular). You can run stream.get_args() before stream.run() to retrieve the command line arguments that will be passed to ffmpeg. You can also run stream.compile() that also includes the ffmpeg executable as the first argument. Take a look at each of the links in the Additional Resources section at the end of this README. If you look everywhere and can't find what you're looking for and have a question that may be relevant to other users, you may open an issue asking how to do it, while providing a thorough explanation of what you're trying to do and what you've tried so far. Issues not directly related to ffmpeg-python or issues asking others to write your code for you or how to do the work of solving a complex signal processing problem for you that's not relevant to other users will be closed. That said, we hope to continue improving our documentation and provide a community of support for people using ffmpeg-python to do cool and exciting things.
            Find more information at:

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

            Find more libraries
            Install
          • PyPI

            pip install ffmpeg-python

          • CLONE
          • HTTPS

            https://github.com/kkroening/ffmpeg-python.git

          • CLI

            gh repo clone kkroening/ffmpeg-python

          • sshUrl

            git@github.com:kkroening/ffmpeg-python.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link