How do I enable FFMPEG logging and where can I find the FFMPEG log file?

119,129

Solution 1

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.)

Solution 2

I found the below stuff in ffmpeg Docs. Hope this helps! :)

Reference: http://ffmpeg.org/ffmpeg.html#toc-Generic-options

‘-report’ Dump full command line and console output to a file named program-YYYYMMDD-HHMMSS.log in the current directory. This file can be useful for bug reports. It also implies -loglevel verbose.

Note: setting the environment variable FFREPORT to any value has the same effect.

Solution 3

I find the answer. 1/First put in the presets, i have this example "Output format MPEG2 DVD HQ"

-vcodec mpeg2video -vstats_file MFRfile.txt -r 29.97 -s 352x480 -aspect 4:3 -b 4000k -mbd rd -trellis -mv0 -cmp 2 -subcmp 2 -acodec mp2 -ab 192k -ar 48000 -ac 2

If you want a report includes the commands -vstats_file MFRfile.txt into the presets like the example. this can make a report which it's ubicadet in the folder source of your file Source. you can put any name if you want , i solved my problem "i write many times in this forum" reading a complete .docx about mpeg properties. finally i can do my progress bar reading this txt file generated.

Regards.

Solution 4

ffmpeg logs to stderr, and can log to a file with a different log-level from stderr. The -report command-line option doesn't give you control of the log file name or the log level, so setting the environment variable is preferable.

(-v is a synonym for -loglevel. Run ffmpeg -v help to see the levels. Run ffmpeg -h full | less to see EVERYTHING. Or consult the online docs, or their wiki pages like the h.264 encode guide).

#!/bin/bash

of=out.mkv
FFREPORT="level=32:file=$of.log" ffmpeg -v verbose   -i src.mp4 -c:a copy -preset slower -c:v libx264 -crf 21 "$of"

That will trancode src.mp4 with x264, and set the log level for stderr to "verbose", and the log level for out.mkv.log to "status".

(AV_LOG_WARNING=24, AV_LOG_INFO=32, AV_LOG_VERBOSE=40, etc.). Support for this was added 2 years ago, so you need a non-ancient version of ffmpeg. (Always a good idea anyway, for security / bugfixes and speedups)


A few codecs, like -c:v libx265, write directly to stderr instead of using ffmpeg's logging infrastructure. So their log messages don't end up in the report file. I assume this is a bug / TODO-list item.

To log stderr, while still seeing it in a terminal, you can use tee(1).


If you use a log level that includes status line updates (the default -v info, or higher), they will be included in the log file, separated with ^M (carriage return aka \r). There's no log level that includes encoder stats (like SSIM) but not status-line updates, so the best option is probably to filter that stream.

If don't want to filter (e.g. so the fps / bitrate at each status-update interval is there in the file), you can use less -r to pass them through directly to your terminal so you can view the files cleanly. If you have .enc logs from several encodes that you want to flip through, less -r ++G *.enc works great. (++G means start at the end of the file, for all files). With single-key key bindings like . and , for next file and previous file, you can flip through some log files very nicely. (the default bindings are :n and :p).

If you do want to filter, sed 's/.*\r//' works perfectly for ffmpeg output. (In the general case, you need something like vt100.py, but not for just carriage returns). There are (at least) two ways to do this with tee + sed: tee to /dev/tty and pipe tee's output into sed, or use a process substitution to tee into a pipe to sed.

# pass stdout and stderr through to the terminal, 
## and log a filtered version to a file (with only the last status-line update).

of="$1-x265.mkv"
ffmpeg -v info -i "$1" -c:a copy -c:v libx265 ... "$of" |&    # pipe stdout and stderr
   tee /dev/tty | sed 's/.*\r//' >> "$of.enc"

## or with process substitution where tee's arg will be something like /dev/fd/123

ffmpeg -v info -i "$1" -c:a copy -c:v libx265 ... "$of" |&
  tee >(sed 's/.*\r//' >> "$of.enc")

For testing a few different encode parameters, you can make a function like this one that I used recently to test some stuff. I had it all on one line so I could easily up-arrow and edit it, but I'll un-obfuscate it here. (That's why there are ;s at the end of each line)

