-
Notifications
You must be signed in to change notification settings - Fork 33
Encoding: support wav, flac etc. #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -92,14 +92,13 @@ AudioEncoder::AudioEncoder( | |||
validateSampleRate(*avCodec, sampleRate); | |||
avCodecContext_->sample_rate = sampleRate; | |||
|
|||
// Note: This is the format of the **input** waveform. This doesn't determine | |||
// the output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original comment was wrong: that's not the format of the input waveform. It's the format of the input AVFrame that we pass to avcodec_send_frame()
. And it needs to be a format that the codec supports.
avCodecContext_->frame_size > 0, | ||
"frame_size is ", | ||
avCodecContext_->frame_size, | ||
". Cannot encode. This should probably never happen?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't always be non-zero, see below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting - it might be worth noting why from the docs (https://ffmpeg.org/doxygen/6.0/structAVCodecContext.html#aec57f0d859a6df8b479cd93ca3a44a33, which I admit to not understanding) when we turn 0 into our default.
# Check that decode(encode(samples)) == samples on lossless formats | ||
|
||
if get_ffmpeg_major_version() == 4 and output_format == "wav": | ||
pytest.skip("Swresample with FFmpeg 4 doesn't work on wav files") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, we're hitting this:
torchcodec/src/torchcodec/_core/FFMPEGCommon.cpp
Lines 159 to 166 in 12cdaa8
status = swr_init(swrContext); | |
TORCH_CHECK( | |
status == AVSUCCESS, | |
"Couldn't initialize SwrContext: ", | |
getFFMPEGErrorStringFromErrorCode(status), | |
". If the error says 'Invalid argument', it's likely that you are using " | |
"a buggy FFmpeg version. FFmpeg4 is known to fail here in some " | |
"valid scenarios. Try to upgrade FFmpeg?"); |
This PR adds support for encoding formats where the encoder doesn't natively support FLTP, which is the sample format of the input waveform. We use
swresample
to convert the input FLTP AVFrames into a sample format that the encoder support.