ffmpeg-libav-tutorial icon indicating copy to clipboard operation
ffmpeg-libav-tutorial copied to clipboard

"COM must not be in STA mode\n"

Open Sulisahne opened this issue 1 year ago β€’ 3 comments

Hi

This error occures when calling avcodec_open2 with the AV_CODEC_ID_H265 or AV_CODEC_ID_H264 encoder on windows:

"COM must not be in STA mode\n"
Could not open the codec: "Invalid argument"

Does anyone have an idea how to fix this?

Sulisahne avatar Jul 15 '22 00:07 Sulisahne

Did you found the reason or a solution ?

gizmocuz avatar Sep 19 '22 15:09 gizmocuz

Calling CoUninitialize(); before avcodec_open2 prevents the error. But that does not seem to be a good solution.

Sulisahne avatar Sep 20 '22 17:09 Sulisahne

It seems to only happen when using the default encoder, not when using nvenc or x264 Calling ::CoInitialize(nullptr); or ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED) seems to solve this issue

gizmocuz avatar Sep 22 '22 11:09 gizmocuz