FFMPEG decoding H264 and Multithreading

For the developers that use FFmpeg in their software.
Post Reply
jeje34
Posts: 3
Joined: Wed Jan 30, 2013 3:16 pm

FFMPEG decoding H264 and Multithreading

Post by jeje34 »

Hello, I'm using FFMPEG to decode video streaming from an IP Camera. all seems good but I try to decrease the CPU usage of my application when I decompress several differents streams.
In fact, I have a dual core processor, and if I decode one stream, my CPU usage is very low (so good). If I decompress two streams, it's ok too. But if I had a third decompression, my CPU increase from 2-5% to 25-30%.

So, I try to activate Mutlithreading in FFMPEG (compiling with --enable-w32threads) with Mingw.
But if I initialize my AVCodecContext with thread_count=3 (because I have a dual core processor) and thread_type = FF_THREAD_FRAME|FF_THREAD_SLICE, when I use avcodec_open2, I always got an result error -22: The maximum value for lowres supported by the decoder is 0. I read where this message appear in FFMPEG code source and it's in utils.c

if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0)

But in my code before call avcodec_open2( lpCodecCtx, lpCodec, ...) I have m_lpCodec->max_lowres=0 and m_lpCodecCtx->lowres=0, so I don't understa,nd why I always have this error.

Perhaps, trying Multithreading isn"t the good solution to decrease the CPU usage, I'm not very sure of this point.
Thanks for your answers,

rogerdpack
Posts: 1881
Joined: Fri Aug 05, 2011 9:56 pm

Re: FFMPEG decoding H264 and Multithreading

Post by rogerdpack »

jeje34 wrote:Hello, I'm using FFMPEG to decode video streaming from an IP Camera. all seems good but I try to decrease the CPU usage of my application when I decompress several differents streams.
In fact, I have a dual core processor, and if I decode one stream, my CPU usage is very low (so good). If I decompress two streams, it's ok too. But if I had a third decompression, my CPU increase from 2-5% to 25-30%.

So, I try to activate Mutlithreading in FFMPEG (compiling with --enable-w32threads) with Mingw.
But if I initialize my AVCodecContext with thread_count=3 (because I have a dual core processor) and thread_type = FF_THREAD_FRAME|FF_THREAD_SLICE, when I use avcodec_open2, I always got an result error -22: The maximum value for lowres supported by the decoder is 0. I read where this message appear in FFMPEG code source and it's in utils.c

if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0)

But in my code before call avcodec_open2( lpCodecCtx, lpCodec, ...) I have m_lpCodec->max_lowres=0 and m_lpCodecCtx->lowres=0, so I don't understa,nd why I always have this error.

Perhaps, trying Multithreading isn"t the good solution to decrease the CPU usage, I'm not very sure of this point.
Thanks for your answers,
I am not sure if ffmpeg's decoders are multi-threaded are they?
Anyway if you're decoding multiple simultaneous streams, you could decode each in a separate thread perhaps...
To answer your original question, I would have to suggest you re-ask it to the libav-user mailing list (at least I have no experience with libav* sorry).
-roger-

ramiro
Posts: 157
Joined: Tue May 10, 2011 12:56 am

Re: FFMPEG decoding H264 and Multithreading

Post by ramiro »

rogerdpack wrote:I am not sure if ffmpeg's decoders are multi-threaded are they?
Some are.

Tocy
Posts: 2
Joined: Wed Feb 27, 2013 10:05 am

Re: FFMPEG decoding H264 and Multithreading

Post by Tocy »

to ramiro: Have you resolved the problems using multithreading ffmpeg to decode H264?
Is there any special setting?

rogerdpack
Posts: 1881
Joined: Fri Aug 05, 2011 9:56 pm

Re: FFMPEG decoding H264 and Multithreading

Post by rogerdpack »

Tocy wrote:to ramiro: Have you resolved the problems using multithreading ffmpeg to decode H264?
Is there any special setting?
You "should" be able to decode it with threads (at least slice based,anyway). I'm not sure why it rejects it in your code, I'd suggest you reask your question on libav-user or ffmpeg-user mailing lists.
GL!
-r

Post Reply