1

I have developed a small batch script using ffmpeg library that can add a video lip at the starting of all the videos containing in the folder

Here is my script:

@echo off
mkdir append

(for %%i in (*.mp4) do @echo %%i) > append/mymp4list.txt

ffmpeg -i main.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts -y append/main.ts

for /F "tokens=*" %%A in (append/mymp4list.txt) do (
    echo %%A
    ffmpeg -i %%A -c copy -bsf:v h264_mp4toannexb -f mpegts -y append/%%A.ts
    ffmpeg -i "concat:append/main.ts|append/%%A.ts" -c copy -bsf:a aac_adtstoasc -y append/%%A_output.mp4
)

it is working fine with video that has names with only digits or characters like sample.mp4 and video123.mp4
but when name of video file contains special characters or white space(like 2016-17 video - English - gateway (1).mp4 )it shows error in this line :

ffmpeg -i "concat:append/main.ts|append/%%A.ts" -c copy -bsf:a aac_adtstoasc -y append/%%A_output.mp4

where main.ts is starting clip of video and %%A is name of video from text file.

can someone tell me that how do i perform concatenate operation of video file when video file name contains special characters or white space ?

1
  • Did you quote the filenames correctly?
    – Xen2050
    May 8, 2017 at 16:17

2 Answers 2

1

First, the disclaimer, it has been a long time since I've done any CMD scripting, and I don't have a Windows host available to test this.

That said, most command line tools use space to separate arguments. You may be able to avoid this using double quotes around each and every use of %%A in your script, that aren't already quoted, for example:

ffmpeg -i "concat:append/main.ts|append/%%A.ts" -c copy -bsf:a aac_adtstoasc -y append/%%A_output.mp4

would become:

ffmpeg -i "concat:append/main.ts|append/%%A.ts" -c copy -bsf:a aac_adtstoasc -y "append/%%A_output.mp4"

Good luck, I hope this actually helps.

Bob

6
  • but that's not the way ffmpeg works...
    – JAGGADAKU
    May 8, 2017 at 16:24
  • 1
    It's the cmd interpreter first parsing the line. Under windows ffmpeg will handle the quoted -y parameter properly. You should try before arguing.
    – LotPings
    May 8, 2017 at 16:37
  • @lotPings that is just name of output of file. and i am facing problem near ffmpeg -i "concat:main.ts | %%A.ts" which is not allowing special character as name of file.
    – JAGGADAKU
    May 8, 2017 at 17:17
  • Try escaping the pipe symbol ^|
    – LotPings
    May 8, 2017 at 17:22
  • already tried that but not really working ffmpeg is considering concat:append/main.ts^|append/%%A.ts as a single file. where | is used to distinguish files.
    – JAGGADAKU
    May 8, 2017 at 17:29
0

The best option is to quote the string. It works for all other special characters and white spaces. I am attaching a snapshot from Here are some examples I found of the ffmpeg documentation page. I am attaching a screen shot just in in case it is unavailable in the future.

Quoting Special Characters

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .