1

I need to take all audio files from a directory, and export them along with one of multiple pictures listed in a text file.

It's working to take all the audio files one by one, but I cannot make it have a different picture for each video. I have same picture all the time.

  1. I don't know how to make the loop working for the pictures files.
  2. Will be nice if someone can tell me how I can group pictures in order to export as a slideshow.

Thank you.

In .txt file my pictures are like this :

1.jpg
2.jpg
3.jpg

And my code looks like this:

@echo off
set "sourcedir=E:\test slideshow imagini"  
set "outputdir=E:\test slideshow imagini\1" 
PUSHD "%sourcedir%"
for /F "tokens=*" %%A in (poze3.txt) do (
    echo %%A
    :: pictures names
     for %%F in (*.wav *.mp3) DO ffmpeg -loop 1 -i %%A -i "%%F" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest -vf scale=1920:1080 "%outputdir%\%%F.mp4" 
    POPD
)
Gerhard
  • 22,678
  • 7
  • 27
  • 43

1 Answers1

2

You need a trick to read the next line of a file with each run of the loop:

@echo off
setlocal enabledelayedexpansion
set "sourcedir=E:\test slideshow imagini"  
set "outputdir=E:\test slideshow imagini\1" 
PUSHD "%sourcedir%"
<"poze3.txt" (
    for %%F in (*.wav *.mp3) DO (
        set /p pic=
        ffmpeg -loop 1 -i !pic! -i "%%F" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest -vf scale=1920:1080 "%outputdir%\%%F.mp4" 
    )
)

(untested, but should work).

Btw: DO NOT use :: as comment. Use REM instead.

I know, :: is used often and behaves well outside of code blocks, but tends to hiccup when used within code blocks, leading to unexpected behaviour which is hard to troubleshoot.

I removed the popd in the loop. Repeatedly popd's without matching push's don't make sense. You do only one pushd before the loop, so the matching popd should be after the loop, where you can omit it, as the script ends anyway.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • One quick question please: How Can I use multiple .txt files in same time? This will help me for slideshow to have different input pictures and to merge them. – Ionut Bejinariu Aug 19 '22 at 15:44
  • [up to eight files](https://stackoverflow.com/a/32739680/2152082) – Stephan Aug 19 '22 at 17:10