batch file for hardcoding subtitles in multiple videos with ffmpeg

1

My question at the top:

What is the correct way to refer to a dynamic file name for the ass filter when using -filter_complex in ?


The story and my attempt:

I have a folder that contains widescreeen (16:9) .mp4 files, 1920x1080 frame size. For each mp4 file, I also have an .ass subtitle file with the naming pattern of originalfilename_outline.ass. Finally, there's a transparent .png that serves as a watermark for the video.

My ultimate target is an mpeg2 PAL DVD .mpg file with input file rescaled to 576px height, and cropped equally on the left and right to a 4:3 aspect ratio with dimensions 720x576, and with the subtitles and watermark hard-coded into the video.

For this, I've tried the following .bat file in Windows, using .

for %%a in ("*.mp4") do ffmpeg -i "%%a"^
 -i full_screen_watermark.png^
 -aspect 4:3^
 -filter_complex "scale=1024x576,crop=iw-304:ih:152:0,overlay=0:0,ass=%%~nA_outline.ass"^
 -target pal-dvd "PAL_DVD_Format\%%~na.mpg"
pause

For an individual file, this works, but it seems like there's a problem with the ass=%%~nA_outline.ass part of the batch file because I get the following error:

Input #0, avi, from 'testing.mp4':
  Duration: 18:09:40.03, start: 0.000000, bitrate: 36 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (DIVX / 0x58564944), yuv420p, 192
0x1080 [SAR 1:1 DAR 16:9], 6461 kb/s, 25 fps, 25 tbr, 25 tbn, 1k tbc
    Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 44100 Hz, stereo, fl
tp, 128 kb/s
Input #1, png_pipe, from 'full_screen_watermark.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba, 720x576 [SAR 3543:3543 DAR 5:4], 25 tbr, 25 t
bn, 25 tbc
[Parsed_ass_3 @ 000000000033ec60] ass_read_file(%~nA_outline.ass): fopen failed
[Parsed_ass_3 @ 000000000033ec60] Could not create a libass track when reading f
ile '%~nA_outline.ass'
[AVFilterGraph @ 0000000004ed1ec0] Error initializing filter 'ass' with args '%~
nA_outline.ass'
Error configuring filters.

I'm actually new to and I've pieced together this Windows batch file by browsing through the ffmpeg online manual and a few other answers on SuperUser, so if there's anything else that I'm doing that is obviously wrong, please let me know :-)

Ananda Mahto

Posted 2015-02-11T10:10:46.380

Reputation: 125

Answers

3

The index variable for FOR loops is case sensitive.  You need to change %%~nA to %%~na (or capitalize the other occurrences).

G-Man Says 'Reinstate Monica'

Posted 2015-02-11T10:10:46.380

Reputation: 6 509

1Man I feel a face-palm coming on.... – Ananda Mahto – 2015-02-11T10:53:41.680