简体   繁体   English

在多线程中使用FFMPEG解码h264文件时出错?

[英]Error when Decode h264 file by using FFMPEG with multithreading?

I write the code for decoding many .flv video files. 我编写了用于解码许多.flv视频文件的代码。 Each video file is decoded by a separate thread. 每个视频文件均由单独的线程解码。 When I try on 1 thread, everything is ok. 当我尝试1个线程时,一切正常。 But when I try on more than 2 threads, it always occurs the error "insufficient thread locking around avcodec_open/close()". 但是,当我尝试2个以上的线程时,总是会发生错误“线程在avcodec_open / close()周围锁定不足”。

I have searched and I know the functions avcodec_open() and avcodec_close() is not thread safe. 我已经搜索过,而且我知道avcodec_open()和avcodec_close()函数不是线程安全的。 And after that, I putted the mutex locking at anywhere that two that functions are called. 之后,我将互斥锁锁定在调用两个函数的任何地方。

lockObj.Lock();
avcodec_open/close();
lockObj.UnLock();

But the error "insufficient thread locking around avcodec_open/close()" is still happen. 但是仍然发生错误“在avcodec_open / close()周围线程锁定不足”。

Someone can tell me the solution? 有人可以告诉我解决方案吗?

Many thanks, 非常感谢,

T&TGroup T&T集团

Is lockObj the same object in every thread? 每个线程中的lockObj是否lockObj相同的对象?

The point of the mutex is to stop more than one thread from calling avcodec_open() at the same time. 互斥锁的目的是要阻止多个线程同时调用avcodec_open() The other threads should stop and wait when they get to the lockObj.Lock() statement until the first thread calls lockObj.UnLock() . 其他线程应该停止并等待它们进入lockObj.Lock()语句,直到第一个线程调用lockObj.UnLock()为止。 This is not possible if each thread has its own lockObj . 如果每个线程都有自己的lockObj则这是不可能的。

I have used this method with a QMutex (from Qt), so I know it is possible. 我已经将这种方法与QMutex(来自Qt)一起使用了,所以我知道这是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM