[FFmpeg-user] Use concat filter with a fade

Cecil Westerhof Cecil at decebal.nl
Tue Jun 14 17:30:25 EEST 2022


Michael Koch <astroelectronic at t-online.de> writes:

> Am 14.06.2022 um 15:33 schrieb Cecil Westerhof via ffmpeg-user:
>> Michael Koch <astroelectronic at t-online.de> writes:
>>
>>> Am 14.06.2022 um 13:47 schrieb Cecil Westerhof via ffmpeg-user:
>>>> Sometimes I have to cut parts out of a video. I now use for this (bash on Debian):
>>>>       ffmpeg -y                                                \
>>>>              -ss ${videoStart} -to ${cutStart} -i ${inputFile} \
>>>>              -ss ${cutEnd}     -to ${videoEnd} -i ${inputFile} \
>>>>              -vcodec         libx264                           \
>>>>              -crf            26                                \
>>>>              -acodec         libmp3lame -qscale:a 9            \
>>>>              -preset         veryfast                          \
>>>>              -lavfi "concat=n=2:v=1:a=1"                       \
>>>>              -an ${outputFile}
>>>>
>>>> But the cut from one part to another is a bit abrupt. Is there a
>>>> possibility to smooth it with something like a fade?
>>> you can use the xfade filter. :
>>> https://www.ffmpeg.org/ffmpeg-all.html#xfade
>>> https://trac.ffmpeg.org/wiki/Xfade
>> I am now using:
>>      offset=$((${cutStart} - ${videoStart} - ${duration}))
>>      xfade=xfade=transition=slideleft:duration=${duration}:offset=${offset}
>>      time ffmpeg -y                                             \
>>            -ss ${videoStart} -to ${cutStart} -i ${inputFile}    \
>>            -ss ${cutEnd}     -to ${videoEnd} -i ${inputFile}    \
>>            -vcodec         libx264                              \
>>            -crf            26                                   \
>>            -acodec         libmp3lame -qscale:a 9               \
>>            -preset         veryfast                             \
>>            -filter_complex ${xfade}                             \
>>            ${outputFile}
>>
>> But I have a major and minor problem.
>> The major problem is that I do not have audio from the second part of
>> the video.
>
> Audio has its own filter: acrossfade

This seems to work:
    xfade="xfade=transition=slideleft:duration=${duration}:offset=${offset};acrossfade=d=${duration}"


>> The minor problem is that I have to calculate the offset. It would be
>> nice if I could use -duration, but that does not work sadly.
>
> As far as I know this isn't yet implemented.

That sounds like it is going to be implemented. Or do I read to much
in this sentence?


>> By the way: how should I do it when I want to use five parts of the video?
>
> I haven't tested this, but I think you must build a binary tree:
> [0:v][1:v]xfade[a];[2:v][3:v]xfade[b];[a][b]xfade

OK, at the moment it is needed I have a starting point.


Thanks.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the ffmpeg-user mailing list