Creating product videos for Etsy can be challenging, especially when dealing with static items like canvas prints. My initial approach involved using Placeit, but I no longer have access to that service. I needed a solution to convert a folder of canvas print mock-ups into a video, no more than 59 seconds long, with smooth transitions between images. This blog details my second attempt at achieving this with the help of ChatGPT.
The Challenge
Etsy recommends posting a video of products to enhance listings and attract more buyers. However, creating engaging videos for static products like canvas prints can be tricky. I wanted a way to automate this process using my macOS computer, ensuring each image transitioned smoothly into the next with fading effects. Additionally, the video needed to be concise, adhering to Etsy’s maximum length requirement of 60 seconds.
Initial Attempts
1.Manual Creation with iMovie:
•Process: I used iMovie to manually import images, set durations, and add transitions.
•Outcome: While iMovie is user-friendly, it required too much manual effort and was not scalable for a large number of images or frequent updates.
2.Exploring Automation:
•Goal: Automate the video creation process to save time and ensure consistency.
•Tool: ffmpeg, a powerful command-line tool for handling video, audio, and other multimedia files and streams, was recommended by ChatGPT.
The Solution
ChatGPT provided guidance on creating a Bash script using ffmpeg to automate the process. The script needed to:
•Convert a folder of images into a video.
•Add fading transitions between images.
•Limit the total video duration to 60 seconds.
The Bash Script
Here’s the script that achieved these requirements:
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 path_to_image_folder"
exit 1
fi
# Directory containing images
IMG_DIR="$1"
# Check if the provided argument is a directory
if [ ! -d "$IMG_DIR" ]; then
echo "Error: $IMG_DIR is not a directory."
exit 1
fi
# Output video file
OUTPUT_VIDEO="$IMG_DIR/output_video.mp4"
# Create a temporary directory for intermediate files
TEMP_DIR=$(mktemp -d)
# Create intermediate video files with fades
COUNT=1
for img in "$IMG_DIR"/*.jpeg; do
if [ -f "$img" ]; then
ffmpeg -y -loop 1 -i "$img" -vf "fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5" -t 3 -pix_fmt yuv420p "$TEMP_DIR/temp-$(printf "%05d" $COUNT).mp4"
COUNT=$((COUNT + 1))
fi
done
# Create a file list for concatenation
CONCAT_LIST="$TEMP_DIR/concat_list.txt"
for video in "$TEMP_DIR"/temp-*.mp4; do
echo "file '$video'" >> "$CONCAT_LIST"
done
# Concatenate the intermediate video files into the final output
ffmpeg -y -f concat -safe 0 -i "$CONCAT_LIST" -c copy "$OUTPUT_VIDEO"
# Get the duration of the concatenated video
DURATION=$(ffprobe -i "$OUTPUT_VIDEO" -show_entries format=duration -v quiet -of csv="p=0")
# Trim the video to 1 minute if it exceeds 60 seconds
if (( $(echo "$DURATION > 60" | bc -l) )); then
ffmpeg -y -i "$OUTPUT_VIDEO" -t 60 -c copy "${OUTPUT_VIDEO%.mp4}_trimmed.mp4"
mv "${OUTPUT_VIDEO%.mp4}_trimmed.mp4" "$OUTPUT_VIDEO"
fi
# Cleanup
rm -r "$TEMP_DIR"
echo "Video created: $OUTPUT_VIDEO"
Execution Steps
To use the script, follow these steps:
1.Make the script executable
chmod +x create_video.sh
2.Run the script with the folder containing images:
./create_video.sh path_to_your_picture_folder
Errors and Challenges
Throughout the process, several errors and challenges were encountered:
•Image Detection Issues: The script did not correctly detect all image files initially. Ensuring the proper file format and path handling was crucial.
•Black Screens and Dark Images: Incorrect filter order and settings led to black screens and dark images. Adjusting the ffmpeg filters resolved this.
•Duration Limit: The video needed to be trimmed to ensure it did not exceed 1 minute. This was managed by checking the video duration and trimming if necessary.
Detailed Walkthrough of the Script
Step 1: Argument Checking
The script starts by checking if exactly one argument (the folder path) is provided. This ensures that the user provides the necessary input.
Step 2: Directory Validation
It confirms that the provided argument is a valid directory. This is crucial to avoid errors during file operations.
Step 3: Temporary Directory Creation
A temporary directory is created to store intermediate video files. This helps keep the workspace organised and prevents clutter in the main image directory.
Step 4: Generate Intermediate Videos
The script loops through each image in the directory, creating a short video clip with fade-in and fade-out effects. Each image is displayed for a total of 3 seconds.
Step 5: Create a File List for Concatenation
A file list is generated for ffmpeg to concatenate the individual video clips into a single output video. This list is essential for the ffmpeg concatenation process.
Step 6: Concatenate Videos
The intermediate video files are concatenated into a single output video, merging all the individual clips into one cohesive video.
Step 7: Get Video Duration
The script uses ffprobe to get the duration of the concatenated video. This is necessary to ensure the final video does not exceed 60 seconds.
Step 8: Trim the Video if Necessary
If the video duration exceeds 60 seconds, the script trims it to meet Etsy’s requirements. This step ensures the final product is within the acceptable time limit.
Step 9: Cleanup
The temporary directory and its contents are deleted to clean up the workspace. This step is essential to prevent clutter and maintain a tidy working environment.
Benefits of the Automated Approach
1. Efficiency:
•The script automates the repetitive task of creating videos, saving significant time.
•This allows me to create videos for new products or update existing ones quickly.
2. Consistency:
•Ensures uniform duration and transitions for all images, providing a professional look.
•Reduces the chances of human error in manual video creation.
3. Cost-Effective:
•Utilises free tools available on macOS, eliminating the need for paid services.
•ffmpeg is a powerful and versatile tool that can handle various multimedia tasks.
Conclusion
This automation process streamlined my workflow, enabling me to efficiently create professional product videos for my Etsy shop. The use of ffmpeg and a simple Bash script, guided by ChatGPT, proved to be an effective solution. If you have similar needs, I hope this guide helps you optimise your workflow, too!
Future Improvements
While the current solution works well, there are potential improvements and additional features that could enhance the workflow further:
1. Enhanced Effects:
•Adding more complex transitions or animations between images.
•Incorporating background music or voiceovers.
2. User Interface:
•Developing a simple graphical user interface (GUI) for non-technical users.
•Allowing users to customise transition effects and durations easily.
3. Integration:
•Integrating with cloud storage services to automatically fetch images.
•Automating the upload process to Etsy directly from the script.
4. Advanced Editing Features:
•Adding text overlays or captions to images.
•Using more sophisticated video editing techniques to enhance visual appeal.
5. Batch Processing:
•Enhancing the script to handle multiple folders or projects simultaneously.
•Implementing batch processing to create multiple videos in one go.
6. Cross-Platform Compatibility:
•Modifying the script to work on other operating systems like Windows and Linux.
•Ensuring the solution is accessible to a broader audience regardless of their preferred platform.
Feel free to reach out if you have any questions. Happy creating!