Use a for loop. This example is for bash
and uses bash
variable manipulation, but it can be adapted for other unix/linux-type shells.
Note: this assumes that you are in the directory with the files, and that both video and audio files are present with the same name, differing only by extension (.m4v -- video, .m4a -- audio).
for v in *.m4v; do ffmpeg -i "${v}" -i "${v//.m4v/.m4a}" -acodec copy -vcodec copy "${v//.m4v/.mp4}"; done
Explanation
for v in *.m4v
Perform the following actions on every file ending in '.m4v'. v
is a variable name that will be assigned every video file in the current directory, one at a time, by bash
. bash
will automatically convert the *.m4v
into a list of .m4v files in the current directory and feed them into the for loop. You do not need to input file names manually.
Variable v
holds a different video file name on each loop iteration, for example "video_file_1.m4v"
, then "video_file_2.m4v"
, etc. The ${v//pattern/replacement}
tells bash
to find occurrences of pattern
and replace them with replacement
. For example, ${v//.m4v/.mp4}
will convert the file name "video_file_1.m4v"
to "video_file_1.mp4"
.