Skip to content

Commit 5ef60d7

Browse files
committed
Fix FFmpeg4 compilation
1 parent e74d72d commit 5ef60d7

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,6 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
9696
return avCodec.sample_fmts[0];
9797
}
9898

99-
UniqueAVFrame allocateAVFrame(
100-
int numSamples,
101-
int sampleRate,
102-
int numChannels,
103-
AVSampleFormat sampleFormat) {
104-
auto avFrame = UniqueAVFrame(av_frame_alloc());
105-
TORCH_CHECK(avFrame != nullptr, "Couldn't allocate AVFrame.");
106-
107-
avFrame->nb_samples = numSamples;
108-
avFrame->sample_rate = sampleRate;
109-
av_channel_layout_default(&avFrame->ch_layout, numChannels);
110-
avFrame->format = sampleFormat;
111-
auto status = av_frame_get_buffer(avFrame.get(), 0);
112-
113-
TORCH_CHECK(
114-
status == AVSUCCESS,
115-
"Couldn't allocate avFrame's buffers: ",
116-
getFFMPEGErrorStringFromErrorCode(status));
117-
118-
status = av_frame_make_writable(avFrame.get());
119-
TORCH_CHECK(
120-
status == AVSUCCESS,
121-
"Couldn't make AVFrame writable: ",
122-
getFFMPEGErrorStringFromErrorCode(status));
123-
return avFrame;
124-
}
125-
12699
} // namespace
127100

128101
AudioEncoder::~AudioEncoder() {}

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,33 @@ void setChannelLayout(
210210
#endif
211211
}
212212

213+
UniqueAVFrame allocateAVFrame(
214+
int numSamples,
215+
int sampleRate,
216+
int numChannels,
217+
AVSampleFormat sampleFormat) {
218+
auto avFrame = UniqueAVFrame(av_frame_alloc());
219+
TORCH_CHECK(avFrame != nullptr, "Couldn't allocate AVFrame.");
220+
221+
avFrame->nb_samples = numSamples;
222+
avFrame->sample_rate = sampleRate;
223+
setDefaultChannelLayout(avFrame, numChannels);
224+
avFrame->format = sampleFormat;
225+
auto status = av_frame_get_buffer(avFrame.get(), 0);
226+
227+
TORCH_CHECK(
228+
status == AVSUCCESS,
229+
"Couldn't allocate avFrame's buffers: ",
230+
getFFMPEGErrorStringFromErrorCode(status));
231+
232+
status = av_frame_make_writable(avFrame.get());
233+
TORCH_CHECK(
234+
status == AVSUCCESS,
235+
"Couldn't make AVFrame writable: ",
236+
getFFMPEGErrorStringFromErrorCode(status));
237+
return avFrame;
238+
}
239+
213240
SwrContext* createSwrContext(
214241
AVSampleFormat srcSampleFormat,
215242
AVSampleFormat outSampleFormat,

src/torchcodec/_core/FFMPEGCommon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ void setChannelLayout(
163163
const UniqueAVFrame& srcAVFrame,
164164
int desiredNumChannels);
165165

166+
UniqueAVFrame allocateAVFrame(
167+
int numSamples,
168+
int sampleRate,
169+
int numChannels,
170+
AVSampleFormat sampleFormat);
171+
166172
SwrContext* createSwrContext(
167173
AVSampleFormat srcSampleFormat,
168174
AVSampleFormat desiredSampleFormat,

0 commit comments

Comments
 (0)