Search code examples
bashshellffmpegmultimediavideo-editing

How to use 2 variable for "for" statement in Shell Script


I want to use f and v for variable. f *.mkv and v *.mp3

for f in *.mkv v in *.mp3; do 
   ffmpeg -i "$f" -i "$v" -vcodec copy merge_"$f"
done

I dont know how to do it properly. I am still new with bash shell scripting.

I hope someone can help me.


Solution

  • If the *.mp3 and *.mkv basenames are the same:

    for f in *.mkv; do
        mp3name="${f%.mkv}.mp3"
        ffmpeg -i "$f" -i "$mp3name" -vcodec copy "merge_${f}"
    done