FFMpeg How to use multithreading? -


i want decode h264 ffmpeg, found decode function used 1 cpu core

system monitor

env: ubuntu 14.04 ffmpeg 3.2.4 cpu i7-7500u


so, search ffmpeg multithreading , decide using cpu cores decoding.
set avcodeccontext this:

//init works //codecid=av_codec_id_h264; avcodec_register_all(); pcodec = avcodec_find_decoder(codecid); if (!pcodec) {     printf("codec not found\n");     return -1; } pcodecctx = avcodec_alloc_context3(pcodec); if (!pcodecctx) {     printf("could not allocate video codec context\n");     return -1; }  pcodecparserctx=av_parser_init(codecid); if (!pcodecparserctx) {     printf("could not allocate video parser context\n");     return -1; } pcodecctx->thread_count = 4; pcodecctx->thread_type = ff_thread_frame;  pcodec->capabilities &= codec_cap_truncated; pcodecctx->flags |= codec_flag_truncated;  if (avcodec_open2(pcodecctx, pcodec, null) < 0) {     printf("could not open codec\n");     return -1; } av_log_set_level(av_log_quiet); av_init_packet(&packet); 

//parse , decode //after av_parser_parse2, packet has complete frame data //in decode function, call avcodec_decode_video2 , frame copy work while (cur_size>0) {     int len = av_parser_parse2(                   pcodecparserctx, pcodecctx,                   &packet.data, &packet.size,                   cur_ptr, cur_size,                   av_nopts_value, av_nopts_value, av_nopts_value);      cur_ptr += len;     cur_size -= len;     if(getpacketsize()==0)         continue;      avframe *pframe = av_frame_alloc();     int ret = decode(pframe);     if (ret < 0)     {         continue;     }     if (ret)     {       //some works     } } 

but nothing different before.
how can use multithreading in ffmpeg? advise?

pcodec->capabilities &= codec_cap_truncated;

and that's bug. please remove line. return value of avcodec_find_decoder() should practical intents , purposes considered const.

specifically, statement removes av_codec_cap_frame_threads flag codec's capabilities, disabling frame-multithreading in rest of code.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -