-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmerge_videos.sh
More file actions
executable file
·74 lines (61 loc) · 1.99 KB
/
Copy pathmerge_videos.sh
File metadata and controls
executable file
·74 lines (61 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# Check if ffmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
echo "FFmpeg is not installed. Install it with:"
echo "nix-env -iA nixos.ffmpeg"
# Or add it to configuration.nix:
# environment.systemPackages = with pkgs; [ ffmpeg ];
exit 1
fi
# Create a temporary file for the list of videos
temp_file="videos_to_merge.txt"
# Remove any existing temp file
rm -f "$temp_file"
# Check if we have any input files
if [ "$#" -eq 0 ]; then
echo "Usage: $0 video1.webm video2.webm video3.webm"
exit 1
fi
# Check if input files exist and are WebM format
for file in "$@"; do
if [ ! -f "$file" ]; then
echo "Error: File $file does not exist"
exit 1
fi
# Check if file is WebM
mime_type=$(file -b --mime-type "$file")
if [[ "$mime_type" != "video/webm" ]]; then
echo "Warning: $file is not a WebM file (detected: $mime_type)"
echo "This might cause issues during merging"
fi
# Write file path to the temporary list
echo "file '$file'" >> "$temp_file"
done
output_file="merged_output.webm"
echo "Starting to merge videos..."
# Merge the videos using WebM format
# Using libvpx-vp9 for video and libopus for audio, which are commonly used in WebM
ffmpeg -f concat -safe 0 -i "$temp_file" \
-c:v copy -c:a copy \
-f webm \
"$output_file"
# Check if the merge was successful
if [ $? -eq 0 ]; then
echo "Videos have been successfully merged into $output_file"
else
echo "Error occurred during merging. Trying alternative method..."
# Alternative method with re-encoding if direct copy fails
ffmpeg -f concat -safe 0 -i "$temp_file" \
-c:v libvpx-vp9 -c:a libopus \
-b:v 2M -b:a 128k \
-f webm \
"$output_file"
if [ $? -eq 0 ]; then
echo "Videos have been successfully merged using re-encoding into $output_file"
else
echo "Error: Failed to merge videos"
exit 1
fi
fi
# Clean up the temporary file
rm -f "$temp_file"