Skip to content

Commit

Permalink
add example video and the tests for bash-video
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-munsch committed Mar 29, 2024
1 parent 08fff07 commit 5259ba4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
23 changes: 17 additions & 6 deletions bash-video.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,35 @@ function join_videos() {
OUTPUT_FILE=$3
verify_file "$INPUT_FILE1"
verify_file "$INPUT_FILE2"
ffmpeg -i "concat:$INPUT_FILE1|$INPUT_FILE2" -c copy "$OUTPUT_FILE" || exit 1

# Create a temporary file to store the list of input files
TEMP_FILE=$(mktemp)
echo "file '$(realpath "$INPUT_FILE1")'" > "$TEMP_FILE"
echo "file '$(realpath "$INPUT_FILE2")'" >> "$TEMP_FILE"

# Use the concat demuxer with the temporary file
ffmpeg -f concat -safe 0 -i "$TEMP_FILE" -c copy -y "$(realpath "$OUTPUT_FILE")" || exit 1

# Remove the temporary file
rm "$TEMP_FILE"
}

# Change playback speed
function change_speed() {
INPUT_FILE=$1
SPEED_FACTOR=$2
OUTPUT_FILE=$3
verify_file "$INPUT_FILE"
ffmpeg -i "$INPUT_FILE" -filter:v "setpts=$SPEED_FACTOR*PTS" -filter:a "atempo=$SPEED_FACTOR" "$OUTPUT_FILE" || exit 1

RECIPROCAL_FACTOR=$(awk "BEGIN {print 1/$SPEED_FACTOR}")
ffmpeg -i "$INPUT_FILE" -filter:v "setpts=$RECIPROCAL_FACTOR*PTS" -filter:a "atempo=$SPEED_FACTOR" "$OUTPUT_FILE" || exit 1
}

# Optimize video to reduce size
function optimize_video() {
INPUT_FILE=$1
OUTPUT_FILE=$2
verify_file "$INPUT_FILE"
ffmpeg -i "$INPUT_FILE" -vcodec libx264 -crf 28 "$OUTPUT_FILE" || exit 1
ffmpeg -i "$INPUT_FILE" -vcodec libx264 -crf 32 -filter:v fps=15 -b:a 96k "$OUTPUT_FILE" || exit 1
}

# Remove a segment from the beginning of the video
Expand Down Expand Up @@ -122,7 +133,7 @@ function extract_audio() {
INPUT_FILE=$1
OUTPUT_FILE=$2
verify_file "$INPUT_FILE"
ffmpeg -i "$INPUT_FILE" -vn -acodec copy "$OUTPUT_FILE" || exit 1
ffmpeg -i "$INPUT_FILE" -vn -acodec libmp3lame -b:a 128k "$OUTPUT_FILE" || exit 1
}

# Add audio to video
Expand Down Expand Up @@ -169,7 +180,7 @@ function rotate_video() {
ffmpeg -i "$INPUT_FILE" -vf "$TRANSPOSE" "$OUTPUT_FILE" || exit 1
}

# Record screen
# Record screen, not sure if this works, i use obs studio
function record_screen() {
OUTPUT_FILE=$1
DURATION=$2
Expand Down
11 changes: 11 additions & 0 deletions subtitles.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1
00:00:00,000 --> 00:00:05,000
Hello, World!

2
00:00:05,000 --> 00:00:10,000
This is a simple subtitle example.

3
00:00:10,000 --> 00:00:13,000
Subtitles are displayed at the specified timestamps.
11 changes: 11 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
./bash-video.sh popright tests/test-1-2-3_14s.mp4 9 tests/popright.mp4
./bash-video.sh popleft tests/popright.mp4 2 tests/popleft.mp4
./bash-video.sh trim tests/test-1-2-3_14s.mp4 2 4 tests/trim.mp4
./bash-video.sh join tests/popleft.mp4 tests/trim.mp4 tests/join.mp4
./bash-video.sh speedup tests/test-1-2-3_14s.mp4 '4' tests/speedup.mp4
./bash-video.sh optimize tests/test-1-2-3_14s.mp4 tests/optimize.mp4
./bash-video.sh extractaudio tests/popleft.mp4 tests/audio.mp3
./bash-video.sh resize tests/test-1-2-3_14s.mp4 100 100 tests/resize-100-100.mp4
./bash-video.sh rotate tests/resize-100-100.mp4 90 tests/rotate-90.mp4
./bash-video.sh addsubtitle tests/test-1-2-3_14s.mp4 ./subtitles.srt tests/subtitle.mp4
./bash-video.sh filter tests/popleft.mp4 'hue=h=90:s=1:b=0.5' tests/filter.mp4
Binary file added tests/test-1-2-3_14s.mp4
Binary file not shown.

0 comments on commit 5259ba4

Please sign in to comment.