Opened 7 years ago

Closed 7 years ago

#4919 closed defect (fixed)

afade filter misses first frame to be filtered

Reported by: ezran Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no


The afade audio filter can skip filtering the first frame it should be applied to, when fading out.

Cause: In filter_frame for the afade filter, when calculating whether the current frame includes part of a fade-out, the number of samples to fade is used rather than the number of samples in the frame. This can let the frame pass through unfiltered even when it should have the fade applied. Then at the beginning of the next frame, the fade starts mid-way through.

How to reproduce:

Generate loud 5-second sine wave at 44100 Hz to test with:
$ ffmpeg -f lavfi -i "sine=duration=5" -af volume=7 sine.wav

Apply fade-out with a duration of 1000 samples, starting at sample 216388:
ffmpeg -i sine.wav -af afade=t=out:ss=216388:ns=1000 out.wav

Because the audio frames are 4096 samples long, the fade will actually be applied starting at sample 217088 (which is 700 samples late), with a sudden drop in volume, and then will continue to fade out over the following 300 samples.

This issue occurs in latest master, and appears to have existed since the afade filter was introduced.

Full log of filter run (no errors evident from log):

$ ffmpeg -i sine.wav -af afade=t=out:ss=216388:ns=1000 out.wav
ffmpeg version N-75841-g5911eeb Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-3)
  configuration: --prefix=/usr --shlibdir=/usr/lib64 --libdir=/usr/lib64 --incdir=/usr/include --bindir=/usr/bin --datadir=/usr/share/ffmpeg --mandir=/usr/share/man
  libavutil      55.  2.100 / 55.  2.100
  libavcodec     57.  4.100 / 57.  4.100
  libavformat    57.  3.100 / 57.  3.100
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 10.100 /  6. 10.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.100 /  2.  0.100
Guessed Channel Layout for  Input Stream #0.0 : mono
Input #0, wav, from 'sine.wav':
    encoder         : Lavf57.3.100
  Duration: 00:00:05.00, bitrate: 705 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s
Output #0, wav, to 'out.wav':
    ISFT            : Lavf57.3.100
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
      encoder         : Lavc57.4.100 pcm_s16le
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
size=     431kB time=00:00:05.00 bitrate= 705.7kbits/s    
video:0kB audio:431kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.017687%

Attachments (2)

fade_1000_at_216388_before.png (7.0 KB ) - added by ezran 7 years ago.
Waveform showing bad fade out
fade_1000_at_216388_after.png (7.3 KB ) - added by ezran 7 years ago.
Waveform showing correct fade out (after patch is applied)

Download all attachments as: .zip

Change History (3)

by ezran, 7 years ago

Waveform showing bad fade out

by ezran, 7 years ago

Waveform showing correct fade out (after patch is applied)

comment:1 by Elon Musk, 7 years ago

Reproduced by developer: set
Resolution: fixed
Status: newclosed
Version: unspecifiedgit-master

Fixed in 9c168f9a2240

Note: See TracTickets for help on using tickets.