Make timelapses easily using FFmpeg
ffmpeg -framerate 30 -pattern_type glob -i '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
ffmpeg -framerate 30 -pattern_type glob -i '*.JPG' -c:v libx264 -r 30 -pix_fmt yuv420p timelapse.mp4
Unfortunately not all versions have "vidstab".
ffmpeg -i "$1" -vf vidstabdetect=shakiness=5:show=1 dummy.avi
ffmpeg -i "$1" -vf yadif, format=yuv420p, vidstabtransform=zoom=2:optzoom=0:crop=black -c:v libx264 -b:a 32k stabilized264.mp4
Yesterweek's shaky video shot from a kayak: https://youtu.be/4pM0VeH4NE0?si=H2qTJfcvis3QmFlj
brew install homebrew-ffmpeg/ffmpeg/ffmpeg $(brew options homebrew-ffmpeg/ffmpeg/ffmpeg --compact)
$ ffmpeg-english "capture video from the camera every 1 second and write it to jpg files"
$ ffmpeg-english "take all of the images ending with .jpg in this directory and make a 30fps timelapse of it"
Sound awesome? Here's the code for ffmpeg-english: #!/usr/bin/env python3
import openai
import sys
import os
import time
# Ensure you have set your OpenAI API key as an environment variable
openai.api_key = os.getenv("OPENAI_API_KEY")
client = openai.OpenAI()
def get_ffmpeg_command(task_description):
# Call the OpenAI API with the task description
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role":"system", "content":"You are an expert in FFmpeg commands. Given the following English description of a task, you respond with the correct FFmpeg command. Do not include any other information in your response except for the command only."},
{"role":"user", "content":task_description},
],
max_tokens=150,
temperature=0.5
)
command = response.choices[0].message.content.strip()
return command
def main():
if len(sys.argv) < 2:
print("Usage: ffmpeg-english <task_description>", file=sys.stderr)
sys.exit(1)
task_description = " ".join(sys.argv[1:])
ffmpeg_command = get_ffmpeg_command(task_description)
# some basic guardrails
assert(ffmpeg_command.startswith("ffmpeg"))
assert(";" not in ffmpeg_command)
assert("|" not in ffmpeg_command)
print(f"Executing command: {ffmpeg_command} in 2 seconds (^C to cancel)")
time.sleep(2)
os.system(ffmpeg_command)
if __name__ == "__main__":
main()And all without python dependency, or even internet access.
Sometimes it tries to align unrelated objects, but that is just funny.
Bash script running on a cron job every hour with:
DATE=$(date +"%Y%m%d%H%M")
raspistill -o /home/pi/timelapse/$DATE.jpg -awb off -awbg 1.8,1.6
Then another bash script running once a week: DATE=$(date +"%Y%m%d%H%M")
ffmpeg -framerate 12 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p -vf 'scale=1920:-2,crop=1920:1080:0:(in_h-1000)' 'timelapse-$DATE.mp4'
scp timelapse-$DATE.mp4 username@my.server:/home/user/
(Edited/simplified, I do a few other things in the scripts like compile the timelapse with pre-made timelapses and share via nginx on the Pi itself)I'm also working on a new one that uses an ASI533 Pro and a 4mm lens from a mirrorless camera to get better quality images.
Also as an FYI to everyone, FFmpeg does support nVidia GPU acceleration but it might not be enabled in your build. So check if you use it a lot.
http://fixounet.free.fr/avidemux/
Another is ShutterEncoder:
Worth a try!
Be aware that -pattern_type glob is not supported on Windows, though, iirc. A workaround is to name your jpegs with consecutive numbers (not necessarily starting at 0) and use a pattern with a counter placeholder in it instead.
Note of support: ffmpeg supported many of the transcoding needs of my former employer back in 2007, being a "friendly" tool to the team. Yes it had/s issue. Being open source gave us a lifeline, to be able to fix our own stuff, and build up our video and audio live streaming and video watching white label service.
> The sortedness of glob.glob's output is platform-dependent.
see https://trac.ffmpeg.org/wiki/Concatenate or https://shotstack.io/learn/use-ffmpeg-to-concatenate-video/
ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4 ffmpeg -t 5 -i example.mp4 -c:v libvpx-vp9 -b:v 2M -filter_complex "[0:v]chromakey=0x00ff00:0.3:0.2[out]" -map "[out]" -map 0:a stop.webm`
where `example.mp4` is a video with the typical green background.Maybe someone needs it :)
Also, an assumption in your command is that all the images are the same aspect ratio. If they’re not, you can use this to dynamically pad it out with black bars on either size:
‘-vf "scale=1920:1080:force_original_aspect_ratio=decrease:eval=frame,pad=1920:1080:-1:-1:eval=frame"’
I have a bunch of old videos that use MTS as the file extension. I would like to convert these to an MP4 (or MKV) file but I would like to do it while keeping the metadata (date taken, date created, etc.). Is there a way to do this?
The scripts I've seen change the file extension by just changing the container but they never keep the metadata which is a huge issue for me.
https://www.movieprint.org/ & https://github.com/fakob/MoviePrint_v004/
I press shift-s to take a snapshot, not sure if that's a default hotkey or I set it to that a long time ago.
In the preferences you choose where it will save to and what format.
Try encoding the video to AV1 with OPUS audio. You'll get ridiculous gainz!
My command is:
$ffmpegPath -i $_.FullName -r 23.976 -vf scale=1280:720 -c:v libsvtav1 -pix_fmt yuv420p10le -crf 30 -preset 10 -g 300 -c:a libopus -b:a 96k -ac 2 -c:s copy -map 0 $destPathNoise reduction, so you compress less useless noise: -vf hqdn3d
Turn up the Constant Rate Factor. This will make better visual tradeoffs than decreasing frame rate. 23 is a good starting point for h264, but keep increasing it until you don't like how the content looks: -crf 23
Throw more CPU at the problem: -preset veryslow
cat *.jpg | ffmpeg -r 90 -f image2pipe -i - -codec:v libx264 -preset fast -crf 23 -vf format=yuv420p video.mp4
I usually open them up in a new project just to create a lossless input video to work with in After Effects, and use that (if I use image sequence directly, DaVinci Resolve acts in weird ways).
ffmpeg might ease that AE part.
Ffmpeg can encode into ProRes, but it’s technically an unofficial implementation.
What issues do you run into with image sequences?
In DaVinci Resolve, many tools go awry with image sequences: for example temporal noise reduction simply doesn't work with a compound clip with image sequences, I also remember having problems with caching performance. I have a few very strange/buggy problems with Resolve though I love color grading with it regardless, so I want to avoid the buggy sides of Resolve (as it's one of the buggiest software I've ever used) but use the upsides of it (grading and some OpenFX filters).
It would help me on this process.
ffmpeg -framerate 30 -i image-%05d.jpg -c:v libx265 -crf 35 -pix_fmt yuv420p timelapse.mp4
Will get images of the form image-00000.jpg, image-00001.jpg, ... image-99999.jpg.Is that something ffmpeg could do?
Is there any good resource for recipes like these?
ffmpeg -ss 00:01:00 -i input.avi -t 30 -vf "fps=1,scale=320:-1:flags=lanczos" output_%04d.jpg
00:01:00 is where to start the flip book, 30 is thirty seconds worth, and 1 fps is how many frames per second. this'll make output_XX.jpg from the Avi which you can then print