edit a video in python

73 views Asked by At

I'm trying edit a MP4 video using ffmpeg-python library but I get

TypeError: 'ffmpeg' has no attribute 'input'

Here is my code, directly copied from the official repository):

import ffmpeg
x=ffmpeg.input('xx.mp4')
x=ffmpeg.hflip(x)
x=ffmpeg.output(x,'yy.mp4')
ffmpeg.run(x)

I'm very confused about this error.
Can anyone help me to figure out??

error using ffmpeg-library

Thanks.

1

There are 1 answers

8
seb On

From a tiny bit of googling : you probably installed the wrong ffmeg python library.
You can use pip install ffmpeg-python to be sure to install the correct one.
you can also list the installed modules with pip list and manually inspect if there is indeed another module sharing the name ffmpeg.

You can also manually inspect the ffmpeg file to ensure it is the right one :

import ffmpeg
print(ffmpeg)

This output something like

<module 'ffmpeg' from 'some_path/__init__.py'>

You can then open the file some_path/_ffmpeg.py and check that it has the desired input attribute. As of ffmpeg-python version 0.2.0, the file begins like this :


from ._utils import basestring

from .nodes import (
    filter_operator,
    GlobalNode,
    InputNode,
    MergeOutputsNode,
    OutputNode,
    output_operator,
)


def input(filename, **kwargs):
    """Input file URL (ffmpeg ``-i`` option)

    Any supplied kwargs are passed to ffmpeg verbatim (e.g. ``t=20``,
    ``f='mp4'``, ``acodec='pcm'``, etc.).

    To tell ffmpeg to read from stdin, use ``pipe:`` as the filename.

    Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
    """
    kwargs['filename'] = filename
    fmt = kwargs.pop('f', None)
    if fmt:
        if 'format' in kwargs:
            raise ValueError("Can't specify both `format` and `f` kwargs")
        kwargs['format'] = fmt
    return InputNode(input.__name__, kwargs=kwargs).stream()

   .......