Search code examples
batch-fileffmpegindentation

Does exists other way of indenting ffmpeg batch script?


How can I indent code in a Batch script other than using temporal variables %= =%? This is the only code that works for me with indentation.

::2020-12-31 10:43:40
@ECHO OFF
::SET VIDEO="E:\Vídeos\test.mp4"
SET VIDEO=%1
SET /P TITULO=Introduzca el título del vídeo: 
ffmpeg ^
    -y ^
    -loglevel verbose ^
    -i %VIDEO% ^
    -vf ^
          scale=^
%=          =%width=-2:^
%=          =%height=360,^
%=      =%drawtext=^
%=          =%fontfile='C\:/Windows/Fonts/impact.ttf':^
%=          =%text=%TITULO%:^
%=          =%fontcolor=white:^
%=          =%borderw=1:^
%=          =%fontsize=18:^
%=          =%alpha=0.99:^
%=          =%x=(w-tw)/2:^
%=          =%y=th/4:^
%=          =%expansion=none,^
%=      =%drawtext=^
%=          =%fontfile='C\:/Windows/Fonts/arial.ttf':^
%=          =%text='WATERMARK':^
%=          =%fontcolor=white:^
%=          =%borderw=1:^
%=          =%fontsize=18:^
%=          =%alpha=0.60:^
%=          =%x=w-tw-10:^
%=          =%y=h-th-10:^
%=          =%expansion=none^
    -map 0:v ^
    -map 0:a? ^
    -c:v h264 ^
    -crf 30 ^
    -c:a aac ^
    -q:a 1 ^
    -ac 1 ^
    %VIDEO:~0,-5%_WATERMARK.mp4

If I try to use spaces or tabs in the "-vf" section ffmpeg interprets them as the end of the filter and the start of the output file argument .


Solution

  • You should quote the video-filter expression. Then you don't need those temporal variables:

    ffmpeg^
      -y^
      -loglevel verbose^
      -i %VIDEO%^
      -vf ^"^
        scale=^
          width=-2:^
          height=360,^
        drawtext=^
          fontfile='C\:/Windows/Fonts/impact.ttf':^
          text='%TITULO%':^
          fontcolor=white:^
          borderw=1:^
          fontsize=18:^
          alpha=0.99:^
          x=(w-tw)/2:^
          y=th/4:^
          expansion=none,^
        drawtext=^
          fontfile='C\:/Windows/Fonts/arial.ttf':^
          text='WATERMARK':^
          fontcolor=white:^
          borderw=1:^
          fontsize=18:^
          alpha=0.60:^
          x=w-tw-10:^
          y=h-th-10:^
          expansion=none^
      "^
      -map 0:v^
      [...]
    

    Yes, that's ^" at the beginning and " at the end.

    Also please quote the "TITULO"-variable within the expression: '%TITULO%'.

    Finally, as a side note; the encoding.
    There's a pretty good chance your Batch script is encoded as ANSI (Windows-1252).
    This means your Introduzca el título del vídeo will come out as Introduzca el tφtulo del vφdeo.

    The ANSI encoded í (ALT+0237) comes out as the OEM encoded φ (ALT+237).

    In order to get the OEM encoded í (ALT+161) you have to enter the ANSI encoded ¡ (ALT+0161).
    So Introduzca el t¡tulo del v¡deo will come out as Introduzca el título del vídeo.

    This website has a nice chart where you can look it up, but charmap can also help.
    If you highlight the í, then you'll see U+00ED (0xA1): Latin Small Letter I With Acute Keystroke: Alt+0237 mentioned below.

    ED (hex) = 237 (dec) and A1 (hex) = 161 (dec).

    You can ignore this if your Batch script is encoded as OEM (CP437).