Recherche avancée

Médias (1)

Mot : - Tags -/book

Autres articles (46)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

Sur d’autres sites (6279)

  • ffmpeg build fails with gcc error even with gcc installed (C compiler test failed)

    15 mars 2023, par Martin

    I am on macos 11.2.3, trying to build ffmpeg in my terminal. When I run my script sh buildffmpeg.sh which is below :

    


    #!/bin/bash

# If you get error `c compiler failed` run `sudo apt install libglfw3-dev libglew-dev`
# apt-get install build-essential
# apt-get build-dep ffmpeg
# when running this on mac, you need to install some libraries such as 'brew install opus'

set -e

CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
ADDITIONAL_CONFIGURE_OPTIONS=""


mkdir -p "$PACKAGES"
mkdir -p "$WORKSPACE"

FFMPEG_TAG="$1"
FFMPEG_URL="http://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/74c4c539538e36d8df02de2484b045010d292f2c.tar.gz"

FFMPEG_ARCHIVE="$PACKAGES/ffmpeg.tar.gz"

if [ ! -f "$FFMPEG_ARCHIVE" ]; then
    echo "Downloading tag ${FFMPEG_TAG}..."
    curl -L -o "$FFMPEG_ARCHIVE" "$FFMPEG_URL"
fi

EXTRACTED_DIR="$PACKAGES/extracted"

mkdir -p "$EXTRACTED_DIR"

echo "Extracting..."
tar -xf "$FFMPEG_ARCHIVE" --strip-components=1 -C "$EXTRACTED_DIR"

cd "$EXTRACTED_DIR"

echo "Building..."

# Min electron supported version
MACOS_MIN="10.10"

./configure $ADDITIONAL_CONFIGURE_OPTIONS \
    --pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
    --prefix=${WORKSPACE} \
    --pkg-config-flags="--static" \
    --extra-libs=-static \
    --extra-cflags=--static \
    --enable-cross-compile \
    --extra-cflags="-I$WORKSPACE/include -mmacosx-version-min=${MACOS_MIN}" \
    --extra-ldflags="-L$WORKSPACE/lib -mmacosx-version-min=${MACOS_MIN} -L/usr/local/opt/lame/lib -Wl,-rpath,/usr/local/opt/lame/lib" \
    --extra-libs="-lpthread -lm" \
    --enable-static \
    --disable-securetransport \
    --disable-debug \
    --disable-shared \
    --disable-ffplay \
    --disable-lzma \
    --disable-doc \
    --enable-version3 \
    --enable-pthreads \
    --enable-runtime-cpudetect \
    --enable-avfilter \
    --enable-filters \
    --disable-libxcb \
    --enable-gpl \
    --disable-libass \
    --enable-libmp3lame \
    --enable-libx264 \
    --enable-libopus

make -j 4
make install

otool -L "$WORKSPACE/bin/ffmpeg"
otool -L "$WORKSPACE/bin/ffprobe"

echo "Building done. The binaries can be found here: $WORKSPACE/bin/ffmpeg $WORKSPACE/bin/ffprobe"

mkdir ffmpeg-mac/ 
cp -r "$WORKSPACE/bin/" "$CWD/ffmpeg-mac/"

rm -rf "$PACKAGES"
rm -rf "$WORKSPACE"

exit 0



    


    It fails with this error :

    


    > sh buildffmpeg.sh

Extracting...
Building...
gcc is unable to create an executable file.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.


    


    I have been trying to solve this error, and have installed gcc with brew, if i run gcc -v I can see my installed gcc version :

    


    $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/12.2.0/bin/../libexec/gcc/x86_64-apple-darwin20/12/lto-wrapper
Target: x86_64-apple-darwin20
Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 12.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=x86_64-apple-darwin20 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Homebrew GCC 12.2.0) 


    


    So if gcc is installed correctly (i think) why is it failing with a gcc error when I build ffmpeg ?

    


    ffbuild/config.log :

    


    ...
