[Cherry-pick 2.0.1] Properly set #samples passed to encoder (#3204) #3239
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Some audio encoders expect specific, exact number of samples described as in
AVCodecContext.frame_size
.The
AVFrame.nb_samples
is set for the frames passed toAVFilterGraph
, but frames coming out of the graph do not necessarily have the same numbr of frames.This causes issues with encoding OPUS (among others).
This commit fixes it by inserting
asetnsamples
to filter graph if a fixed number of samples is requested.Note:
It turned out that FFmpeg 4.1 has issue with OPUS encoding. It does not properly discard some sample. We should probably move the minimum required FFmpeg to 4.2, but I am not sure if we can enforce it via ABI. Work around will be to issue an warning if encoding OPUS with 4.1. (follow-up)
Pull Request resolved: #3204
Reviewed By: nateanl
Differential Revision: D44374668
Pulled By: mthrok
fbshipit-source-id: 10ef5333dc0677dfb83c8e40b78edd8ded1b21dc