@@ -180,7 +180,7 @@ class FFmpegStream {
180
180
}
181
181
return Status::OK ();
182
182
}
183
- Status OpenCodec () {
183
+ Status OpenCodec (int64 thread_count, int64 thread_type ) {
184
184
int64 stream_index = stream_index_;
185
185
186
186
#if LIBAVCODEC_VERSION_MAJOR > 56
@@ -211,6 +211,8 @@ class FFmpegStream {
211
211
#else
212
212
codec_context_ = format_context_->streams [stream_index]->codec ;
213
213
#endif
214
+ codec_context_->thread_count = (int )thread_count;
215
+ codec_context_->thread_type = (int )thread_type;
214
216
{
215
217
// avcodec_open2 is not thread-safe
216
218
mutex_lock lock (mu);
@@ -300,7 +302,8 @@ class FFmpegAudioStream : public FFmpegStream {
300
302
301
303
Status OpenAudio (int64 index) {
302
304
TF_RETURN_IF_ERROR (Open (AVMEDIA_TYPE_AUDIO, index ));
303
- TF_RETURN_IF_ERROR (OpenCodec ());
305
+ // FF_THREAD_SLICE=2, see libavcodec/avcodec.h
306
+ TF_RETURN_IF_ERROR (OpenCodec (FF_THREAD_SLICE, 1 ));
304
307
305
308
int64 stream_index = stream_index_;
306
309
#if LIBAVCODEC_VERSION_MAJOR > 56
@@ -597,7 +600,8 @@ class FFmpegVideoStream : public FFmpegStream {
597
600
598
601
Status OpenVideo (int64 index) {
599
602
TF_RETURN_IF_ERROR (Open (AVMEDIA_TYPE_VIDEO, index ));
600
- TF_RETURN_IF_ERROR (OpenCodec ());
603
+ // FF_THREAD_SLICE=2, see libavcodec/avcodec.h
604
+ TF_RETURN_IF_ERROR (OpenCodec (FF_THREAD_SLICE, 1 ));
601
605
602
606
dtype_ = DT_UINT8;
603
607
height_ = codec_context_->height ;
0 commit comments