Hello,
I have some trouble using the avcodec_decode_video2() function in my
project (Java wrapper for Libav). The function alone causes much higher CPU
load than the whole avplay tool which also does some frame scaling and
rendering in addition. It is most obvious while decoding an H.264 encoded
video stream. For example if the whole avplay consumes 69 seconds of CPU
time, the avcodec_decode_video2() alone is responsible for consuming 78
seconds of CPU time in my application (both cases under same conditions).
Of course there is a little overhead because of calling the native function
from the JVM, but it is so small it is almost not worth of mentioning (and
it would also affect other Libav functions I'm using if there was a big
overhead).

Here is a brief description of the decoding process my application uses:
 - thread 1:
    1) read a next packet using the av_read_frame() function
    2) duplicate the packet
    3) put the duplicate into a packet buffer
    4) go back to the step 1 if there are more packets
 - thread 2:
    1) open a codec context using the avcodec_open2() function (with NULL
options param)
    2) get a next packet from the packet buffer
    3) decode the packet
    4) wait for the right time to display a frame if there is a new one
    5) go back to the step 2 if there are more packets in the buffer

Complete code is available here: http://code.google.com/p/jlibav/
Important classes are:
VideoFrameDecoder (
http://code.google.com/p/jlibav/source/browse/jlibav/src/main/java/org/libav/video/VideoFrameDecoder.java),

BufferedPacketReader (
http://code.google.com/p/jlibav/source/browse/jlibav/src/main/java/org/libav/data/BufferedPacketReader.java),

CodecContextWrapper54 (
http://code.google.com/p/jlibav/source/browse/jlibav/src/main/java/org/libav/avcodec/CodecContextWrapper54.java
),
FormatContextWrapper54 (
http://code.google.com/p/jlibav/source/browse/jlibav/src/main/java/org/libav/avformat/FormatContextWrapper54.java
).

Do you have any idea where could be a problem? Maybe some decoder
configuration?
_______________________________________________
libav-api mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-api

Reply via email to