File tree Expand file tree Collapse file tree 4 files changed +12
-35
lines changed
Expand file tree Collapse file tree 4 files changed +12
-35
lines changed Original file line number Diff line number Diff line change @@ -116,16 +116,17 @@ void setChannelLayout(
116116#endif
117117}
118118
119- SwrContext* allocateSwrContext (
119+ SwrContext* createSwrContext (
120120 UniqueAVCodecContext& avCodecContext,
121121 AVSampleFormat sourceSampleFormat,
122122 AVSampleFormat desiredSampleFormat,
123123 int sourceSampleRate,
124124 int desiredSampleRate) {
125125 SwrContext* swrContext = nullptr ;
126+ int status = AVSUCCESS;
126127#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
127128 AVChannelLayout layout = avCodecContext->ch_layout ;
128- auto status = swr_alloc_set_opts2 (
129+ status = swr_alloc_set_opts2 (
129130 &swrContext,
130131 &layout,
131132 desiredSampleFormat,
@@ -155,6 +156,14 @@ SwrContext* allocateSwrContext(
155156#endif
156157
157158 TORCH_CHECK (swrContext != nullptr , " Couldn't create swrContext" );
159+ status = swr_init (swrContext);
160+ TORCH_CHECK (
161+ status == AVSUCCESS,
162+ " Couldn't initialize SwrContext: " ,
163+ getFFMPEGErrorStringFromErrorCode (status),
164+ " . If the error says 'Invalid argument', it's likely that you are using "
165+ " a buggy FFmpeg version. FFmpeg4 is known to fail here in some "
166+ " valid scenarios. Try to upgrade FFmpeg?" );
158167 return swrContext;
159168}
160169
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ void setChannelLayout(
158158void setChannelLayout (
159159 UniqueAVFrame& dstAVFrame,
160160 const UniqueAVFrame& srcAVFrame);
161- SwrContext* allocateSwrContext (
161+ SwrContext* createSwrContext (
162162 UniqueAVCodecContext& avCodecContext,
163163 AVSampleFormat sourceSampleFormat,
164164 AVSampleFormat desiredSampleFormat,
Original file line number Diff line number Diff line change @@ -1735,31 +1735,6 @@ void SingleStreamDecoder::createSwsContext(
17351735 streamInfo.swsContext .reset (swsContext);
17361736}
17371737
1738- SwrContext* SingleStreamDecoder::createSwrContext (
1739- UniqueAVCodecContext& avCodecContext,
1740- AVSampleFormat sourceSampleFormat,
1741- AVSampleFormat desiredSampleFormat,
1742- int sourceSampleRate,
1743- int desiredSampleRate) {
1744- auto swrContext = allocateSwrContext (
1745- avCodecContext,
1746- sourceSampleFormat,
1747- desiredSampleFormat,
1748- sourceSampleRate,
1749- desiredSampleRate);
1750-
1751- auto status = swr_init (swrContext);
1752- TORCH_CHECK (
1753- status == AVSUCCESS,
1754- " Couldn't initialize SwrContext: " ,
1755- getFFMPEGErrorStringFromErrorCode (status),
1756- " . If the error says 'Invalid argument', it's likely that you are using "
1757- " a buggy FFmpeg version. FFmpeg4 is known to fail here in some "
1758- " valid scenarios. Try to upgrade FFmpeg?" );
1759- // streamInfo.swrContext.reset(swrContext);
1760- return swrContext;
1761- }
1762-
17631738// --------------------------------------------------------------------------
17641739// PTS <-> INDEX CONVERSIONS
17651740// --------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -310,13 +310,6 @@ class SingleStreamDecoder {
310310 const DecodedFrameContext& frameContext,
311311 const enum AVColorSpace colorspace);
312312
313- SwrContext* createSwrContext (
314- UniqueAVCodecContext& avCodecContext,
315- AVSampleFormat sourceSampleFormat,
316- AVSampleFormat desiredSampleFormat,
317- int sourceSampleRate,
318- int desiredSampleRate);
319-
320313 // --------------------------------------------------------------------------
321314 // PTS <-> INDEX CONVERSIONS
322315 // --------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments