Is there any tool or script for batch converting animated webp images?
I want to create animated thumbnails from my animated webp images:
resize image size
reduce quality (lossy compression)
reduce frame rate
I tried tools like ImageMagick, but they cannot change the frame rate.
If you just want to change the framerate, the webpmux tool from Google (available as the webp package on your Linux OS) can do the job quickly and easily.
First you need to know the current duration interval for the source file - there are several ways to do that, but the webpinfo from the same package is maybe the easiest - webpinfo source.webp the note the duration listed for the frames.
Then calculate your new desired frame rate - if the source animation had an FPS of 10, it would show a duration of 100. To change it to 25, divide 100ms duration by 2.5 (the multiplier to go from 10 to 25), which will get you a target duration of 40ms.
Finally run webpmux -duration 40 source.webp -o destination.webp to create a copy of the source animation with a changed interhframe duration.
ffmpeg can't decode animated WebP
See #4907: Support decoding animated WebP images.
Use another tool, such as anim_dump, to extract the WebP frames. See How can I convert an animated WebP to a WebM? for more info and examples.
Once you have the frames you can use ffmpeg.
Example
10 fps, half size:
ffmpeg -framerate 25 -i input_%03d.webp -vf "fps=10,scale=iw/2:-1" -quality 25 output.webp
To encode WebP, ffmpeg must be compiled with --enable-libwebp.
resize image size
Use the scale filter.
reduce quality (lossy compression)
Use the -quality option for the encoder libwebp. Range is 0-100. Default is 75.
Optionally, use the -preset option to match the content type.
See ffmpeg -h encoder=libwebp for more options and info.
reduce frame rate
Use the fps filter or the -r option.
Related
I have a set of transparent images, where each one represents a frame of a video. I know that I can overlay them on top of another video using -i %d.png. What I want to be able to do is turn them into a transparent video ahead of time, and then later be able to overlay that transparent video onto another video. I've tried just doing -i %d.png trans.mov and then overlaying trans.mov on top of another video, but it doesn't seem like trans.mov is actually transparent.
You have to use an encoder that supports transparency/alpha channel. You can view a list of encoders with ffmpeg -h encoders and get further details with ffmpeg -h encoder=<encoder name>, such as ffmpeg -h encoder=qtrle. Then refer to the Supported pixel formats line: if has as "a" in the supported pixel format name, such as rgba, then it supports alpha. See a general list of pixel formats with ffmpeg -pix_fmts.
The simplest solution is to mux the PNG files into MOV:
ffmpeg -framerate 25 -i %d.png -c copy output.mov
I have to create 'preview' on video progress hover. I'm doing with a sprite image and WebVTT file. Using ffmpeg and imagemagick. However generating thumbnails from a mp4 video is really damn slow (20-30 minutes for 2hrs and 20 min long video). The video is Full HD, H246 encoded, 2GB big. The command used
"ffmpeg.exe -i largevideo.mp4 -f image2 -bt 20M -vf fps=1/5 thumbs-%03d.jpg"
Which means thumb for every 5 secs of the video. Is there a way to make it faster? Videos in prod can be even bigger.
OS: Win10, ImageMagick is used later to create the sprite from all the thumbnails created with ffmpeg.
Skip everything except keyframes:
ffmpeg -skip_frame nokey -i input.mp4 -vsync passthrough thumbs-%03d.jpg
Also see:
Get keyframe intervals
Control JPG quality
Have adapted FFmpeg sample muxing.c under Windows 7 to write MP4 files from video camera RGB data.
Using muxing.c default bit_rate=400000.
Am not setting global_quality.
Resultant MP4 is poor quality, highly pixelated.
Original raw images in video camera are sharp.
What values should I use for bit_rate? Do I have to also set rc_max_rate?
What values should I use for global_quality? Do I have to set any flags to enable use of global_quality?
Is bit_rate versus global_quality an either/or situation? Or can both be useful in adjusting quality?
Thanks for your time.
I have some images that were taken from a video via screen capture. I would like to know when in the video these images appear (timestamps). Is there a way to programmatically match an image with a specific frame in a video using ffmpeg or some other tool?
I am very open to different technologies as I'm eager to automate this. It would be extremely time consuming to do this manually.
You can get the psnr between that image and each frame in the video, and the match is the frame with the highest psnr. ffmpeg has a tool to calculate the psnr in tests/tiny_psnr which you can use to script this together, or there's also a psnr filter in the libavfilter module in ffmpeg if you prefer to code rather than script.
Scripting, you'd basically decode the video to a FIFO, decode the image to a file, and then match the FIFO frames repeatedly against the image file using tiny_psnr, selecting the framenumber for the frame with highest psnr. The output will be a frame-number, which (using fps output on the commandline) you can approximately convert to a timestamp.
Programming-wise, you'd decode the the video and image to AVFrame, use the psnr filter to compare the two, and then look at the output frame metadata to record the psnr value in your program, and search for the frame with the highest metadata psnr value, and for that frame, AVFrame->pkt_pts would be the timestamp.
I am looking for some tool or program to automatically grab snapshots (a few mins interval) from a video file without display it for me. Mkv support would be nice!
From the ffmpeg manual page http://ffmpeg.org/ffmpeg.html :
For extracting images from a video:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg
This will extract one video frame per second from the video and will output them in files named ‘foo-001.jpeg’, ‘foo-002.jpeg’, etc. Images will be rescaled to fit the new WxH values.
There are other options for extracting images depending on frame position or time, etc.