对ffmpeg的以下几个线程有关的api所涉及的机制不太懂: int avcodec_thread_init(AVCodecContext *s, int thread_count); void avcodec_thread_free(AVCodecContext *s); int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); 在ffmpeg.c里,只调用到了avcodec_thread_init()这个函数 如在 static void new_video_stream(AVFormatContext *oc) 函数3213行里: avcodec_thread_init(st->codec, thread_count; 其他2个函数 avcodec_thread_free是在avcodec_thread_init里调用 avcodec_default_execute,avcodec_default_execute2是在avcodec_get_context_defaults2赋值 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ ... ... s->execute= avcodec_default_execute; s->execute2= avcodec_default_execute2; ... ... }; 我猜的是这样的: ffmpeg转换时,支持多线程,那么api暴露出来的函数avcodec_thread_init, 设置线程数,那么内部则通过s->execute这个字段来做多线程的工作. 即当我使用以下命令时: { "threads", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, 如: ffmpeg -i a.flv -threads 5 a.avi ffmpeg内部自动开了5条线程来进行转换? 不知道我理解得对不对?但同时,我有疑问的是, 是不是线程安全,信号量,ffmpeg已经做好了的.比如,即使,我要在UI界面里,操作控件,将转换进度等信息表现出来, 都可以直接使用的,而不用在UI界面里要考滤同步的问题? 同时,怎么没有设置线程优先级之类的函数.呵呵,我是在windows下编程的,可能这个问题有点没水平,不清楚linux的情形. |
学习ffmpeg.c过程中遇上的系列问题
最新推荐文章于 2025-03-26 11:27:55 发布