1

I'm quite new to ffmpeg and writing batches for command-line. I have a bunch of ffmpeg batch files, for various video processing tasks, that I'd like to add comments to so that other users can understand them and customize as required. Can anyone advise on methods of adding comments? Here's a simplified example showing what I've tried:

C:\some_location\ffmpeg.exe ^
-i input_file -vsync cfr ^            rem /COMMENT_01
-map 0:v ^                            rem /COMMENT_02
-r 24000/1001 ^                       rem /COMMENT_03
-pix_fmt yuv444p10le ^                rem /COMMENT_04
-c:v prores_ks -profile:v 4444 ^      rem /COMMENT_05
-map_metadata -1 ^                    rem /COMMENT_06
output_file

which gives the message: "Unable to find a suitable output format for 'rem'"

C:\some_location\ffmpeg.exe ^
-i input_file -vsync cfr ^            & :: /COMMENT_01
-map 0:v ^                            & :: /COMMENT_02
-r 24000/1001 ^                       & :: /COMMENT_03
-pix_fmt yuv444p10le ^                & :: /COMMENT_04
-c:v prores_ks -profile:v 4444 ^      & :: /COMMENT_05
-map_metadata -1 ^                    & :: /COMMENT_06
output_file

which gives the message: "Trailing options were found on the commandline." And then none of the options are recognized as commands.

C:\some_location\ffmpeg.exe ^
rem /COMMENT_01
-i input_file -vsync cfr ^
rem /COMMENT_02
-map 0:v ^
rem /COMMENT_03
-r 24000/1001 ^
rem /COMMENT_04
-pix_fmt yuv444p10le ^
rem /COMMENT_05
-c:v prores_ks -profile:v 4444 ^
rem /COMMENT_06
-map_metadata -1 ^
output_file

which gives the message: "Unable to find a suitable output format for 'rem'"

Does anyone have any ideas?

Niraj
  • 13
  • 2
  • 1
    You need to realise that as a single command line, split using `^` as a concatenation character, you're trying to add comments as command line arguments to ffmpeg. You could just add your remarks all together preceding the single command, which would be the sensible idea. Otherwise you could try using undefined variables as comments, e.g. `-i input_file -vsync cfr %= COMMENT_01 =% ^`. For this to work however, you cannot include any further **`%`** or **`:`** characters within those comments. – Compo Oct 09 '19 at 17:01
  • Use line continuation with care: 1. put a space before the `^` and ensure there is no character after `^`; 2. indent every continued line with at least one space, because the `^` from the preceding line actually escapes the first character of the next one, which is likely unintended; 3. do not use line continuation with the special commands `for`, `if` and `rem`, because those are particularly handled by the parser and may therefore cause errors... – aschipfl Oct 09 '19 at 18:34
  • There are no real in-line comments in batch scripting, though @Compo showed a nice work-around (take also a look at [this post](https://stackoverflow.com/a/34782032)); ensure that they do not appear behind the `^`! note that variables like `%= some name =%` cannot be defined, so (mis-)using them is quite safe, but this only works within a batch file but not directly in a command prompt window! – aschipfl Oct 09 '19 at 18:37

1 Answers1

2
C:\some_location\ffmpeg.exe ^
-i input_file -vsync cfr %= COMMENT_01 =% ^
-map 0:v %= COMMENT_02 =% ^
-r 24000/1001 %= COMMENT_03 =% ^
-pix_fmt yuv444p10le %= COMMENT_04 =% ^
-c:v prores_ks -profile:v 4444 %= COMMENT_05 =% ^
-map_metadata -1 %= COMMENT_06 =% ^
output_file

Treat expansion of an undefined variable as a comment (expands to nothing).

Line continuation ^ must be the last character on the line. Each %= COMMENT =% can appear anywhere on the line as long as it precedes the final ^.

Comments of this form cannot contain : or %

This only works within batch files. It cannot work on the command line because expansion of an undefined variable in command line mode does not result in an empty string.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Doesn't work for me. Can't comment out part of cmd line arguments. Using cmd.exe shell. %= -af aformat=flt,adeclip,loudnorm=I=-14:TP=-1:print_format=summary:measured_I=-21.1:measured_tp=2.0:measured_lra=12.0:measured_thresh=-31.2:offset=2.0,aresample=48k:dither_method=triangular_hp =% returns error: Unable to find a suitable output format for '%=' – Radim Kolář Oct 22 '22 at 10:41
  • @RadimKolář - I clearly stated the technique cannot be used if the comment contains `:` or `%`. Your comment contains `:`, so of course it will not work. – dbenham Oct 25 '22 at 21:47