Lightweight Video Editing: Bulk Change Default Audio Tracks and Merge Multiple Videos (MKVToolNix Not Suitable)
In this article, we will discuss how to perform lightweight video editing tasks such as bulk changing default audio tracks and merging multiple videos. This is particularly useful for individuals who have many folders with numerous videos of different sizes in MP4 and MKV formats and want to upload them in an organized manner.
Bulk Change Default Audio Tracks
Changing the default audio track of a video can be useful when the audio track in the default language is not preferred. While there are several video editing software available, not all of them support bulk changing default audio tracks. One lightweight and efficient tool for this task is ffmpeg.
ffmpeg -i input.mkv -c copy -disposition:a:0 default output.mkv
In the above command, -i input.mkv specifies the input file, -c copy tells ffmpeg to copy the existing video and audio streams, and -disposition:a:0 default sets the first audio stream as the default audio track. The output file is specified as output.mkv.
To change the default audio track for multiple videos in bulk, the following command can be used:
for i in *.mkv; do ffmpeg -i "$i" -c copy -disposition:a:0 default "${i%.*}_default.mkv"; done
The above command uses a for loop to iterate through all MKV files in the current directory, changes the default audio track, and saves the output file with the same name as the input file but with "_default" appended to the name.
Merge Multiple Videos
Merging multiple videos can be useful when creating a longer video from shorter clips. One lightweight and efficient tool for this task is also ffmpeg.
ffmpeg -i "concat:input1.mp4|input2.mp4|input3.mp4" -c copy output.mp4
In the above command, concat: specifies that multiple input files will be concatenated. The input files are separated by the "|" character. The output file is specified as output.mp4.
To merge multiple videos in bulk, the following command can be used:
find . -type f -name '*.mp4' -print0 | sort -z | awk -v ORS='|' '{print "'"$0"'"}' | xargs -0 -I % ffmpeg -i "concat:%" -c copy output.mp4
The above command uses the find command to find all MP4 files in the current directory and its subdirectories, sort command to sort the files in alphabetical order, and awk command to add the "|" character between the file names. The output file is specified as output.mp4.
In this article, we have discussed how to perform lightweight video editing tasks such as bulk changing default audio tracks and merging multiple videos using the ffmpeg tool. These tasks can be useful for individuals who have many folders with numerous videos of different sizes in MP4 and MKV formats and want to upload them in an organized manner.