Hello! Need help on how to merge video, audio, and multiple subtitles from one folder using ffmpeg with bash script. I'm using Google Colab to run the script with my Drive mounted on it.
So, I have a folder on my Drive named "episode1" with the following files and want to merge them to .mkv.episode1_video.mp4Merging them manually with this command:
episode1_audio.m4a
episode1_subtitle_en.vtt
episode1_subtitle_es.vtt
episode1_subtitle_pt.vtt
However, this is time-consuming since I need to copy-paste each file path manually, so I tried making a bash script. (Please note that I'm new to script-making and just mostly copied and combined what I found on the internet.)Code:ffmpeg -i "/content/drive/MyDrive/episode1/episode1_video.mp4" -i "/content/drive/MyDrive/episode1/episode1_audio.m4a" -i "/content/drive/MyDrive/episode1/episode1_subtitle_en.vtt" -i "/content/drive/MyDrive/episode1/episode1_subtitle_es.vtt" -i "/content/drive/MyDrive/episode1/episode1_subtitle_pt.vtt" \ -map 0:v -map 0:a? -map 1 -map 2 -map 3 -map 4 \ -c copy \ -disposition:s:0 default \ /content/drive/MyDrive/show_episode1.mkv \ -hide_banner
But I get this error instead:Code:#!/bin/bash input_directory="/content/drive/MyDrive/episode1" #@param {type: "string"} output_path="/content/drive/MyDrive" #@param {type: "string"} file_name="show_episode1" #@param {type: "string"} for video_file in "$input_directory"/*.mp4; do base_path=${video_file%.*} base_name=${base_path##*/} for audio_file in "$input_directory"/*.m4a; do base_path=${audio_file%.*} base_name=${base_path##*/} for subtitle_file in "$input_directory"/*.vtt; do base_path=${subtitle_file%.*} base_name=${base_path##*/} ffmpeg -i "$video_file" -i "$audio_file" -i "$subtitle_file" -map 0:v -map 0:a? -map 1 -map 2 -map 3 -map 4 -c copy -disposition:s:0 default "$output_path"/"$file_name".mkv -hide_banner done done done
There's something wrong/missing with the script but can't figure out how to fix it. I want to merge everything including all the subtitles. Hope someone can help. Thank you!Code:Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/content/drive/MyDrive/episode1/episode1_video.mp4': Metadata: major_brand : isom minor_version : 1 compatible_brands: isomavc1mp42iso5iso6 Duration: 00:01:09.47, start: 0.066733, bitrate: 3869 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3862 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default) Metadata: handler_name : Bento4 Video Handler Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/content/drive/MyDrive/episode1/episode1_audio.m4a': Metadata: major_brand : isom minor_version : 1 compatible_brands: isomiso5iso6 Duration: 00:01:09.50, start: 0.000000, bitrate: 199 kb/s Stream #1:0(kor): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 192 kb/s (default) Metadata: handler_name : Bento4 Sound Handler Input #2, webvtt, from '/content/drive/MyDrive/episode1/episode1_subtitle_en.vtt': Duration: N/A, bitrate: N/A Stream #2:0: Subtitle: webvtt Invalid input file index: 3.
+ Reply to Thread
Results 1 to 2 of 2
-
Last edited by oknchm; 13th Nov 2022 at 17:19.
Similar Threads
-
How to batch merge video & audios with same name inside a folder in Windows
By maxteddy in forum Video ConversionReplies: 4Last Post: 31st Jan 2022, 10:58 -
[ffmpeg] merge two audio track with delay
By FXMkD in forum ProgrammingReplies: 6Last Post: 1st Nov 2021, 08:35 -
merge video ffmpeg problem
By lomero in forum Video ConversionReplies: 11Last Post: 16th Apr 2021, 07:17 -
How to normalize audio of an entire folder with MP4s (FFmpeg)
By Aorin in forum Newbie / General discussionsReplies: 0Last Post: 4th Jun 2020, 17:23 -
FFMPEG how to merge 2 stereo .wav audio files into one of 4 channels?
By marcorocchini in forum Newbie / General discussionsReplies: 4Last Post: 24th Jun 2018, 07:25