sunlubo / SwiftFFmpeg

A Swift wrapper for the FFmpeg API
Apache License 2.0
511 stars 83 forks source link

About 8 fps compared to 60 fps using C ... #14

Closed smhk closed 5 years ago

smhk commented 5 years ago

We made a simple C program - including ffmpegapi library - for the iPhone.

All it does is open a local .ts file, and demux/decode it. So just ..

    res = avformat_open_input(&fmtCtx, filename, NULL, NULL);
    ...
    while (av_read_frame(fmtCtx, pkt) >= 0) {
          res = avcodec_send_packet(codecCtxZERO, pkt);
          ree_frame(codecCtxZERO, frameLeft);
         ... etc

On any iPhone this consistently spits out 60 fps.

But if I use SwiftFFmpeg ...

I am only decoding and doing nothing else.

This seems strange,

  1. anyone else see this?

  2. what could possibly cause it??

NOTE even the 60 or so, with the C codebase, is very slow. There is no reason for it to be so slow.

sunlubo commented 5 years ago

Hi, smhk. Please share your demo project with me, I will take a look tomorrow.

smhk commented 5 years ago

For sure, I'll check it a bit more with different test files, and then email it to you thanks a million

smhk commented 5 years ago

Ok I have learned that FFMPEG IS VERY WEAK AT DOING HARDWARE ACCEL on iOS

What happens is it does not choose the correct codec ...

HERE IS THE SECRET:

https://medium.com/liveop-x-team/accelerating-h264-decoding-on-ios-with-ffmpeg-and-videotoolbox-1f000cb6c549

You have to do exactly what that guy says in the two paragraphs starting at:

Out of the list of available pixel formats we receive .............

you do not get hardware acceleration in ffmpegapi/most-iPhones unless you do all that.

we increased performance from 7 to 10 frames per second, to 120 to 150 frames per second :)

We did that in our C - ffmpeg - Unity codebase, I will try to work out how to do it in the Swift side!!!!!!!!!!

THANK YOU!

sunlubo commented 5 years ago

For hardware acceleration on SwiftFFmpeg, you can refer to this example.