I need to apply crossfade to the last X frames of a video with the first X frames in order to obtain a seamless loop, but making this for the necessary part of video.
Here's the answer for looping the entire video.
Currently what I have: (Whole video duration = 25. Cutted (result) part = 15 sec (from 5 to 20 sec pos). Transition = 1 sec.)
ffmpeg -i input.mp4 -ss 5 -to 20 -filter_complex
"[0]split[body][pre];
[pre]trim=duration=1,format=yuva420p,fade=d=1:alpha=1,setpts=PTS+( (15+(5-1)) /TB)[jt];
[body]trim=1,setpts=PTS-STARTPTS[main];
[main][jt]overlay" -c:v libx264 -preset veryslow -b:v 2500K output.mp4
In this case, everything works, but at the end of the resulting video, a piece from the original video is superimposed, which starts from 0 to 1 second, and not from 4 to 5 seconds of the original video, as it should be.
I read the official ffmpeg documentation, tried some actions on "start/end" parameters for "trim/fade" with changing of "setpts", but I always got just another batch of bugs.