diff options
| author | BardofSprites <[email protected]> | 2025-07-31 14:44:22 -0400 |
|---|---|---|
| committer | BardofSprites <[email protected]> | 2025-07-31 14:44:22 -0400 |
| commit | 14ead75d64c366222c003fe90291b88dd587cae8 (patch) | |
| tree | 530f17fb489d32c8e3f525370868462915270fd8 /bin/.local | |
| parent | c394442a08e5c46d0fa3b3ec55914adfb5660aa2 (diff) | |
add simple music to video
Diffstat (limited to 'bin/.local')
| -rwxr-xr-x | bin/.local/bin/scripts/video-editing/bg_music | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/.local/bin/scripts/video-editing/bg_music b/bin/.local/bin/scripts/video-editing/bg_music new file mode 100755 index 0000000..bf85afa --- /dev/null +++ b/bin/.local/bin/scripts/video-editing/bg_music @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# Get input arguments or die with usage message +my $video_file = $ARGV[0] or die "Usage: ./bg_music video.mp4 music.mp3 [volume] output.mp4\n"; +my $audio_file = $ARGV[1] or die "Usage: ./bg_music video.mp4 music.mp3 [volume] output.mp4\n"; +my $volume = (defined $ARGV[2] && $ARGV[2] =~ /^\d*\.?\d+$/) ? $ARGV[2] : 0.5; +my $video_output = $ARGV[3] || $ARGV[2]; # Handles case where volume is skipped + +# Fix usage message if output filename is still missing +die "Usage: ./bg_music video.mp4 music.mp3 [volume] output.mp4\n" unless defined $video_output && $video_output ne $volume; + +# Build the FFmpeg command +my $ffmpeg_command = "ffmpeg -i \"$video_file\" -i \"$audio_file\" " . + "-filter_complex \"[1:a]volume=${volume}[a1];[0:a][a1]amix=inputs=2:duration=first:dropout_transition=2[a]\" " . + "-map 0:v -map \"[a]\" -c:v copy -c:a aac \"$video_output\""; + +# Run the command +system($ffmpeg_command) == 0 + or die "Failed to run ffmpeg: $!"; |
