Why are screenshots taken with ffmpeg uneven in time? - ffmpeg

I'm using the following ffmpeg command to take screenshots every 5 seconds of a video file that is 85 seconds long:
ffmpeg -i out2.mp4 -vf fps=1/05 img%03d.jpg
I get 18 files When I look at the resulting screenshots, they are 5 seconds apart, but the first frame starts around 3 seconds, the second is then 8 seconds, and so on. How do I get it to start with the very first frame, and then go 5 seconds apart on subsequent frames?

You're the using the fps function, whose primary use is to change the framerate, not select specific frames. When using it to reduce framerate, it uses a regular cadence to retain frames. For 1/5, that's the middle frame in a 5-second segment.
Use the select filter.
ffmpeg -i out2.mp4 -vf select='lte(mod(t,5),0.01)' -vsync 0 img%03d.jpg

Related

Segmenting a video live stream into videos of a fixed length using ffmpeg

I want to use an ffmpeg command to save segments of length 10 seconds from a video being streamed via HTTP using VLC.
The command I used to carry out the task is:
ffmpeg -i http://[Local IPv4 address]:8080 -f segment -segment_time 10 -vcodec copy -acodec copy -reset_timestamps 1 video%03d.mp4
However, the lengths of the output videos I'm receiving are around 8.333 or 16.666 seconds in duration. (The videos video000.mp4, video005.mp4, video010.mp4, video015.mp4... have duration of around 16.666 seconds and the remaining videos have duration of around 8.333 seconds).
I'm aware that the segmentation of input video happens based on the occurrences of keyframes in the video. It appears that the key frames in the video being streamed occur with an interval of around 8 seconds.
Is there a way to obtain video segments that are closer to 10 seconds in duration from the live stream of such a video?
Also, I occasionally get the "Non-monotonous DTS in output stream 0:0" warning while executing the above command. I tried using different flags (+genpts, +igndts, +ignidx) hoping that the warning message would not be displayed, but no luck. Is it possible that there is any correlation between this warning and the issue with lengths of the segments?

ffpmeg extracting frames produces too many images

I'm using FFMpeg to extract some png files from a video using the following command:
ffmpeg -i FILE.mp4 -vf "select=not(mod(n\,75))" -vsync vfr img_%03d.png
the source video has a duration of 2898 seconds and a framerate of 25 FPS. This means I should be grabbing a picture every 3 seconds for 966 pictures.
However, instead I'm getting 1158 pictures. After doing some math I've discovered that that is the within 2 pictures of what I would expect if I was grabbing the 75th frame from a 30 FPS video.
I've tried -framerate=25 but it still produces the same amount of pictures. The video does have a variable framerate, however using ffprobe it says that the max FPS is 25.47. So even if it was at the max FPS the whole video then I'd still only expect to see 984 pictures.
Is there anyway to tell FFMpeg that my source video is only 25 fps? Or am I missing something obvious?

FFmpeg how to extract time fragments of exact duration at set intervals?

I have a video file, I know how to extract segments with ffmpeg and setting the keyframes to do so exact.
However, I would like to extract a segment of a certain duration, say 1 minute, then wait 50 seconds, again segment 1 minute, wait 50 seconds, again segment 1 minute, etc. until the end of the video file.
How can I accomplish this?
Is it possible to use a list.txt as cut input?
Let's call your segment duration X and interval between end of one segment and start of another Y. Both in seconds. Use
ffmpeg -i in.mp4 -vf select='lt(mod(t,X+Y),X)',setpts=N/FRAME_RATE/TB -force_key_frames expr:gte(t,n_forced*X) -f segment -segment_time X out%d.ts
You may want to add -reset_timestamps 1 for zero-start timestamps for each segment. Audio is ignored and will be out of sync if present. Add a corresponding audio filter with aselect/asetpts to cut audio in sync.

FFMPEG - convert into variable framerate by removing duplicate frames

I have slideshow video (i.e. 10GB) 1080p quality (30 FPS), and each image lasts about 15 seconds ...
Is there any option with FFMPEG, to convert those 15 seconds periods from 30 FPS(because they are just duplicate frames) into i.e. 1 fps, thus, making the video small size...
the only periods that should keep original FPS is the fadeout period from image to image (that lasts 3 seconds... they are not duplicate frames, each frame is different because of fade-out effect).
You just need to re-encode with ffmpeg using a mid CRF value, like between 24-27. I-frames will be smaller but mainly P-frames which are static will only take few dozen bytes to store. Actually decimating the static frames and keeping the fade sequences at full FPS can be done but will be cumbersome and subject to trial and error. Just doing a simple re-encode will get you most of the size savings you would have gotten
Basic command is
ffmpeg -i in.mp4 -crf 25 -c:a copy out.mp4

Create thumbnails tile for time range of video

I need to create, let's say, 12 thumbnails from video, but skip 10 percent in the beginning and in the ending. I found this thing, but it just takes every 1000th frame. In my case this range will be variable and it will be better if it will be in seconds. Can't figure out how to do this with ffmpeg, don't work with it much.
ffmpeg -ss $skip_time -i $input_path -vframes 1 -vf select=isnan(prev_selected_t)+gte(t-prev_selected_t\,$screenshot_time), scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih),pad=($width):($height):($width-iw)/2):($height-ih)/2),tile=3x4 -vcodec mjpeg $output_filename
$skip_time - time to skip from the beginning
$screenshot_time - time interval for screenshots to be taken
These values should be precalculated, I used ffprobe to get video duration.

Resources