Update Timelapse Tuner script to support vertical video output
This commit is contained in:
parent
66beb6e7df
commit
656cc017e4
52
README.org
52
README.org
@ -2,18 +2,23 @@
|
||||
|
||||
[[https://gitlab.com/uploads/-/system/project/avatar/62789004/timelapse_tuner.png]]
|
||||
|
||||
Timelapse Tuner is a Bash script that automates the process of creating timelapse videos with randomly selected background music. It merges a timelapse video file with a randomly chosen audio file from the current directory, applying fade-in and fade-out effects to the audio for a polished result.
|
||||
Timelapse Tuner is a Bash script that automates the process of creating timelapse videos with randomly selected background music. It merges a timelapse video file with a randomly chosen audio file from the current directory, applying fade-in and fade-out effects to the audio for a polished result. It now supports both horizontal and vertical video output!
|
||||
|
||||
* Video Demo
|
||||
:PROPERTIES:
|
||||
:ID: 79d45ea3-780f-4cb7-adff-847580153cc6
|
||||
:ID: 7c97f6c4-0db4-4105-b4ba-24efa508b035
|
||||
:END:
|
||||
|
||||
[[https://www.youtube.com/watch?v=_zmkQXfcmow][Check out this quick demo of what Timelapse Tuner can do]] (Youtube)
|
||||
Check out this quick demo of what Timelapse Tuner can do:
|
||||
|
||||
#+BEGIN_EXPORT html
|
||||
<video src="demo.mp4" controls="controls" style="max-width: 730px;">
|
||||
</video>
|
||||
#+END_EXPORT
|
||||
|
||||
* Features
|
||||
:PROPERTIES:
|
||||
:ID: ed705d67-d8db-4a99-aeca-8ac19bd69041
|
||||
:ID: f0a43fa6-6a89-409e-a72b-83145dd70e0c
|
||||
:END:
|
||||
|
||||
- Merges a specified timelapse video file with a randomly selected MP3 audio file
|
||||
@ -21,11 +26,12 @@ Timelapse Tuner is a Bash script that automates the process of creating timelaps
|
||||
- Randomly selects a start point in the audio file to add variety
|
||||
- Supports custom input timelapse video and output file specification
|
||||
- Allows customization of fade duration
|
||||
- Provides option to convert horizontal videos to vertical format
|
||||
- Provides detailed logging of the merging process
|
||||
|
||||
* Prerequisites
|
||||
:PROPERTIES:
|
||||
:ID: 81e96c1f-1850-4542-a427-dab68da4be73
|
||||
:ID: f328ae90-484d-46ad-b626-035ffffde43b
|
||||
:END:
|
||||
|
||||
This script requires the following tools to be installed and available in your system PATH:
|
||||
@ -39,7 +45,7 @@ You will also need to provide your own MP3 files for background music. If you ne
|
||||
|
||||
* Installation
|
||||
:PROPERTIES:
|
||||
:ID: 1bd35147-fde9-4cff-b18c-7e6127ee0662
|
||||
:ID: bc85ae88-4d69-40f2-9ac7-22fd583d447c
|
||||
:END:
|
||||
|
||||
1. Clone this repository or download the script file:
|
||||
@ -57,36 +63,43 @@ You will also need to provide your own MP3 files for background music. If you ne
|
||||
|
||||
* Usage
|
||||
:PROPERTIES:
|
||||
:ID: a914277b-f210-417c-b687-b55e0539eb69
|
||||
:ID: 62ab58d1-3682-405f-a8ca-dc39fd8a0a1a
|
||||
:END:
|
||||
|
||||
Run the script with the following command:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
./tt --video <input_timelapse_video> --output <output_file> [--fade <fade_duration>]
|
||||
./tt --video <input_timelapse_video> --output <output_file> [--fade <fade_duration>] [--vertical]
|
||||
#+END_SRC
|
||||
|
||||
** Options:
|
||||
:PROPERTIES:
|
||||
:ID: 3538bb4d-e7bd-4871-80a5-25b802aa15d1
|
||||
:ID: 9afd9a28-f9bf-47f0-a154-ff51f72c67e8
|
||||
:END:
|
||||
|
||||
- =--video=: Specify the input timelapse video file (required)
|
||||
- =--output=: Specify the output MP4 file name (optional, default: output_video.mp4)
|
||||
- =--fade=: Specify the fade duration in seconds (optional, default: 2)
|
||||
- =--vertical=: Convert the video to vertical format (optional, default: horizontal)
|
||||
|
||||
** Example:
|
||||
** Examples:
|
||||
:PROPERTIES:
|
||||
:ID: 34ab92af-9a7e-42d8-8559-82bd877a442f
|
||||
:ID: 0b930521-693e-49de-af95-fc7004264b30
|
||||
:END:
|
||||
|
||||
For horizontal output (default):
|
||||
#+BEGIN_SRC sh
|
||||
./tt --video my_timelapse.mp4 --output final_timelapse.mp4 --fade 3
|
||||
#+END_SRC
|
||||
|
||||
For vertical output:
|
||||
#+BEGIN_SRC sh
|
||||
./tt --video my_timelapse.mp4 --output vertical_timelapse.mp4 --fade 3 --vertical
|
||||
#+END_SRC
|
||||
|
||||
* How It Works
|
||||
:PROPERTIES:
|
||||
:ID: 4cba4005-9974-4a7a-837f-ab3f4fcdf2e7
|
||||
:ID: fa647cfa-a442-4b44-a14b-e818600e4006
|
||||
:END:
|
||||
|
||||
1. The script checks for the required dependencies (FFmpeg, FFprobe, bc).
|
||||
@ -95,12 +108,13 @@ Run the script with the following command:
|
||||
4. The lengths of both the timelapse video and audio files are calculated.
|
||||
5. Fade-in and fade-out durations are set (default 2 seconds, customizable with --fade) for smooth audio transitions.
|
||||
6. A random start point in the audio file is selected to ensure variety in the background music.
|
||||
7. FFmpeg is used to merge the timelapse video with the selected portion of the audio, applying fade effects.
|
||||
8. The final timelapse video with background music is saved as an MP4 file.
|
||||
7. If the --vertical option is used, the video is scaled and cropped to 1080x1920 resolution.
|
||||
8. FFmpeg is used to merge the timelapse video with the selected portion of the audio, applying fade effects and any necessary format conversion.
|
||||
9. The final timelapse video with background music is saved as an MP4 file.
|
||||
|
||||
* Providing Background Music
|
||||
:PROPERTIES:
|
||||
:ID: 0d01337a-c391-4f24-b6f7-07e644d8d101
|
||||
:ID: c5dff28e-02b5-43af-9523-2387a1458882
|
||||
:END:
|
||||
|
||||
Timelapse Tuner requires MP3 files in the same directory as the script to use as background music. Before running the script, make sure to add your desired MP3 files to the project directory.
|
||||
@ -109,14 +123,14 @@ For royalty-free music options, we recommend visiting [[https://pixabay.com/musi
|
||||
|
||||
* Logging
|
||||
:PROPERTIES:
|
||||
:ID: cfb9f3e9-581b-440e-a703-232fc7fc3a4b
|
||||
:ID: 37ace425-c1c2-463b-a187-e44180b9c910
|
||||
:END:
|
||||
|
||||
The script provides detailed logging of each step in the process. Logs are printed to the console with timestamps, allowing you to follow the progress of your timelapse creation.
|
||||
|
||||
* Troubleshooting
|
||||
:PROPERTIES:
|
||||
:ID: 3181d824-595b-4222-b25f-b6db028e0bcc
|
||||
:ID: c48b9d34-8a23-41e7-92a5-d2f4ec705d9d
|
||||
:END:
|
||||
|
||||
If you encounter any issues:
|
||||
@ -128,14 +142,14 @@ If you encounter any issues:
|
||||
|
||||
* Contributing
|
||||
:PROPERTIES:
|
||||
:ID: bfb3160f-6b64-4743-9db9-23ce1b0ea748
|
||||
:ID: af49793f-f703-4842-aa4e-5daefbb31e99
|
||||
:END:
|
||||
|
||||
Contributions to improve Timelapse Tuner are welcome. Please feel free to submit a Merge Request with your enhancements.
|
||||
|
||||
* Acknowledgments
|
||||
:PROPERTIES:
|
||||
:ID: 58e07a75-cd65-4c1a-9f86-86c50eba9760
|
||||
:ID: e02fc533-869c-4835-a249-f6727c94351a
|
||||
:END:
|
||||
|
||||
- FFmpeg project for providing powerful multimedia processing tools.
|
||||
|
38
tt
38
tt
@ -17,7 +17,6 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
|
||||
# Function to check if a command exists
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
@ -25,11 +24,12 @@ command_exists() {
|
||||
|
||||
# Function to print usage information
|
||||
print_usage() {
|
||||
echo "Usage: $0 --video <video_file> --output <output_file> [--fade <fade_duration>]"
|
||||
echo "Usage: $0 --video <video_file> --output <output_file> [--fade <fade_duration>] [--vertical]"
|
||||
echo "Options:"
|
||||
echo " --video Specify the input video file"
|
||||
echo " --output Specify the output MP4 file name (default: output_video.mp4)"
|
||||
echo " --fade Specify the fade duration in seconds (default: 2)"
|
||||
echo " --video Specify the input video file"
|
||||
echo " --output Specify the output MP4 file name (default: output_video.mp4)"
|
||||
echo " --fade Specify the fade duration in seconds (default: 2)"
|
||||
echo " --vertical Convert the video to vertical format (default: horizontal)"
|
||||
}
|
||||
|
||||
# Function to log messages with timestamps
|
||||
@ -41,6 +41,7 @@ log_message() {
|
||||
video_file=""
|
||||
output_file="output_video.mp4"
|
||||
fade_duration=2
|
||||
vertical=false
|
||||
|
||||
# Parse command-line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
@ -57,6 +58,10 @@ while [[ $# -gt 0 ]]; do
|
||||
fade_duration="$2"
|
||||
shift 2
|
||||
;;
|
||||
--vertical)
|
||||
vertical=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
log_message "Error: Unknown option: $1"
|
||||
print_usage
|
||||
@ -135,17 +140,32 @@ else
|
||||
fi
|
||||
log_message "Random start time: $random_start seconds"
|
||||
|
||||
# Run ffmpeg with audio fade-in, fade-out, and random start
|
||||
# Prepare FFmpeg command
|
||||
ffmpeg_command="ffmpeg -loglevel error -stats -i \"$video_file\" -ss $random_start -i \"$audio_file\""
|
||||
|
||||
if $vertical; then
|
||||
log_message "Converting to vertical format..."
|
||||
ffmpeg_command+=" -filter_complex \"[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[v];[1:a]afade=t=in:st=0:d=$fade_duration,afade=t=out:st=$fade_out_start:d=$fade_duration[a]\""
|
||||
ffmpeg_command+=" -map \"[v]\" -map \"[a]\""
|
||||
else
|
||||
ffmpeg_command+=" -filter_complex \"[1:a]afade=t=in:st=0:d=$fade_duration,afade=t=out:st=$fade_out_start:d=$fade_duration[a]\""
|
||||
ffmpeg_command+=" -map 0:v -map \"[a]\""
|
||||
fi
|
||||
|
||||
ffmpeg_command+=" -c:v libx264 -c:a aac -shortest \"$output_file\""
|
||||
|
||||
# Run FFmpeg command
|
||||
log_message "Starting ffmpeg process..."
|
||||
ffmpeg -loglevel error -stats -i "$video_file" -ss "$random_start" -i "$audio_file" -filter_complex \
|
||||
"[1:a]afade=t=in:st=0:d=$fade_duration,afade=t=out:st=$fade_out_start:d=$fade_duration[a]" \
|
||||
-map 0:v -map "[a]" -c:v libx264 -c:a aac -shortest "$output_file"
|
||||
eval $ffmpeg_command
|
||||
|
||||
# Check if ffmpeg was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
log_message "ffmpeg process completed successfully"
|
||||
log_message "Merged $video_file with random audio: $audio_file"
|
||||
log_message "Audio starts at $random_start seconds, with fade-in/out effects"
|
||||
if $vertical; then
|
||||
log_message "Video converted to vertical format"
|
||||
fi
|
||||
log_message "Output saved as: $output_file"
|
||||
else
|
||||
log_message "Error: ffmpeg process failed"
|
||||
|
Loading…
x
Reference in New Issue
Block a user