Bogdan
Bogdan

Reputation: 91

PHP FFmpeg drawtext command not working from exec

I have a problem that a struggle for days. I have a laravel 9 backend and I'm using ffmpeg to edit videos. I'm running diferite commands that are working perfectly from exec command.

The weird part is that only drawtext command is not working from exec, If I run the the exactly same command from terminal it's working. This is the command:

 C:\\ffmpeg\\ffmpeg -i  C:\\xampp\\htdocs\\360_backend\\storage\\app\\public\\videos\\sample.mp4  -filter_complex drawtext=\"x=640:y=360:fontsize=24:fontcolor=white:fontfile=georgia.ttf:text=test.txt\" -c:a copy C:\\xampp\\htdocs\\360_backend\\storage\\app\\public\\videos\\testtt3.mp4 2> C:\\xampp\\htdocs\\360_backend\\storage\\app\/public\\videos\/out.txt" 

This is what I get on the output file, it's geting stuck on Stream #0:1[0x2]

ffmpeg version 6.0-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\xampp\htdocs\360_backend\storage\app\public\videos\sample.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01T00:00:00.000000Z
    encoder         : Lavf53.24.2
  Duration: 00:00:05.31, start: 0.000000, bitrate: 1589 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 1205 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 384 kb/s (default)
    Metadata:
      creation_time   : 1970-01-01T00:00:00.000000Z
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

Upvotes: 0

Views: 95

Answers (1)

Bogdan
Bogdan

Reputation: 91

The error was from loading the fontFile. Also for drawtext command on Windows is needed to escape path when running from exec() ex: fontfile=C\\:\\\\Windows\\\\Fonts\\\\georgia.ttf

Here is the final working command: exec('C:\ffmpeg\ffmpeg -i C:\xampp\htdocs\360_backend\storage\app\public\videos\sample.mp4 -vf drawtext=x=640:y=360:fontsize=24:fontcolor=white:fontfile=\'C\\:\\\xampp\\\\htdocs\\\360_backend\\\storage\\\app\\\public\\\videos\\\georgia.ttf\':text=blabla -y C:\xampp\htdocs\360_backend\storage\app\public\videos\test.mp4 2> C:\xampp\htdocs\360_backend\storage\app\public\videos\out.txt')

Upvotes: 0

Related Questions