Create endless loop animation using ffmpeg using only certain frames - loops

I can create an animated gif using the commands below.
ffmpeg -i wrist_0001.png -vf palettegen=16 palette.png
ffmpeg -i wrist_%04d.png -i palette.png -filter_complex "fps=20,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse" logo.gif
What I'm trying to know how to do is:
Create another animated gif using just the first 20 frames and the animation loops endlessly (no pausing at the end of the animation).
Create another animated gif using just the first 20 frames where the animation plays then pauses at the end for 3 seconds then continues. (endlessly) Example: (play animation - pause 3 seconds - play animation - pause 3 seconds - play animation - pause 3 seconds...)
Note: I'm trying to avoid having to type in wrist_0001.png wrist_0002.png...is there away to do wrist_0001.png to wrist_0020.png?

Create another animated gif using just the first 20 frames and the animation loops endlessly (no pausing at the end of the animation):
ffmpeg -framerate 20 -i wrist_%04d.png -filter_complex "scale=720:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=16[p];[s1][p]paletteuse" -frames:v 20 -loop 0 20framesloop.gif
When using a set of images as the input set the frame rate with the -framerate image demuxer input option. Your original command is defaulting to 25 fps and then using the fps filter to convert to 20 fps meaning frames are being dropped.
-loop 0 is the default for the GIF muxer, but I added it to show how it works if you want to change the looping. 0 means infinite loop.
This example makes the GIF in one command as shown in How do I convert a video to GIF using ffmpeg, with reasonable quality?
Create another animated gif using just the first 20 frames where the animation plays then pauses at the end for 3 seconds then continues. (endlessly)
Most efficient method is to re-mux the GIF from the previous step:
ffmpeg -i 20framesloop.gif -c copy -final_delay 300 -loop 0 3secpause.gif
-final_delay 300 takes a value in centiseconds, so 3 seconds is 300 centiseconds. See ffmpeg -h muxer=gif for more info.

Related

Getting an error 'too many inputs specified for the "scale" filter' in ffmpeg

I'm trying to add watermarks to multiple images using ffmpeg. It works good in the beginning but when I try to change the opacity of the watermark it shows the error as:
[AVFilterGraph # 0000019b2a655340] Too many inputs specified for the
"scale" filter. Error initializing complex filters. Invalid argument
The used code:
for %%a in ("*.jpg") do ffmpeg -i "%%a" -i wm.png -filter_complex "[1]lut=a=val*0.3[a];[0][a][1]scale=iw*0.50:-1[wm];[0][wm]overlay=0:0" -preset ultrafast "post\%%~na.jpg"
If I understand your intent correctly, change
[1]lut=a=val*0.3[a];[0][a][1]scale=iw*0.50:-1[wm];
to
[1]lut=a=val*0.3,scale=iw*0.50:-1[wm];
The watermarked can be scaled directly after the alpha change.

Compressed video:How to show B and P frames

I want to analyze a compressed video (h264).
I'm encoding using this command:
ffmpeg -i in_path -vf scale=340:256,setsar=1:1 -q:v 1 -c:v h264 -f
rawvideo out_path
now I want to see how the P&B frames look like, so I'm using this command in order extract only the b frames:
ffmpeg -ss 0 -i in_vid -t 2 -q:v 2 -vf
select="eq(pict_type\,PICT_TYPE_B)" -vsync 0 frameb%03d.jpg
The extraction went well, no errors, and the number of frames extracted makes since by theory.
But, I Don't know how to "show" the image, when I'm doing:
eog frameb001.jpg
I'm getting a normal picture and not what I expected from a B frame, now I understand why doing "eog" won't be good, but I have no idea how to "show" the frame so that it will be meaningful (saw some articles that use HSV to show the frame).
One more thing the fact that I got a meaningful image from the B frames, maybe the extraction wasn't good.
Any help will be great, Thanks a lot!

How seeking ffplay or pipe from ffmpeg to ffplay

my goal is to check the file 10 minutes after the start. This is my script.
ffplay.exe -f lavfi "amovie=input.mov,showvolume=b=4:w=640:h=96"
If I add seeking, something like -ss 600, the file always starts from the beginning,
anyone know workaround? thanks.
Two ways of doing this:
ffplay -f lavfi "amovie=input.mov:sp=600,showvolume=b=4:w=640:h=96"
sp is option seek_point - will seek from nearest keyframe before seek point.
ffplay -f lavfi "amovie=input.mov,atrim=600,showvolume=b=4:w=640:h=96"
Apply a (a)trim filter.

Is there a way to stop recording screen with Byzanz?

I use tool called byzanz to record my screen and create gif files.
This is the way I use it:
byzanz-record -d 55 --delay=2 -x 0 -y 0 -w 3940 -h 950 desktop-animation.gif
However, often I can't tell in advance how long the recording will be so it ends up with awkward moments at the end or prematurely ending the recording. Is there a way how to tell byzanz to stop its job, perhaps by sending a signal to it with kill or something?
There seems to be an option that could achieve that :
http://manpages.ubuntu.com/manpages/zesty/man1/byzanz-record.1.html
-e, --exec=COMMAND
Instead of specifying the duration of the animation, execute the
given COMMAND and record until the command exits. This is useful
both for benchmarking and to use more complex ways to stop the
recording, like writing scripts that listen on dbus.
However, in my package manager with the latest byzanz (fedora), --exec doesn't exist.
I think with that option, you could do :
byzanz-record --exec 'sleep 1000000' --delay=2 -x 0 -y 0 -w 3940 -h 950 desktop-animation.gif
and when you want to stop the recording, do : killall sleep
Sidenote: I have opened an issue on redhat bugzilla tracker to update their byzanz-record version : https://bugzilla.redhat.com/show_bug.cgi?id=1531055

How to get time conversion using FFmpeg

I have tried extracting video.mpg to images using FFmpeg command line and it works fine, but I want get time of the conversion process that will be taken till video.mpg is extracted, and save to Time.txt.
This is what I have tried so far:
ffmpeg -i video.mpg image%d.jpg>>time.txt
Where I have been wrong?
ffmpeg outputs the progress messages to stderr, so to redirect it to a file use 2>>time.txt:
ffmpeg -i video.mpg image%d.jpg 2>>time.txt
More info: http://ss64.com/nt/syntax-redirection.html
P.S. in batch-files % should be doubled: ffmpeg -i video.mpg image%%d.jpg 2>>time.txt

Resources