Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file doesn’t seem to work

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I am trying to run the following batch file from a folder. The folder also contains the ffmpeg exe and any mp3 files and a subfolder named ‘files’.

Code:
ffmpeg -f concat -i <( for f in *.mp3; do echo "file '$(pwd)/$f'"; done ) "files\concat.mp3”

What should happen is whichever folder I choose to drop all the files / folder as mentioned above in and then run the bat file I should get a single mp3 file in the folder named ‘files’ which has be concatenated with all the mp3 files. But it doesn’t seem to work.

Code:
file 'elvis 01.mp3'
file 'elvis 02.mp3'
file 'elvis 03.mp3'

The for loop should return the names on the fly in the above format (spaces included, if any) as that is what ffmpeg reads. The above example assumes 3 mp3 files named elvis 01.mp3, elvis 02.mp3 and elvis 03.mp3
 
Here is the official documentation for FFMPEG: Something in your argument doesn't seem valid but I cannot put my finger on it this exact second....

Not to push you away from here but seeing as this question may be extremely specific to those that have used the program, you may want to try here as it is specifically set up for using this program in a Windows environment:
Learning - A never ending quest for knowledge usually attained by being thrown in a situation and told to fix it NOW.
 
Hello DrB0b

Thanks for your reply.

I’ve been trying to solve this for days now, quite ridiculous I know, as it seemed to me to be something simple I was doing wrong.

I’m sure its to do with the bat loop, and that I’m running the bat file in whatever folder I place all the files in.

For example if I replace the loop part of the code

Code:
<( for f in *.mp3; do echo "file '$(pwd)/$f'"; done )

with the following

Code:
concat.txt

so the exact line would be

Code:
ffmpeg -f concat -i concat.txt -c copy "files\concat.mp3"

and place the example above in a text file named concat.txt in the same folder with all the other files

ie

Code:
file 'elvis 01.mp3'
file 'elvis 02.mp3'
file 'elvis 03.mp3'

then it works. So must be the loop. But my bat skills are not up to solving it. any ideas?
 
Um, what OS are you trying to do this from? I ask as the $(pwd)/$f looks suspiciously Linux/UNIX like

However, if you are using a Windows based OS, the format for a FOR loop is "FOR %variable IN (set) DO command [command-parameters]"

So wouldn't your FOR loop need to be something like for %f in (*.mp3) do echo file '%f'
 
Shouldn't it be
Code:
for /f %f in (files\*.mp3) do ffmpeg -f concat -i concat.txt -c copy %f
 
Hello everyone and thank you for your replies.

Something is definitely not quite right.

The o/s is winxp pro.

So the linux spot was a good one however I had already worked out that %f was the way to go when I found that the line below would generate the concat.txt file automatically for me.

Code:
for %%f in (*.mp3) do echo file '%%f' >> concat.txt

The problem however is that I don’t want to have to create the concat,txt file and read from it, I want to use process substitution <( ) which creates a file—or, to be precise, a file descriptor—on the fly, which ffmpeg can read.

So I thought the final one liner should be as follows but something must be off as it does nothing?

Can anyone help fix this?

Code:
ffmpeg -f concat -i <(for %%f in (*.mp3) do echo file '%%f') -c copy "files\output.mp3"
 
I'm still googling trying to find the right way to write the code, but just can't solve it, surely it's not this difficult?

Did find the following but just don't know if it takes me closer to solving the problem or is way off?

Any ideas?

Code:
ls Movie\ Part\ * | while read line; do echo file \'$line\'; done | ffmpeg -f concat -i - -c copy output.mp4

Just to keep things clear the following line is what i want to work in windowsxp

Code:
ffmpeg -f concat -i <(for %%f in (*.mp3) do echo file '%%f') -c copy "files\output.mp3"

The for loop should read in the following information or at least thats the information when in a separate text file that does work (assumes those are the files in the directory)

Code:
file 'elvis 01.mp3'
file 'elvis 02.mp3'
file 'elvis 03.mp3'



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top