mktemp -u XXXXXX
9v9a2o
test_ld cc
test_cc
BEGIN /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test.c
    1   int main(void){ return 0; }
END /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test.c
gcc --static -I/Users/martinbarker/Documents/projects/rendertunev1.1.2/workspace/include -mmacosx-version-min=10.10 -c -o /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test.o /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test.c
gcc -L/Users/martinbarker/Documents/projects/rendertunev1.1.2/workspace/lib -mmacosx-version-min=10.10 -L/usr/local/opt/lame/lib -Wl,-rpath,/usr/local/opt/lame/lib -o /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test /var/folders/p7/w8ysrm_x76v_z4n3nk70yd6m0000gn/T//ffconf.rUw6aGKJ/test.o -lpthread -lm -static
ld: warning: directory not found for option '-L/Users/martinbarker/Documents/projects/rendertunev1.1.2/workspace/lib'
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
C compiler test failed.



    


    gcc test :

    


    apples-MacBook:gcctest apple$ export CC=$(which gcc)
apples-MacBook:gcctest apple$ export CXX=$(which g++)
apples-MacBook:gcctest apple$ ls
minimal.c
apples-MacBook:gcctest apple$ gcc -static -Wall -o minimal minimal.c -v
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name minimal.c -static-define -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/10.0.0 -Wall -fdebug-compilation-dir /Users/apple/Documents/projects/gcctest -ferror-limit 19 -fmessage-length 157 -stack-protector 1 -fblocks -fencode-extended-block-signature -fobjc-runtime=macosx-10.13.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/7t/d2z0gq194s92vn5xz923gq5h0000gn/T/minimal-8cfbfc.o -x c minimal.c
clang -cc1 version 10.0.0 (clang-1000.10.44.4) default target x86_64-apple-darwin17.0.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -static -arch x86_64 -macosx_version_min 10.13.0 -o minimal -lcrt0.o /var/folders/7t/d2z0gq194s92vn5xz923gq5h0000gn/T/minimal-8cfbfc.o
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)


    


  • Adding ffmpeg OMX codec to Genymotion Android 4.4.2 emulator

    22 avril 2016, par photon

    Basic Question :

    Is there a way to add a new audio codec to the Genymotion Android emulator, short of downloading the entire Android source, learning how to build it, and creating my own version of Android ?


    Context :

    I have written a java Android app that acts as an audio renderer, as well as being a DLNA/OpenHome server and client. Think "BubbleUpnp" without video. My primary development platform is Win8.1. The program started as an ActiveState "pure-perl" DLNA MediaServer on Windows, which I then ported to Ubuntu, which I got working under Android a few years ago. It was pretty funky ... all UI being presented thru an HTTP server/jquery/jquery-ui, served from an Ubuntu shell running under Android (a trick in itself), serving up HTML pages to Chrome running on the same (Android) device. Besides being "funky" it had a major drawback that it required a valid IP address to work ... as I could not figure out how to get ubuntu to have a local loopback device for a 127.0.0.01 localhost I use the app as a "car stereo" on my boat (which is my home), which is often not hooked up to the internet.

    I had a hard time getting started in Android app development because the speed of the Android emulators in Eclipse was horrid, and the ADB drivers did not work from Win8 for the longest time.

    Then one day, about a year ago, I ran into Genymotion (kudos to the authors), and all of a sudden I had a workable Android development environment, so I added a Java implementation of the DLNA server, which then grew into a renderer also, using Android’s MediaPlayer class, and, adding the ability to act as a DLNA control point, and more recently also added OpenHome servers and renderers to it.

    In a separate effort, I created a build environment for this program called fpCalc, based on ffMpeg, on a variety of platforms, including Win, Linux, and Android x86, arm, and arm7 devices (bitbucket.org/phorton1/) and did an extensive series of tests to determine the validity, and longevity of fpcalc fingerprints, discovering that the fpCalc fingerprint changed based on the version of ffmpeg it was built against, a separate topic to be sure, but in the process, learned at least a bit about how to build ffmpeg as well as Android shared libraries, JNI interfaces, etc.

    So now the Android-Java version of the program has advanced past the old perl version, and I am debating whether I want to continue to try to build the perl version (and or add an wxPerl UI) to it.

    One issue that has arisen, for me, is that the Genymotion emulator does not support WMA decoding ... as Android dropped support for WMA due to licensing issues, etc, a ways back in time ... yet my music library has significant numbers of tunes in WMA files, and I don’t want to "convert" them, my carefully thought-out philosophy is that my program does not modify the contents, or tags, or anything in the original media files that I have accumulated, or will receive in the future, rather treating them as "artifacts" worth preserving "as is". No conversion is going to make a file "better" than it was, and I wish to preserve ALL of the original sources for ALL of my music going forward.

    So, I’m thinking, gee, I can build FFMPEG on 7 different platforms, and I see all these references to "OMX FFMPEG Codec Support for Android" on the net, so I’m thinking, "All I need to do is create the OMX Component and somehow get it into Genymotion".

    I have studied up OMX, OpenMaxIL, seen Michael Chen’s posts, seen the stack overflow questions

    How to make ffmpeg codec componet as OMX component

    and

    Android : How to integrate a decoder to multimedia framework

    and Cedric Fung’s page https://vec.io/posts/use-android-hardware-decoder-with-omxcodec-in-ndk, and Michael Chen’s repository at https://github.com/omxcodec , as well as virtually every other page on the net that mentions any combination of libstagefright, OMX, Genymotion, and FFMPEG.

    (this page would not let me put more than 2 links as i don’t have a "10" reputation, or I would have listed some of the sources I have seen) ..

    My Linux development environment is a Ubuntu12.04 vbox running on my win machine. I have downloaded and run the Android-x86 iso as a vbox, and IT contains the ffmpeg codecs, but unfortunately, it neither supports a wifi interface, nor the vbox "guest additions", so it has a really funky mouse. I tried for about 3 days to address those two issues, but in the end do not feel it is usable for my puproses, and I really like the way genymotion "feels", particularly the moust support, so I’d like to keep genymotion as my "windows android" virtual device under which I may run my program, deprecate and stop using my old perl source,

    except genymotion does not support WMA files ...


    Several side notes :

    (a) There is no good way to write a single sourced application in Java that runs natively in Windows, AND as an Android app.

    (b) I don’t want to reboot my Windows machine to a "real" Android device just to play my music files. The machine has to stay in Windows as I use it for other things as well.

    (c) I am writing this as my machine is in the 36th hour of downloading the entire ASOP source code base to a partition in my Ubuntu vbox while I am sitting in a hotel room on a not-so-good internet connection in Panama City, Panama, before I return to my boat in remote Bocas Del Toro Panama, where the internet connection is even worse.

    (d) I did get WMA decoding to work in my app by calling my FFMPEG executable from Java (converting it to either WAV/PCM or AAC), but, because of limitations in Android’s MediaPlayer, it does not work well, particularly for remotely hosted WMA files ... MediaPlayer insists on having the whole file present before it starts to play, which can take several seconds or longer, and I am hoping that by getting a ’real’ WMA codec underneath MediaPlayer, that problem will just disappear ....


    So, I’m trying to figure this whole mess out. There are a lot of tantalizing clues, and suggestions, but what I have found, or at least what I am starting to believe, is that if I want to add a simple WMA audio decoding codec to Android (Genymotion), not only do I have to download, basically, the ENTIRE ASOP Android source tree, and learn a new set of tools (repo, etc), but I have to (be able to) rebuild, from scratch, the entire Android system, esp. libstagefright.so in such a way as to be COMPLETELY compatible with the existing one in GenyMotion, while at the same time adding ffmpeg codecs ala Michael Chen’s page.

    And I’m just asking, is it, could it really be that difficult ?


    Anyways, this makes me crazy. Is there no way to just build a new component, or at worst a new OMX core, and add it to Genymotion, WITHOUT building all of Android, and preferably, based only on the OMX h files ? Or do I REALLY have to replace the existing libstagefright.so, which means, basically, rebuilding all of Android ...

    p.s. I thought it would be nice to get this figured out, build it, and then post the installable new FFMPEG codecs someplace for other people to use, so that they don’t also grow warts on their ears and have steam shooting out of their eyeballs, while they get old trying to figure it out ....

  • Can't decode h264 frame by frame

    17 mai 2017, par J. Doe

    Here is problematic code :

    int frame_count{0};
    int status = -1;
    while ((status = av_read_frame(ctx, pkt)) >= 0) {
       int got_frame;
       auto len =
           avcodec_decode_video2(video_ctx, frame, &got_frame, pkt);
       errcheck(len);

       if (got_frame == 0)
           errthrow("No frame could be decompressed");

       auto w = frame->width;
       auto h = frame->height;
       auto gray_convert_ctx = sws_getContext(
           w, h, input_pix_format, w, h, output_pix_format, SWS_POINT,
           nullptr, nullptr, nullptr);

       sws_scale(gray_convert_ctx, frame->data, frame->linesize, 0, h,
             frame_converted->data, frame_converted->linesize);

       f_(frame_converted->data[0], frame_converted->linesize[0], w,
          h);
       ++frame_count;
       sws_freeContext(gray_convert_ctx);

       if (pkt->data) {
           pkt->size -= len;
           pkt->data += len;
       }
    }
    if (status != AVERROR_EOF)
       errcheck(status);

    With vp8/vp9 all is okay, but when I’m trying to decode h264, I’ve got error :

    ➤ ./cv /tmp/x
    file size: 694KiB
    read /tmp/x: 694KiB
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] ISO: File Type Major Brand: mp42
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] rfps: 31.000000 0.000599
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] Before avformat_find_stream_info() pos: 3104 bytes read:32768 seeks:0
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] All info found
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x191fc00] After avformat_find_stream_info() pos: 456697 bytes read:458752 seeks:0 frames:34
    [h264 @ 0x1926700] no frame!
    error: AV: Invalid data found when processing input

    Maybe that’s because of h264 does not support AV_CODEC_CAP_TRUNCATED ? But I suppose it’s should be handled in av_read_frame.

    Then ignoring (just skipping this read if error occurs) — no frame decoded anyway until EOF. :c This video working fine with ffplay/mpv/etc. and was recorded by Android.

    #include <iostream>

    extern "C" {
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    }

    #include <functional>

    class Video
    {
         public:
       static std::string TAG;

       Video();
       Video(void *data_ptr, size_t data_size);
       ~Video();

       void set(void *data_ptr, size_t data_size);
       void process(std::function f_);

         private:
       static constexpr AVPixelFormat output_pix_format{AV_PIX_FMT_GRAY8};

       struct {
           uint8_t *ptr{nullptr};
           size_t size;
       } bd;

       bool video_ctx_opened{false};
       AVCodecContext *video_ctx{nullptr};
       AVStream *video_stream{nullptr};

       size_t width;
       size_t heigh;

       AVPixelFormat input_pix_format;

       size_t avio_ctx_buffer_size = 32 * 1024; // 32 KiB
       uint8_t *avio_ctx_buffer{nullptr};

       AVFormatContext *ctx{nullptr};
       AVIOContext *avio_ctx{nullptr};

       uint8_t *frame_converted_buffer{nullptr};
       AVFrame *frame_converted{nullptr};

       AVFrame *frame{nullptr};
       AVPacket *pkt{nullptr};

       void init_stream();
       void init_codec();
       void init_frame_converted();
    };


    extern "C" {
    #include <libswscale></libswscale>swscale.h>
    }

    #include <iostream>
    #include <stdexcept>

    namespace
    {
    using str_t = decltype(Video::TAG);

    static str_t averr(int code)
    {
       static thread_local std::array buf;
       av_make_error_string(buf.data(), buf.size(), code);
       return str_t(buf.data(), buf.size());
    }

    static str_t errstr(int err) { return Video::TAG + ": " + averr(err); }

    static str_t errstr(const char *err) { return Video::TAG + ": " + err; }

    static void errthrow(str_t err) { throw std::runtime_error{std::move(err)}; }

    static void errcheck(int val)
    {
       if (val &lt; 0)
           errthrow(errstr(val));
    }

    template <class t="t"> static void errcheck(T *ptr, const char *errmsg)
    {
       if (!ptr)
           errthrow(errstr(errmsg));
    }

    static int read_packet(void *opaque, uint8_t *buf, int buf_size)
    {
       struct _bd {
           uint8_t *ptr;
           size_t size;
       };
       _bd *bd = static_cast&lt;_bd *>(opaque);

       buf_size = FFMIN(buf_size, bd->size);

       memcpy(buf, bd->ptr, buf_size);
       bd->ptr += buf_size;
       bd->size -= buf_size;

       return buf_size;
    }
    }

    std::string Video::TAG = "AV";

    Video::Video()
    {
       av_register_all();
       avcodec_register_all();

       frame = av_frame_alloc();
       errcheck(frame, "Could not allocate frame");

       pkt = static_cast<avpacket>(av_malloc(sizeof(AVPacket)));
       errcheck(pkt, "Could not allocate packet");
       av_init_packet(pkt);
    }

    Video::Video(void *data_ptr, size_t data_size) : Video()
    {
       set(data_ptr, data_size);
    }

    Video::~Video()
    {
       avformat_close_input(&amp;ctx);
       if (avio_ctx) {
           av_freep(&amp;avio_ctx->buffer);
           av_freep(&amp;avio_ctx);
       }

       if (video_ctx) {
           avcodec_close(video_ctx);
           av_free(video_ctx);
       }
       if (frame)
           av_frame_free(&amp;frame);
       if (frame_converted_buffer)
           av_freep(&amp;frame_converted_buffer);
       if (frame_converted)
           av_frame_free(&amp;frame_converted);
       if (pkt) {
           av_free_packet(pkt);
           av_free(pkt);
       }
    }

    void Video::set(void *data_ptr, size_t data_size)
    {
       bd.ptr = static_cast(data_ptr);
       bd.size = data_size;

       init_stream();
       init_frame_converted();
       init_codec();
       pkt->data = nullptr;
       pkt->size = 0;
    }

    void Video::process(
       std::function f_)
    {
       int frame_count{0};
       int status = -1;
       while ((status = av_read_frame(ctx, pkt)) >= 0) {
           int got_frame;
           auto len =
               avcodec_decode_video2(video_ctx, frame, &amp;got_frame, pkt);
           errcheck(len);

           if (got_frame == 0)
               errthrow("No frame could be decompressed");

           auto w = frame->width;
           auto h = frame->height;
           auto gray_convert_ctx = sws_getContext(
               w, h, input_pix_format, w, h, output_pix_format, SWS_POINT,
               nullptr, nullptr, nullptr);

           sws_scale(gray_convert_ctx, frame->data, frame->linesize, 0, h,
                     frame_converted->data, frame_converted->linesize);

           f_(frame_converted->data[0], frame_converted->linesize[0], w,
              h);
           ++frame_count;
           sws_freeContext(gray_convert_ctx);

           if (pkt->data) {
               pkt->size -= len;
               pkt->data += len;
           }
       }
       if (status != AVERROR_EOF)
           errcheck(status);
    }

    void Video::init_stream()
    {
       ctx = avformat_alloc_context();
       errcheck(ctx, "Could not allocate format context");

       avio_ctx_buffer =
           static_cast(av_malloc(avio_ctx_buffer_size));
       errcheck(avio_ctx_buffer, "Could not allocate io buffer");

       avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0,
                                     &amp;bd, &amp;read_packet, nullptr, nullptr);
       errcheck(avio_ctx, "Could not allocate io context");
       ctx->pb = avio_ctx;

       auto status = avformat_open_input(&amp;ctx, nullptr, nullptr, nullptr);
       errcheck(status);

       status = avformat_find_stream_info(ctx, nullptr);
       errcheck(status);

       for (decltype(ctx->nb_streams) i = 0; i &lt; ctx->nb_streams; ++i) {
           auto stream = ctx->streams[i];
           if (!stream || !stream->codec)
               continue;
           if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
               video_stream = stream;
               break;
           }
       }
       errcheck(video_stream, "Could not find valid video stream");

       width = video_stream->codec->width;
       heigh = video_stream->codec->height;

       input_pix_format = video_stream->codec->pix_fmt;
    }

    void Video::init_codec()
    {
       auto codec = avcodec_find_decoder(video_stream->codec->codec_id);
       errcheck(codec, "Codec not found");

       video_ctx = avcodec_alloc_context3(codec);
       errcheck(video_ctx, "Could not allocate video codec context");

       if (codec->capabilities &amp; AV_CODEC_CAP_TRUNCATED)
           video_ctx->flags |=
               AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames

       auto status = avcodec_open2(video_ctx, codec, nullptr);
       errcheck(status);
    }

    void Video::init_frame_converted()
    {
       frame_converted = av_frame_alloc();
       errcheck(frame_converted, "Could not allocate frame");

       int frame_converted_buffer_size =
           avpicture_get_size(output_pix_format, width, heigh);
       errcheck(frame_converted_buffer_size);

       frame_converted_buffer =
           static_cast(av_malloc(frame_converted_buffer_size));
       errcheck(frame_converted_buffer, "Could not allocate picture buffer");

       auto status = avpicture_fill(
           reinterpret_cast<avpicture>(frame_converted),
           frame_converted_buffer, output_pix_format, width, heigh);
       errcheck(status);
    }

    #include <vector>
    #include <fstream>

    std::vector<char> read_file(const std::string &amp;fname)
    {
       std::ifstream file(fname, std::ios::binary | std::ios::ate);
       if (!file.is_open())
           throw std::runtime_error{"can't open " + fname};

       auto size = file.tellg();
       file.seekg(0, std::ios::beg);

       std::cout &lt;&lt; "file size: " &lt;&lt; std::to_string(size / 1024) &lt;&lt; "KiB\n";

       std::vector<char> buffer(size);

       if (file.read(buffer.data(), size))
           return buffer;
       return {};
    }

    int main(int argc, const char **argv)
    {
       if (argc &lt; 2)
           return EXIT_FAILURE;

       av_log_set_level(AV_LOG_DEBUG);

       try {
           auto data = read_file(argv[1]);
           std::cout &lt;&lt; "read " &lt;&lt; argv[1] &lt;&lt; ": "
                     &lt;&lt; std::to_string(data.size() / 1024) &lt;&lt; "KiB\n";

                   Video v;
               v.set(data.data(), data.size());

               v.process([](unsigned char *data, int wrap, int xsize,
                              int ysize) {
                   std::cout &lt;&lt; "w: " &lt;&lt; xsize
                             &lt;&lt; " h: " &lt;&lt; ysize &lt;&lt; '\n';
               });

       } catch (const std::runtime_error &amp;e) {
           std::cout &lt;&lt; "error: " &lt;&lt; e.what() &lt;&lt; '\n';
       }
    }
    </char></char></fstream></vector></avpicture></avpacket></class></stdexcept></iostream></functional></iostream>

    Compile&Run :
    g++ cv.cpp -std=c++14 -lavutil -lavcodec -lavformat -lswscale ; ./a.out file.name.here