I need to create a really long video from a looping clip but it needs to fade in at the beginning and fade out at the end. I'm taking the looping segment and using this command:
ffmpeg -stream_loop 128 -i "{input}" -y -c copy "{output_looped}"
followed by:
ffmpeg -i "{output_looped}" -y -vf "fade=t=in:st=0:d=4,fade=t=out:st=1920:d=4" -c:a copy "{output}"
input file and ffmpeg info:
ffmpeg -i input.mp4ffmpeg version N-94150-g231d0c819f Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.1.1 (GCC) 20190621 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 30.100 / 56. 30.100 libavcodec 58. 53.101 / 58. 53.101 libavformat 58. 28.101 / 58. 28.101 libavdevice 58. 7.100 / 58. 7.100 libavfilter 7. 55.100 / 7. 55.100 libswscale 5. 4.101 / 5. 4.101 libswresample 3. 4.100 / 3. 4.100 libpostproc 55. 4.100 / 55. 4.100Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42mp41 creation_time : 2020-09-08T22:05:04.000000Z Duration: 00:00:13.96, start: 0.000000, bitrate: 24636 kb/s Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 24626 kb/s, 24 fps, 24 tbr, 24k tbn, 48 tbc (default) Metadata: creation_time : 2020-09-08T22:05:04.000000Z handler_name : ?Mainconcept Video Media Handler encoder : AVC Coding
However, this is extremely slow because the looped segment is so long and ffmpeg is (presumably) re-encoding it. It would be ideal if I could add the fade out to the beginning and the end of the video without re-encoding the middle section. So perhaps splitting output_looped
into 3 sections, applying the fade in to the beginning, leaving the middle the same, and applying the fade out to the end, and then concatenating the streams back together somehow.
Is this possible in ffmpeg? If so, how would you do it? Or is there any other way to avoid re-encoding the middle section while applying a fade in to the beginning and a fade out to the end?