ffenc-testclip(){
  # v should be set by the caller, to a vertical resolution.  We scale to WxH, where W is a multiple of 8 (-vf scale=-8:$v)
  db=0;   # convenient to use shell vars to encode settings that you want to include in the filename and the ffmpeg cmdline
  [email protected].${v}p.x265$pre.mkv; 
  [[ -e "$of.enc" ]]&&echo "$of.enc exists"&&return;   # early-out if the file exists

  # encode 25 seconds starting at 21m15s (or the keyframe before that)
  nice -14 ffmpeg -ss $((21*60+15))  -i src.mp4 -t 25  -map 0 -metadata title= -color_primaries bt709 -color_trc bt709 -colorspace bt709 -sws_flags lanczos+print_info -c:a copy -c:v libx265 -b:v 1500k -vf scale=-8:$v  -preset $pre -ssim 1 -x265-params ssim=1:cu-stats=1:deblock=$db:aq-mode=1:lookahead-slices=0 "$of" |&
   tee /dev/tty | sed 's/.*\r//' >> "$of.enc";
}

# and use it with nested loops like this.
for pre in fast slow;  do for v in  360 480 648 792;do  ffenc-testclip ;done;done

less -r ++G *.enc       # -r is useful if you didn't use sed

Note that it tests for existence of the output video file to avoid spewing extra garbage into the log file if it already exists. Even so, I used and append (>>) redirect.

It would be "cleaner" to write a shell function that took args instead of looking at shell variables, but this was convenient and easy to write for my own use. That's also why I saved space by not properly quoting all my variable expansions. ($v instead of "$v")

Solution 5

appears that if you add this to the command line:

 -loglevel debug

or

 -loglevel verbose

You get more verbose debugging output to the command line.

Share:
119,129
undefined
Author by

undefined

Developer working mainly with Flash AS2 and AS3, PHP, HTML etc.

Updated on July 19, 2022

Comments

  • undefined
    undefined almost 2 years

    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 logging and where is the log file saved. I have FFMPEG installed on a CentOS LAMP machine.

  • cregox
    cregox about 14 years
    While ffmpeg may not provide an option to write log files, depending on your codec and options the encoder will create logs. And that can be very disruptive since it's written where it's been executed, which can lead to permission issues. In my instance, it was a problem with PHP and using -pass 1/2.
  • Sukhpreet Singh Alang
    Sukhpreet Singh Alang almost 13 years
    @Stu Thompson, the problem here is that ffmpeg does not produce normal debug output to stderr when ffmpeg is not run from a console but executed programatically (it checks whether it's a TTY).
  • Stu Thompson
    Stu Thompson about 12 years
    @Tom: I don't have that problem, my Java code calls FFmpeg programmatically with no problems. And I'm not the only one.
  • rogerdpack
    rogerdpack over 11 years
    appears these days FFREPORT can also specify an output filename, see stackoverflow.com/questions/11241878/ffmpeg-report-generatio‌​n/… also NB that specifying "-report" automatically sets logging to verbose mode, I believe.
  • MarcusJ
    MarcusJ over 9 years
    Can you use -report and change the loglevel to debug?
  • Peter Cordes
    Peter Cordes almost 8 years
    @MarcusJ: Yes, use of=out.mkv; FFREPORT="level=32:file=$of.log" ffmpeg -v verbose ... "$of" to set the log level for stderr to "verbose", and the log level for out.mkv.log to "status". (AV_LOG_WARNING=24, AV_LOG_INFO=32, AV_LOG_VERBOSE=40). Support for this was added 2 years ago, so you need a non-ancient version of ffmpeg.
  • commonpike
    commonpike almost 8 years
    @Stu, I do, and so do others. FFMpeg runs fine called programmatically, but it generates no or different output to stderr
  • Peter Cordes
    Peter Cordes about 7 years
    @commonpike: I don't think it checks stdout or stderr, because redirecting those both to a pipe doesn't change the output. (With FFmpeg 3.3 run from a terminal on Linux). It might check whether there is a controlling tty, though, which a process still has even if its stdin, stdout, and stderr are redirected. Or maybe different versions of ffmpeg are different. (especially if the ffmpeg command on your system was really using the avconv fork of FFmpeg, that's certainly something that might have changed.)
  • user25
    user25 about 6 years
    what about Android?
  • Suuuehgi
    Suuuehgi over 4 years
    @MarcusJ FFREPORT=file="/my/log/location/%p-%t.log":level=48 ffmpeg -i [...] (compare)