Search code examples
ubuntuffmpegvideo-processingtranscodingswscale

"sws_scale_frame" function not found in libswscale/swscale.h


I am trying to scale a video from 1080p to 480p. However, whenever I am calling sws_scale_frame() function, I keep getting undefined reference. When I checked the header file, I found that the function signature is missing from the header file. I have installed libswscale using the command sudo apt install libswscale-dev. If this is not the right appoarch, can anyone help with how to get the function or alternative if this is deprecated?

P.S. My build options in VS Code are as follows: "-lavformat","-lavcodec","-lswscale","-lavutil", "-lm", "-lpthread"

EDIT: Version of libswscale-dev is 7:4.4.2-0ubuntu0.22.04.1 if needed.


Solution

  • libswscale-dev_4.4.2 is actually too old, and doesn't yet support sws_scale_frame().

    I think sws_scale_frame() was added in FFmpeg version 5.0 (and version 4.4.2 applies FFmpeg version 4.4.2 or so).

    The following page has instructions for installing FFmpeg version 5.0 on Ubuntu.

    What worked for me is (for upgrading libswscale-dev):

    sudo apt install ppa-purge

    sudo add-apt-repository ppa:savoury1/ffmpeg5

    sudo apt install libswscale-dev

    We better also install FFmpeg 5:

    sudo apt install ffmpeg


    Now the file /usr/include/x86_64-linux-gnu/libswscale/ has declaration of the function:

    int sws_scale_frame(struct SwsContext *c, AVFrame *dst, const AVFrame *src);
    

    Note:
    I tested with Ubuntu 18.04, and installing FFmpeg 5 was not working.