ffmpeg -hide_banner -loglevel error

This is alluded to in a comment below the current answer.

The option -hide_banner was introduced in late 2013 -- https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2013-December/152349.html )

-loglevel warning leads to more output than the error level (but less than the default info level) as it shows all warning messages.

-loglevel panic is the least verbose output (omitting even error messages) but is undocumented.

The official -loglevel documentation can be found in the ffmpeg Documentation under Generic options, subsection -loglevel [flags+]loglevel | -v [flags+]loglevel.

Answer from Hugues on Stack Exchange
🌐
GitHub
github.com › kkroening › ffmpeg-python › issues › 30
Add a way to pass arbitrary arguments to ffmpeg.run() · Issue #30 · kkroening/ffmpeg-python
September 20, 2017 - Great work! I'd like to pass -loglevel quiet to ffmpeg.run. I've tried this but it fails: >>> stream = ffmpeg.nodes.GlobalNode(stream, 'loglevel', 'quiet') >>> ffmpeg.run(stream) AssertionError: Unsupported global node: loglevel(quiet) I...
Author   elelayan
Discussions

How do I enable FFMPEG logging and where can I find the FFMPEG log file? - Stack Overflow
I want to be able to log FFMPEG processes because I am trying to work out how long a minute of video takes to convert to help with capacity planning of my video encoding server. How do I enable log... More on stackoverflow.com
🌐 stackoverflow.com
python - Disable output in subprocess call ffmpeg - Stack Overflow
I am currently using the following command in python to convert my .webm file to .ogg subprocess.call(['ffmpeg', '-i', songfile, songfile + ".ogg"]) This prints out a bunch of output whi... More on stackoverflow.com
🌐 stackoverflow.com
July 16, 2021
How to catch ffmpeg read error in Python?
Use the ffmpeg python bindings instead of running a subproc. You can read from stderr until the read fails with .readuntil() More on reddit.com
🌐 r/ffmpeg
6
4
January 9, 2022
How to hide console output of FFmpeg in Python? - Stack Overflow
I was working on a YouTube video downloader Python program. I want to encode downloaded data to other media formats for this job i used FFmpeg and FFmpeg-Python (Package to use FFmpeg in Python). More on stackoverflow.com
🌐 stackoverflow.com
🌐
FFmpeg
ffmpeg.org › ffmpeg.html
ffmpeg Documentation
3 weeks ago - Under normal circumstances, a filtergraph should not buffer more than a few frames, especially if frames are being fed to it and read from it in a balanced way (which is the intended behavior in ffmpeg). That said, this option allows you to limit the total number of frames buffered across all links in a filtergraph. If more frames are generated, filtering is aborted and an error is returned. The default value is 0, which means no limit. -pre[:stream_specifier] preset_name (output,per-stream) Specify the preset for matching stream(s). ... Log encoding progress/statistics as "info"-level log (see -loglevel).
🌐
PyAV
pyav.org › docs › develop › api › utils.html
Utilities — PyAV 9.0.3.dev0 documentation
Convert a library log level to a Python log level. ... Get the last log that was at least ERROR. ... Return current FFmpeg logging threshold.
🌐
FFmpeg
ffmpeg.org › ffprobe.html
ffprobe Documentation
It also implies -loglevel debug. Setting the environment variable FFREPORT to any value has the same effect. If the value is a ’:’-separated key=value sequence, these options will affect the report; option values must be escaped if they contain special characters or the options delimiter ’:’ (see the “Quoting and escaping” section in the ffmpeg...
🌐
FFmpeg Python
kkroening.github.io › ffmpeg-python
ffmpeg-python: Python bindings for FFmpeg — ffmpeg-python documentation
filter_ is normally used by higher-level filter functions such as hflip, but if a filter implementation is missing from ffmpeg-python, you can call filter_ directly to have ffmpeg-python pass the filter name and arguments to ffmpeg verbatim.
Find elsewhere
🌐
Reddit
reddit.com › r/ffmpeg › how to catch ffmpeg read error in python?
r/ffmpeg on Reddit: How to catch ffmpeg read error in Python?
January 9, 2022 -

-----------------------------------------------------------------------------------

Edit: Problem solved. The second code example works as expected.

Hi!

I'm using ffmpeg in a Python program to convert movie files.

The problem is that ffmpeg does not return a non-zero errorCode when it fails with a "read error" (e.g. connection to source file lost).

Here's the code:

 try:
        subprocess.run(params, check=True, stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr)

        log.info('Finished conversion.')
        log.info('Created file: ' + output_file_path)
        log.info('---------------------------------------------------------')
    except subprocess.CalledProcessError as error:
        log.info('ffmpeg exited with return code ' + str(error.returncode))
        log.error(f'**ERROR** An error occurred while converting the file'
                  f' {movie.file_path}.{os.linesep}{traceback.format_exc()}')
        sys.exit(0)

"params" contains the ffmpeg commands etc.

If subprocess.run() returns an error (non-zero), a CalledProcessError is raised, which I can then handle.

But how am I supposed to handle it if ffmpeg just silently fails?! Do I seriously have to find a way to parse ffmpeg's output line by line and search for "error"?

Edit:

I'm currently trying to parse ffmpeg's output for the "error" keyword playing around with this code:

    process = subprocess.Popen(params, encoding='UTF-8', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

    # while process is running
    while not process.poll():
        if process.stdout:
            std_out = process.stdout.readline()
            if std_out:
                log.info(std_out)
                if 'error' in std_out:
                    log.error('**ERROR** Detected error message from ffmpeg:')
                    # log.error(std_err)
                    log.info('Killing ffmpeg process...')
                    process.kill()
                    sys.exit(1)

    # process terminated
    if process.returncode and process.returncode != 0:
        log.error('**ERROR** ffmpeg returned error code ' + str(process.returncode))

Unfortuantely, I cannot find a way to get the "read error" message to get logged. It's not in ffmpeg's stdout nor in its stderr.

Top answer
1 of 6
16

set loglevel to quiet

ffmpeg.input(file).output(filename, loglevel="quiet").run()
2 of 6
5

It has been 1 year and 8 months since you have asked this question, you might already have a solution for that. However, I found a solution to solve your problem.

You can solve this problem by modifying the original ffmpeg code when you package your python program.

First, find your ffmpeg lib folder, if you install with the default location, you can check your libs here: C:\Users\User\AppData\Local\Programs\Python\Python310\Lib\site-packages\ffmpeg.

Second, find _probe.py and modify codes, here is the code that already got modified, any change is written in the comments. You need to Popen add args: shell=True, stdin=subprocess.PIPE.

import json
import subprocess
from ._run import Error
from ._utils import convert_kwargs_to_cmd_line_args


def probe(filename, cmd='ffprobe', **kwargs):
    """Run ffprobe on the specified file and return a JSON representation of the output.

    Raises:
        :class:`ffmpeg.Error`: if ffprobe returns a non-zero exit code,
        an :class:`Error` is returned with a generic error message.
        The stderr output can be retrieved by accessing the
        ``stderr`` property of the exception.
    """
    args = [cmd, '-show_format', '-show_streams', '-of', 'json']
    args += convert_kwargs_to_cmd_line_args(kwargs)
    args += [filename]

    # Original: p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # Popen add args: shell=True, stdin=subprocess.PIPE,

    p = subprocess.Popen(args, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if p.returncode != 0:
        raise Error('ffprobe', out, err)
    return json.loads(out.decode('utf-8'))


__all__ = ['probe']

Then, go to _run.py. You need to add shell=True, modify stdin=subprocess.PIPE or modify pipe_stdin=True (The code section below is just a part of the code):

@output_operator()
def run_async(
    stream_spec,
    cmd='ffmpeg',
    pipe_stdin=False,
    pipe_stdout=False,
    pipe_stderr=False,
    quiet=False,
    overwrite_output=False,
):
    """Asynchronously invoke ffmpeg for the supplied node graph.

Args:
    pipe_stdin: if True, connect pipe to subprocess stdin (to be
        used with ``pipe:`` ffmpeg inputs).
    pipe_stdout: if True, connect pipe to subprocess stdout (to be
        used with ``pipe:`` ffmpeg outputs).
    pipe_stderr: if True, connect pipe to subprocess stderr.
    quiet: shorthand for setting ``capture_stdout`` and
        ``capture_stderr``.
    **kwargs: keyword-arguments passed to ``get_args()`` (e.g.
        ``overwrite_output=True``).

Returns:
    A `subprocess Popen`_ object representing the child process.

Examples:
    Run and stream input::

        process = (
            ffmpeg
            .input('pipe:', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(width, height))
            .output(out_filename, pix_fmt='yuv420p')
            .overwrite_output()
            .run_async(pipe_stdin=True)
        )
        process.communicate(input=input_data)

    Run and capture output::

        process = (
            ffmpeg
            .input(in_filename)
            .output('pipe':, format='rawvideo', pix_fmt='rgb24')
            .run_async(pipe_stdout=True, pipe_stderr=True)
        )
        out, err = process.communicate()

    Process video frame-by-frame using numpy::

        process1 = (
            ffmpeg
            .input(in_filename)
            .output('pipe:', format='rawvideo', pix_fmt='rgb24')
            .run_async(pipe_stdout=True)
        )

        process2 = (
            ffmpeg
            .input('pipe:', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(width, height))
            .output(out_filename, pix_fmt='yuv420p')
            .overwrite_output()
            .run_async(pipe_stdin=True)
        )

        while True:
            in_bytes = process1.stdout.read(width * height * 3)
            if not in_bytes:
                break
            in_frame = (
                np
                .frombuffer(in_bytes, np.uint8)
                .reshape([height, width, 3])
            )
            out_frame = in_frame * 0.3
            process2.stdin.write(
                frame
                .astype(np.uint8)
                .tobytes()
            )

        process2.stdin.close()
        process1.wait()
        process2.wait()

.. _subprocess Popen: https://docs.python.org/3/library/subprocess.html#popen-objects
"""
    args = compile(stream_spec, cmd, overwrite_output=overwrite_output)
    stdin_stream = subprocess.PIPE if pipe_stdin else None
    stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None
    stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None

    # Original: return subprocess.Popen(
    #           args, stdin=pipe_stdin, stdout=stdout_stream, stderr=stderr_stream)    
    # Add shell=True, modify stdin=subprocess.PIPE or modify pipe_stdin=True

    return subprocess.Popen(
        args, shell=True, stdin=subprocess.PIPE, stdout=stdout_stream, stderr=stderr_stream
    )
🌐
PyAV
pyav.org › docs › stable › api › utils.html
Utilities — PyAV 9.0.2 documentation
Convert a library log level to a Python log level. ... Get the last log that was at least ERROR. ... Return current FFmpeg logging threshold.
🌐
GitHub
github.com › kkroening › ffmpeg-python › issues › 22
Add logger to ffmpeg call · Issue #22 · kkroening/ffmpeg-python
July 9, 2017 - It would be very useful to have a logger for the ffmpeg call. It would be easier to integrate in a system of loggers. Is it possible to have in the future?
Author   WisdomPill
🌐
OneLinerHub
onelinerhub.com › ffmpeg › how-to-change-loglevel
Ffmpeg: How to change loglevel - OneLinerHub
9951 explained code solutions for 126 technologies · You can set one of the following log levels: "quiet", "panic", "fatal", "error", "warning", "info", "verbose", "debug", "trace":
🌐
Reddit
reddit.com › r/ffmpeg › trouble creating a log file
r/ffmpeg on Reddit: Trouble creating a log file
July 17, 2023 -

Hi everyone,

I'm wanting FFMPEG to create a log file so I can see if there have been errors while the program is running.

All I'm doing is mixing videos down from surround sound to stereo, so my command line looks like this:

ffmpeg -i [input file] -c:v copy -c:a libfdk_aac -b:a 256k [output file]

What do I add to generate a txt file that shows any major errors? I have been looking around for days and cannot find anything that works. I'm not a programmer so reading documentation has only confused me further. Help?

Thank you in advance! :)

Top answer
1 of 2
3

Actually, the full set of environment variables to control logging of ffmpeg and the video-related parts of OpenCV is as follows:

  • OPENCV_LOG_LEVEL (the general OpenCV log level. e.g.: VERBOSE)
  • OPENCV_VIDEOIO_DEBUG (set to 1 to enable debugging of the videoio module)
  • OPENCV_FFMPEG_DEBUG (set to 1 to enable debugging of the ffmpeg backend) and
  • OPENCV_FFMPEG_LOGLEVEL which expects a numerical value. you can pick one from the following defines (stripped from ffmpeg source code) :
    #define AV_LOG_QUIET    -8
    #define AV_LOG_PANIC     0
    #define AV_LOG_FATAL     8
    #define AV_LOG_ERROR    16
    #define AV_LOG_WARNING  24
    #define AV_LOG_INFO     32
    #define AV_LOG_VERBOSE  40
    #define AV_LOG_DEBUG    48
    #define AV_LOG_TRACE    56

So.. for the debug level you have to do something like:

export OPENCV_FFMPEG_LOGLEVEL=48

You'd probably want the following variables as well:

export OPENCV_VIDEOWRITER_DEBUG=1
export OPENCV_VIDEOCAPTURE_DEBUG=1

Sooo.. for maximum logging of OpenCV/videoio/ffmpeg:

export OPENCV_VIDEOIO_DEBUG=1
export OPENCV_FFMPEG_DEBUG=1
export OPENCV_LOG_LEVEL=VERBOSE
export OPENCV_FFMPEG_LOGLEVEL=56

but there are many more environment variables you can use to get a better picture of what is going on. the following are a collection of additional variables i use for debugging:

export OPENCV_OPENCL_RAISE_ERROR=1
export OPENCV_OPENCL_ABORT_ON_BUILD_ERROR=1
export OPENCV_DUMP_ERRORS=1
export OPENCV_DUMP_CONFIG=1
export OPENCV_TRACE=1
export OPENCV_TRACE_DEPTH_OPENCV=1
export OPENCV_TRACE_SYNC_OPENCL=1
2 of 2
2

Hello you can set those env variable:

export OPENCV_VIDEOIO_DEBUG=1
export OPENCV_FFMPEG_DEBUG=1
export OPENCV_LOG_LEVEL=DEBUG
🌐
GitHub
github.com › kkroening › ffmpeg-python › issues › 68
Passing flags to ffmpeg · Issue #68 · kkroening/ffmpeg-python
February 2, 2018 - I would like to pass on the following flags to ffmpeg .-nostdin -loglevel error Is it possible ? The nostdin flag is required because ffmpeg swallows stdin. More info here. The loglevel parameter w...
Author   kishaningithub
🌐
GitHub
github.com › kkroening › ffmpeg-python › issues › 822
How to set the logging level · Issue #822 · kkroening/ffmpeg-python
February 15, 2024 - When running ffmpeg, I have a bunch of logs in the console. Which is great for debugging, but a lot of noise anyways when you know stuff works. Is there a way to disable those logs? Thank you 👍
Author   AdrKacz
🌐
Basswood-io
pyav.basswood-io.com › docs › stable › api › utils.html
Utilities — PyAV 16.1.0 documentation
Convert a library log level to a Python log level. ... Get the last log that was at least ERROR. ... Returns the current log level. See set_level(). ... Send a log through the library logging system. This is mostly for testing. ... Revert back to FFmpeg’s log callback, which prints to the terminal.