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.
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.
I haven't tested it out, but I see an option in the man page to do:
ffmpeg -loglevel panic [rest of your ffmpeg stuff]
Should make it so only serious errors are logged, in theory
How do I enable FFMPEG logging and where can I find the FFMPEG log file? - Stack Overflow
python - Disable output in subprocess call ffmpeg - Stack Overflow
How to catch ffmpeg read error in Python?
How to hide console output of FFmpeg in Python? - Stack Overflow
FFmpeg does not write to a specific log file, but rather sends its output to standard error. To capture that, you need to either
- capture and parse it as it is generated
- redirect standard error to a file and read that afterward the process is finished
Example for std error redirection:
ffmpeg -i myinput.avi {a-bunch-of-important-params} out.flv 2> /path/to/out.txt
Once the process is done, you can inspect out.txt.
It's a bit trickier to do the first option, but it is possible. (I've done it myself. So have others. Have a look around SO and the net for details.)
From the ffmpeg documentation:
’-report’
Dump full command line and log output to a file namedprogram-YYYYMMDD-HHMMSS.login the current directory. This file can be useful for bug reports. It also implies-loglevel debug.
Setting the environment variableFFREPORTto any value has the same effect.
Additional options are available to change the filename and verbosity.
https://ffmpeg.org/ffmpeg.html#Generic-options
Daweo's answer is worth looking at, but here is why your attempt did not work: Remember that there is no shell involved when you do subprocess.call (unless you explicitly ask for it), which means that you need to pass -loglevel quiet as two separate items; ..., '-loglevel', 'quiet', ...
subprocess.call docs says
To suppress stdout or stderr, supply a value of
DEVNULL.
so you might replace
subprocess.call(['ffmpeg', '-i', songfile, songfile + ".ogg"])
using
subprocess.call(['ffmpeg', '-i', songfile, songfile + ".ogg"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
-----------------------------------------------------------------------------------
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.
set loglevel to quiet
ffmpeg.input(file).output(filename, loglevel="quiet").run()
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
)
This is now possible as of FFmpeg 2.2 with the -hide_banner option. See also the relevant commit and ticket.
AFAIK there is no way, loglevel is no use. Look at ffmpeg.c:
init_opts();
show_banner();
and cmdutils.c:
void show_banner(void)
{
fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n",
program_name, program_birth_year, this_year);
fprintf(stderr, " built on %s %s with %s %s\n",
__DATE__, __TIME__, CC_TYPE, CC_VERSION);
fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n");
print_all_libs_info(stderr, INDENT|SHOW_CONFIG);
print_all_libs_info(stderr, INDENT|SHOW_VERSION);
}
See here for an unsuccessful attempt of skipping it (I don't get what the GPL has to do with anything of this). I suggest you to file a bug and hope you are convicing enough.
As many others, I have ffmpeg compiled with show_banner() commented out, it's simply tiresome.
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! :)
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
Hello you can set those env variable:
export OPENCV_VIDEOIO_DEBUG=1
export OPENCV_FFMPEG_DEBUG=1
export OPENCV_LOG_LEVEL=DEBUG