Search code examples
batch-filecommand-lineffmpegcommentsline-continuation

How to write comments in batch files for ffmpeg?


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?


Solution

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