1

How to fade out audio AND video in *.mp4 file? If I try code from this answer:

ffmpeg -i "c:/input.mp4" -filter:v 'fade=in:0:30,fade=out:227:30' -c:v libx264 -crf 22 -preset veryfast -c:a copy "c:/testsong.mp4"

I get:

[AVFilterGraph @ 000001e0f41affc0] No such filter:  fade=in:0:30,fade=out:227:30'
Error opening filters!

Complete output:

ffmpeg version N-86994-g92da230 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7.1.0 (GCC) configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib libavutil 55. 74.100 / 55. 74.100 libavcodec 57.102.100 / 57.102.100 libavformat 57. 76.100 / 57. 76.100 libavdevice 57. 7.100 / 57. 7.100 libavfilter 6. 99.100 / 6. 99.100 libswscale 4. 7.102 / 4. 7.102 libswresample 2. 8.100 / 2. 8.100 libpostproc 54. 6.100 / 54. 6.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 's:/dummy.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2016-08-24T16:42:38.000000Z Duration: 00:03:50.34, start: 0.000000, bitrate: 980 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 960x720 [SAR 1:1 DAR 4:3], 851 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: creation_time : 2016-08-24T16:42:38.000000Z handler_name : ISO Media file produced by xyz... Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: creation_time : 2016-08-24T16:42:38.000000Z handler_name : ISO Media file produced by xyz... Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [AVFilterGraph @ 0000000002d64580] No such filter: 'fade=in:0:30,fade=out:227:30' Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed!

What' wrong here? Thanks in advance!

2
  • 1
    Welcome! Please share the full console output, not just the one error. Aug 10, 2017 at 22:58
  • 1
    Update your ffmpeg version to a recent one.
    – slhck
    Aug 11, 2017 at 12:43

2 Answers 2

2

Fade both video & audio

First of all, the command you've provided won't achieve the desired effect: the fade filter only applies to a video stream, plus you specifically apply it to your input video stream with -filter:v.

To fade both audio and video, you'll need both afade and fade filters.

E.g.

ffmpeg -i input.mp4 -filter:v "fade=in:0:30, fade=out:1770:30" -filter:a "afade=in:0:44100, afade=out:2601900:44100" -c:v libx264 -c:a aac output.mp4

This command fades in and out the first and last 30 video frames and 44100 audio samples, on a 1800 frames-long and 2646000 samples-long video (which, if your framerate is 30 fps and samplerate 44100 Hz, will be the first and last second of your 60 seconds-long clip).

Working with frames and samples can be highly impractical, so to work with start and duration in seconds, use the st (start) and d (duration) parameters, like so :

ffmpeg -i input.mp4 -filter:v "fade=in:st=0:d=1, fade=out:st=59:d=1" -filter:a "afade=in:st=0:d=1, afade=out:st=59:d=1" -c:v libx264 -c:a aac output.mp4

(fades in and out first and last second of a 60s clip)

See afade and fade filters documentation for more details on parameters.

Alternatively, you can also use a complex filtergraph as suggested by Manul Hüttinger, which can be handy if you need to apply further filters to your clip:

ffmpeg -i input.mp4 -filter_complex \
  "fade=in:st=0:d=1, fade=out:st=59:d=1; \
   afade=in:st=0:d=1, afade=out:st=59:d=1" \
 -c:v libx264 -c:a aac output.mp4

Regarding your particular error

I'm not sure where your error comes from, but you should try the following:

  • First, update your ffmpeg: your libavfilter is in version 6.99.100, latest is at least 7.6.100
  • I guess you're on Windows, given the filepath and build number. Beware that you cannot use single quotes (') on Windows, you must use double-quotes ("). Looking at the console output, this might be the origin of your error:

[AVFilterGraph @ 0000000002d64580] No such filter: fade=in:0:30,fade=out:227:30'

  • Then, if it keeps failing, try with a different input (the error message might indicate an encoding/decoding error:

Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed

0

try -filter_complex "fade=t=in:st=0:d=30,fade=t=out:st=227:d=30"

1
  • 1
    Can you explain the how this will work compared to what the OP already tried? That will make this useful to others trying to solve similar problems. Sep 29, 2017 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.