1

I'm using ffmpeg to burn frame number into video. I suspect the error has something to do with file path.

Here's my command

ffmpeg -i in.mp4 -vf "drawtext=fontfile='E\:\\ffmpegTool\\bin\\arialbd.ttf':fontsize=30: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}: box=1" -y out.mp4

I've tried this, this and this. They didn't work

Here's the error

ffmpeg version N-85091-g23ae3cc Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
  libavutil      55. 57.100 / 55. 57.100
  libavcodec     57. 88.100 / 57. 88.100
  libavformat    57. 70.100 / 57. 70.100
  libavdevice    57.  5.100 / 57.  5.100
  libavfilter     6. 81.100 /  6. 81.100
  libswscale      4.  5.100 /  4.  5.100
  libswresample   2.  6.100 /  2.  6.100
  libpostproc    54.  4.100 / 54.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\ffmpegTool\bin\00872.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-04-01T08:35:15.000000Z
  Duration: 00:00:52.31, start: 0.000000, bitrate: 11442 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 11130 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      creation_time   : 2017-04-01T08:35:15.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2017-04-01T08:35:15.000000Z
      handler_name    : Alias Data Handler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 @ 00000000010ab340] Cannot find a valid font for the family Sans
[AVFilterGraph @ 00000000052c9280] Error initializing filter 'drawtext' with args 'fontfile=E\:\\ffmpegTool\\bin\\arialbd.ttf:fontsize=30: fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\:n+1}: box=1'
Error reinitializing filters!
Failed to inject frame into filter network: No such file or directory
Error while processing the decoded data for stream #0:0
Conversion failed!

Appreciate the help.

2

Omit double quotes (") around the whole filter, use them only for the path to font file and omit spaces after ::

ffmpeg -i in.mp4 -vf drawtext=fontfile="E\:\\ffmpegTool\\bin\\arialbd.ttf":fontsize=30:fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}:box=1 -y out.mp4

Also, your path to the font file is suspicious - try using the default Windows font path

c:\Windows\Fonts\,

so your command will be

ffmpeg -i in.mp4 -vf drawtext=fontfile="c\:\\Windows\\Fonts\\arialbd.ttf":fontsize=30:fontcolor=black:x=(w-text_w)/2:y=(h-text_h)/2:text=%{expr\\\\\:n+1}:box=1 -y out.mp4
  • It didn't work :( maybe it's the Fontconfig error: Cannot load default config file? – Moore Apr 10 '17 at 10:40
  • No, default config file is *nix specific - it is the file fonts.conf (in the default directory /etc/fonts/). You are using Windows - probably you wrote incorrect path. I edited my answer, see it. – MarianD Apr 10 '17 at 11:04
  • Apparently it's the fontcolor that keeps making the error. I omitted one by one and this is the working code ffmpeg -i in.mp4 -vf drawtext=fontsize=40:x=(w-text_w)/2:y=(h-text_h)/2:fontfile='C\:\\Windows\\Fonts\\Arial.ttf':text=%{n}:box=1 -y out.mp4 (") didn't work. but (') did. How very strange it's the fontcolor... – Moore Apr 10 '17 at 11:54
  • It seems as something impossible (in spite of that black is the default fontcolor). Did you try some other colors or the notation fontcolor=0x000000 ? – MarianD Apr 10 '17 at 12:24
  • Yes you're right. It seems it's the part text=%{expr\\\\\:n+1} that caused something wrong. I forgot I also omitted that part at the same time. fontcolor works as expected. Thanks! – Moore Apr 10 '17 at 14:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.