leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.93k stars 956 forks source link

"COM must not be in STA mode\n" #118

Open Sulisahne opened 2 years ago

Sulisahne commented 2 years ago

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?

gizmocuz commented 2 years ago

Did you found the reason or a solution ?

Sulisahne commented 2 years ago

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

gizmocuz commented 2 years ago

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