0

I have 50 images with different names.

In the same folder, I a names.txt file that contains the names of all the images in that folder, like so:

apples.jpg
oranges.jpg
blackberries.jpg
etc.

And I have one audio file, sound.wav

I want to mix each image with the sound.wav file, to generate 50 videos:

apples.mp4
oranges.mp4
blackberries.mp4
etc.

Any ideas?

This is the script that worked for me for converting each image manually:

ffmpeg -loop 1 -y -i oranges.jpg -i sound.wav -shortest oranges.mp4

But I'd like to scale this, maybe have a script that goes through each line in the names.txt file to get the name of the image, converts that image to video and then moves on to the next image.

Thanks

  • What operating system are you using? Have you tried anything yet? – slhck Aug 4 '18 at 20:04
  • Windows 10, 64-bit OS. Haven't tried anything yet, any ideas? :) – Duraid Aug 5 '18 at 21:30
  • If you do a web search on how to read from a file line-by-line, you will find some examples on how to do that under Windows. All you need for a start is to replace -i oranges.jpg with -i %a, where %a would be replaced with the line you're reading from the text file. – slhck Aug 6 '18 at 6:55
  • I couldn't figure out how to do it that way. But I found another solution, basically concatenating the scripts in a CSV and then copy/pasting it into the Command Prompt. Like: ffmpeg -loop 1 -y -i apples.jpg -i intro5.wav -shortest apples_video.mp4 & ffmpeg -loop 1 -y -i oranges.jpg -i intro5.wav -shortest oranges_video.mp4 & ffmpeg -loop 1 -y -i blackberries.jpg -i intro5.wav -shortest blackberries_video.mp4 However, I'm having an issue with the video length. The audio is 28 seconds but the final video always comes out to 30 seconds (with the last 2 seconds being silent). Any ideas? – Duraid Aug 6 '18 at 19:15
  • I was able to achieve the desired result by replacing -shortest with -t 28 (where 28 is the number of seconds in the final video file). Not bad, but if you know of another way to achieve the same result without having to specify the length of the final file I'd love to hear it. :) Thanks – Duraid Aug 6 '18 at 19:22
1

You can iterate through the lines of a file in a Windows Batch file:

for /F "tokens=*" %%A in (names.txt) do [process]

Here, replace [process] with:

ffmpeg -loop 1 -y -i %%A -i intro5.wav -shortest %%~nA_movie.mp4

Where %A is the filename in the line, and %%~nA is the name without extension.

  • Note: this is untested, as I don't have Windows here to check. – slhck Aug 7 '18 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.