Skip to content

Commit 9f7679e

Browse files
authored
Add ffmpeg default thread options (#1435)
* add ffmpeg thread options * add benchmark test * trim trailing comma * remove unused member vars * fix lint error * revert python api change * add FF_THREAD_SLICE comment
1 parent 87e2b4d commit 9f7679e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tensorflow_io/core/kernels/ffmpeg_kernels.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class FFmpegStream {
180180
}
181181
return Status::OK();
182182
}
183-
Status OpenCodec() {
183+
Status OpenCodec(int64 thread_count, int64 thread_type) {
184184
int64 stream_index = stream_index_;
185185

186186
#if LIBAVCODEC_VERSION_MAJOR > 56
@@ -211,6 +211,8 @@ class FFmpegStream {
211211
#else
212212
codec_context_ = format_context_->streams[stream_index]->codec;
213213
#endif
214+
codec_context_->thread_count = (int)thread_count;
215+
codec_context_->thread_type = (int)thread_type;
214216
{
215217
// avcodec_open2 is not thread-safe
216218
mutex_lock lock(mu);
@@ -300,7 +302,8 @@ class FFmpegAudioStream : public FFmpegStream {
300302

301303
Status OpenAudio(int64 index) {
302304
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));
304307

305308
int64 stream_index = stream_index_;
306309
#if LIBAVCODEC_VERSION_MAJOR > 56
@@ -597,7 +600,8 @@ class FFmpegVideoStream : public FFmpegStream {
597600

598601
Status OpenVideo(int64 index) {
599602
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));
601605

602606
dtype_ = DT_UINT8;
603607
height_ = codec_context_->height;

0 commit comments

Comments
 (0)