#!/bin/bash # Script: copy_audio.sh # Description: Combines the video from input.mp4 with the audio from audio.mp4 # Usage: ./copy_audio.sh input.mp4 audio.mp4 # Check if the correct number of arguments is provided if [ $# -ne 2 ]; then echo "Usage: $0 " exit 1 fi # Get input arguments INPUT_VIDEO="$1" AUDIO_VIDEO="$2" # Check if the input files exist if [ ! -f "$INPUT_VIDEO" ]; then echo "Error: Input video file '$INPUT_VIDEO' does not exist." exit 1 fi if [ ! -f "$AUDIO_VIDEO" ]; then echo "Error: Audio video file '$AUDIO_VIDEO' does not exist." exit 1 fi # Extract the basename of the input video without extension BASENAME=$(basename "$INPUT_VIDEO" .mp4) # Construct the output filename OUTPUT_VIDEO="${BASENAME}_with_audio.mp4" # Use ffmpeg to combine the video and audio ffmpeg -i "$INPUT_VIDEO" -i "$AUDIO_VIDEO" -c copy -map 0:v:0 -map 1:a:0 "$OUTPUT_VIDEO" echo "Created '$OUTPUT_VIDEO' with video from '$INPUT_VIDEO' and audio from '$AUDIO_VIDEO'."