Execute a ffmpeg command for each mp3 file in a folder
Moderator: DosItHelp
-
- Posts: 5
- Joined: 26 Jan 2024 15:52
Execute a ffmpeg command for each mp3 file in a folder
I have this command which works fine
ffmpeg -i "concat:felica.mp3|4sec.mp3|felica.mp3" -acodec copy felica4secfelica.mp3
What is it? It's a pronunciation audio + 4 seconds silence + a repeat of the audio.
I also have this code
dir /b /a-d *.mp3 > mp3file.txt
Which collects the names of all mp3 files in the folder
What I need is a code body to count the number of lines in mp3files.txt and use that number to execute the ffmpeg command for every mp3-file in the folder. (That will of course include that 4sec-file but that's not a problem)
ffmpeg -i "concat:felica.mp3|4sec.mp3|felica.mp3" -acodec copy felica4secfelica.mp3
What is it? It's a pronunciation audio + 4 seconds silence + a repeat of the audio.
I also have this code
dir /b /a-d *.mp3 > mp3file.txt
Which collects the names of all mp3 files in the folder
What I need is a code body to count the number of lines in mp3files.txt and use that number to execute the ffmpeg command for every mp3-file in the folder. (That will of course include that 4sec-file but that's not a problem)
Re: Execute a ffmpeg command for each mp3 file in a folder
You're about making it an XY problem. Neither do you need to write a text file, nor do you ever need to know the number of files. Just process the output of DIR directly, preferably with a filter that excludes file names containing "4sec".
Give that a go:
This only prints the ffmpeg commands. If you think it would do what you intend, remove the ECHO command to actually execute the commands listed before.
Steffen
Give that a go:
Code: Select all
@echo off &setlocal
for /f "delims=" %%i in ('dir /b /a-d *.mp3^|findstr /vc:"4sec"') do ECHO ffmpeg -i "concat:%%~i|4sec.mp3|%%~i" -acodec copy "%%~ni4sec%%~i"
PAUSE
Steffen
-
- Posts: 5
- Joined: 26 Jan 2024 15:52
Re: Execute a ffmpeg command for each mp3 file in a folder
Steffen, Du bist ein Mensch.
I've been looking for the answer to this problem for over a week, and you gave it to me in no time.
Don't know if line breaks are allowed in bat files, but with or without them could you break down the code and explain the most important parts?
I've been looking for the answer to this problem for over a week, and you gave it to me in no time.
Don't know if line breaks are allowed in bat files, but with or without them could you break down the code and explain the most important parts?
Re: Execute a ffmpeg command for each mp3 file in a folder
Code: Select all
@echo off
Code: Select all
setlocal
Code: Select all
for /f "delims=" %%i in
Run FOR /? in a cmd prompt to get more context from the help message.
Code: Select all
('dir /b /a-d *.mp3^|findstr /vc:"4sec"')
Run FINDSTR /? in a cmd prompt and read about options /v and /c.
Code: Select all
do ffmpeg -i "concat:%%~i|4sec.mp3|%%~i" -acodec copy "%%~ni4sec%%~i"
Steffen
-
- Posts: 5
- Joined: 26 Jan 2024 15:52
Re: Execute a ffmpeg command for each mp3 file in a folder
Steffen, you're a Super-Mensch!
I may finally be able to understand some of the inner workings of this mysterious DOS command world.
The fun thing is that I used to write Java programs, so the code shouldn't be that difficult for me to understand, but the syntax is quite different, so I was left stumped.
Once again, thank you, and in the words of the great philosopher Arnold Schwarzenegger. I'll be back!
I may finally be able to understand some of the inner workings of this mysterious DOS command world.
The fun thing is that I used to write Java programs, so the code shouldn't be that difficult for me to understand, but the syntax is quite different, so I was left stumped.
Once again, thank you, and in the words of the great philosopher Arnold Schwarzenegger. I'll be back!
-
- Posts: 5
- Joined: 26 Jan 2024 15:52
Re: Execute a ffmpeg command for each mp3 file in a folder
And I'm back!
Slight hick-up. The audio files are pronunciation of Esperanto words, some of which has diacritics like ĝ or ŭ. This causes the batch file to complain
No such file or directory.
Any way to fix this?
Slight hick-up. The audio files are pronunciation of Esperanto words, some of which has diacritics like ĝ or ŭ. This causes the batch file to complain
No such file or directory.
Any way to fix this?
Re: Execute a ffmpeg command for each mp3 file in a folder
I would think your code page would be set properly considering you are in the EU. Would be interesting to see what your code page is currently set to. You can type chcp at a command prompt to get that information. You can change the code page with the chcp command as well. You could try 65001.
-
- Posts: 5
- Joined: 26 Jan 2024 15:52
Re: Execute a ffmpeg command for each mp3 file in a folder
My code page was set to 850.
I changed to 65001 as per your recommendation, and now the bat file runs smoothly again.
Until the next stumbling block...
I changed to 65001 as per your recommendation, and now the bat file runs smoothly again.
Until the next stumbling block...