Recherche avancée

Médias (91)

Autres articles (31)

  • Pas question de marché, de cloud etc...

    10 avril 2011

    Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
    sur le web 2.0 et dans les entreprises qui en vivent.
    Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
    Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
    le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
    Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

Sur d’autres sites (5024)

  • LibVLC DXVA2 Windows C++ Hardware Acceleration

    15 novembre 2016, par Sergiu Vlad

    I want to decode a h264 RTSP stream using DXVA2 Accelerated decoder. In VLC it does work but in my code have the following output :

    avcodec generic warning: threaded frame decoding is not compatible with DXVA2, disabled
    avcodec generic debug: available hardware decoder output format 61 (dxva2_vld)
    avcodec generic debug: available hardware decoder output format 128 (d3d11va_vld)
    avcodec generic debug: available software decoder output format 12 (yuvj420p)
    core generic debug: looking for hw decoder module matching "any": 1 candidates
    core generic debug: no hw decoder modules matched

    Is this a problem with NV12 conversion ? Is there a way to force DXVA2 ?

    Thanks

    CODE :

       #include
    #include
    #include
    #include
    #include
    #include <iostream>

    #include
    #include <ctime>
    #include <vlc></vlc>vlc.h>

    // RTSP address
    const char* rtspAddress = "rtsp://admin:admin@192.168.0.245/live_st1";
    // Video resolution WxH
    cv::Size rtspRes(1920, 1080);

    struct VideoDataStruct
    {
       int param;
    };

    int done = 0;
    libvlc_media_player_t *mp;
    unsigned int videoBufferSize = 0;
    uint8_t *videoBuffer = 0;

    void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size)
    {
       if (size > videoBufferSize || !videoBuffer)
       {
           printf("Reallocate raw video buffer %d bytes\n", size);
           free(videoBuffer);
           videoBuffer = (uint8_t *)malloc(size);
           videoBufferSize = size;
       }

       // videoBuffer = (uint8_t *)malloc(size);
       *pp_pixel_buffer = videoBuffer;
    }
    void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, int size, int64_t pts)
    {
       // Unlocking
       //CloseHandle(hMutex);

    }

    //static void handleEvent(const libvlc_event_t* pEvt, void* pUserData)
    //{
    //    libvlc_time_t time;
    //    switch (pEvt->type)
    //    {
    //    case libvlc_MediaPlayerTimeChanged:
    //        time = libvlc_media_player_get_time(mp);
    //        printf("MediaPlayerTimeChanged %lld ms\n", (long long)time);
    //        break;
    //    case libvlc_MediaPlayerEndReached:
    //        printf("MediaPlayerEndReached\n");
    //        done = 1;
    //        break;
    //    default:
    //        printf("%s\n", libvlc_event_type_name(pEvt->type));
    //    }
    //}

    clock_t startTime[8];
    int framesReceivedThisSecond[8];

    int main()
    {


       // VLC pointers
       libvlc_instance_t *inst;
       libvlc_media_t *m;
       void *pUserData = 0;

       VideoDataStruct dataStruct;

       // VLC options
       char smem_options[1000];

       // RV24
       sprintf(smem_options
               , "#transcode{vcodec=RV24}:smem{"
                 "video-prerender-callback=%lld,"
                 "video-postrender-callback=%lld,"
                 "video-data=%lld,"
                 "no-time-sync},"
               , (long long int)(intptr_t)(void*)&amp;cbVideoPrerender
               , (long long int)(intptr_t)(void*)&amp;cbVideoPostrender
               , (long long int)(intptr_t)(void*)&amp;dataStruct
               );

       const char * const vlc_args[] = {
           "-I", "dummy",            // Don't use any interface
           "--ignore-config",        // Don't use VLC's config
           "--extraintf=logger",     // Log anything
           "--verbose=4",            // Be verbose
           //        "--ffmpeg-hw",
           //        "-vvv",
           "--ffmpeg-hw",
           "--avcodec-hw=any",
           "--sout", smem_options    // Stream to memory

       };

       // Launch VLC
       inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

       // Create a new item
       m = libvlc_media_new_location(inst, rtspAddress);



       // Create a media player playing environement
       mp = libvlc_media_player_new_from_media(m);

       //    libvlc_event_manager_t* eventManager = libvlc_media_player_event_manager(mp);
       //    libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged, handleEvent, pUserData);
       //    libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, handleEvent, pUserData);
       //    libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged, handleEvent, pUserData);

       //libvlc_video_set_format(mp, "RV24", 240, 320, 240 * 3 );

       // play the media_player
       libvlc_media_player_play(mp);


       // Create a window for displaying the video
       std::string winName("Demo Video");
       cv::namedWindow(winName, cv::WINDOW_AUTOSIZE);

       cv::Mat frame;
       int key = 0;

       // Endless loop, press Esc to quit
       while (key != 27)
       {

           // Check for invalid input
           if (videoBuffer)
           {
               // CV_8UC3 = 8 bits, 3 chanels
               frame = cv::Mat(rtspRes, CV_8UC3, videoBuffer);
           }


           if (frame.rows == 0 || frame.cols == 0)
               continue;

           int stream_number=0;
           framesReceivedThisSecond[stream_number]++;
           long    duration = ( std::clock() - startTime[stream_number] );
           if(duration>1000)
           {
               std::cout&lt;&lt;"\n"&lt;&lt;"FPS "&lt;code></ctime></iostream>

    FULL LOG :

    core libvlc debug: Copyright © 1996-2016 the VideoLAN team
    core libvlc debug: revision 2.2.3-37-g888b7e89
    core libvlc debug: configured with ../extras/package/win32/../../../configure  '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-twolame' '--enable-quicktime' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-x264' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--disable-sdl' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=i686-w64-mingw32' '--build=x86_64-pc-linux-gnu' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=i686-w64-mingw32' 'PKG_CONFIG_PATH=/opt/intel/opencl:' 'PKG_CONFIG_LIBDIR=/home/svlad/DEV/vlc/contrib/i686-w64-mingw32/lib/pkgconfig'
    core libvlc debug: using multimedia timers as clock source
    core libvlc debug:  min period: 1 ms, max period: 1000000 ms
    core libvlc debug: searching plug-in modules
    core libvlc debug: loading plugins cache file C:\DEV\VLCStreamProcessor\build-untitled-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug\debug\plugins\plugins.dat
    core libvlc debug: recursively browsing `C:\DEV\VLCStreamProcessor\build-untitled-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug\debug\plugins'
    core libvlc debug: saving plugins cache C:\DEV\VLCStreamProcessor\build-untitled-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug\debug\plugins\plugins.dat
    core libvlc debug: plug-ins loaded: 418 modules
    core libvlc debug: translation test: code is "C"
    core libvlc debug: CPU has capabilities MMX MMXEXT SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 FPU
    core playlist debug: creating audio output
    core audio output debug: looking for audio output module matching "any": 6 candidates
    directsound audio output debug: found 2 devices
    core audio output debug: using audio output module "directsound"
    core playlist debug: keeping audio output
    core interface debug: looking for interface module matching "logger,none": 16 candidates
    logger interface: VLC media player - 2.2.4 Weatherwax
    logger interface: Copyright © 1996-2016 the VideoLAN team
    logger interface:
    Warning: if you cannot access the GUI anymore, open a command-line window, go to the directory where you installed VLC and run "vlc -I qt"
    logger interface: using logger.
    logger interface warning: no log filename provided, using `vlc-log.txt'
    logger interface debug: opening logfile `vlc-log.txt'
    core libvlc debug: VLC media player - 2.2.4 Weatherwax
    core libvlc debug: Copyright © 1996-2016 the VideoLAN team
    core libvlc debug: revision 2.2.3-37-g888b7e89
    core libvlc debug: configured with ../extras/package/win32/../../../configure  '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-twolame' '--enable-quicktime' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-x264' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--disable-sdl' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=i686-w64-mingw32' '--build=x86_64-pc-linux-gnu' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=i686-w64-mingw32' 'PKG_CONFIG_PATH=/opt/intel/opencl:' 'PKG_CONFIG_LIBDIR=/home/svlad/DEV/vlc/contrib/i686-w64-mingw32/lib/pkgconfig'
    core interface debug: using interface module "logger"
    core generic debug: creating audio output
    core audio output debug: looking for audio output module matching "any": 6 candidates
    directsound audio output debug: found 2 devices
    core audio output debug: using audio output module "directsound"
    core generic debug: keeping audio output
    core input debug: Creating an input for 'rtsp://192.168.0.245/live_st1'
    core stream output debug: using sout chain=`transcode{vcodec=RV24}:smem{video-prerender-callback=15667245,video-postrender-callback=15667630,video-data=3471900,no-time-sync},'
    core stream output debug: stream=`smem'
    core stream out debug: looking for sout stream module matching "smem": 22 candidates
    core stream out debug: set config option: sout-smem-video-prerender-callback to 15667245
    core stream out debug: set config option: sout-smem-video-postrender-callback to 15667630
    core stream out debug: set config option: sout-smem-video-data to 3471900
    core stream out debug: set config option: sout-smem-time-sync to (null)
    core stream out debug: using sout stream module "stream_out_smem"
    core stream output debug: stream=`transcode'
    core stream out debug: looking for sout stream module matching "transcode": 22 candidates
    core stream out debug: set config option: sout-transcode-vcodec to RV24
    stream_out_transcode stream out debug: Checking video codec mapping for RV24 got RV24
    stream_out_transcode stream out debug: codec video=RV24 0x0 scaling: 0.000000 0kb/s
    core stream out debug: using sout stream module "stream_out_transcode"
    core input debug: using timeshift granularity of 50 MiB, in path 'C:\Users\BCDVideo\AppData\Local\Temp'
    core input debug: `rtsp://admin:admin@192.168.0.245/live_st1' gives access `rtsp' demux `' path `admin:admin@192.168.0.245/live_st1'
    core input debug: specified demux `any'
    core input debug: creating demux: access='rtsp' demux='any' location='admin:admin@192.168.0.245/live_st1' file='\\admin:admin@192.168.0.245\live_st1'
    core demux debug: looking for access_demux module matching "rtsp": 12 candidates
    live555 demux debug: version 2016.01.12
    live555 demux debug: RTP subsession 'video/H264'
    core input debug: selecting program id=0
    live555 demux debug: setup start: 0.000000 stop:0.000000
    live555 demux debug: We have a timeout of 60 seconds
    live555 demux debug: spawned timeout thread
    live555 demux debug: play start: 0.000000 stop:0.000000
    core demux debug: using access_demux module "live555"
    core decoder debug: looking for packetizer module matching "any": 23 candidates
    packetizer_h264 decoder debug: found NAL_SPS (sps_id=0)
    packetizer_h264 decoder debug: found NAL_PPS (pps_id=0 sps_id=0)
    core decoder debug: using packetizer module "packetizer_h264"
    core input debug: starting in sync mode
    core demux meta debug: looking for meta reader module matching "any": 2 candidates
    lua demux meta debug: Trying Lua scripts in C:\Users\BCDVideo\AppData\Roaming\vlc\lua\meta\reader
    lua demux meta debug: Trying Lua scripts in C:\DEV\VLCStreamProcessor\build-untitled-Desktop_Qt_5_5_1_MSVC2013_32bit-Debug\debug\lua\meta\reader
    core demux meta debug: no meta reader modules matched
    core input debug: `rtsp://admin:admin@192.168.0.245/live_st1' successfully opened
    core input debug: switching to async mode
    core input debug: Buffering 0%
    core input debug: Buffering 3%
    core input debug: Buffering 10%
    core stream output debug: adding a new sout input (sout_input:00c21c50)
    core input debug: Buffering 13%
    stream_out_transcode stream out debug: creating video transcoding from fcc=`h264' to fcc=`RV24'
    core input debug: Buffering 16%
    core generic debug: looking for decoder module matching "any": 43 candidates
    core input debug: Buffering 20%
    core input debug: Buffering 23%
    avcodec generic debug: CPU flags: 0x0107d3db
    core input debug: Buffering 30%
    avcodec generic debug: trying to use direct rendering
    core input debug: Buffering 33%
    avcodec generic debug: allowing 4 thread(s) for decoding
    core input debug: Buffering 36%
    avcodec generic warning: threaded frame decoding is not compatible with DXVA2, disabled
    core input debug: Buffering 40%
    avcodec generic debug: avcodec codec (H264 - MPEG-4 AVC (part 10)) started
    core input debug: Buffering 43%
    avcodec generic debug: using slice thread mode with 4 threads
    core input debug: Buffering 50%
    core generic debug: using decoder module "avcodec"
    core input debug: Buffering 53%
    core encoder debug: looking for encoder module matching "any": 20 candidates
    core input debug: Buffering 56%
    core input debug: Buffering 60%
    avcodec encoder debug: CPU flags: 0x0107d3db
    core input debug: Buffering 63%
    avcodec encoder debug: Time base for probing setted to 1/1000000
    core input debug: Buffering 70%
    avcodec encoder debug: Time base set to 1/1000000
    core input debug: Buffering 73%
    avcodec encoder debug: found encoder Raw video
    core input debug: Buffering 76%
    core encoder debug: using encoder module "avcodec"
    core input debug: Buffering 80%
    core encoder debug: removing module "avcodec"
    core input debug: Buffering 83%
    core input debug: Buffering 90%
    core input debug: Buffering 93%
    core input debug: Buffering 96%
    core input debug: Stream buffering done (1002 ms in 834 ms)
    core input debug: Decoder wait done in 0 ms
    avcodec generic debug: available hardware decoder output format 61 (dxva2_vld)
    avcodec generic debug: available hardware decoder output format 128 (d3d11va_vld)
    avcodec generic debug: available software decoder output format 12 (yuvj420p)
    core generic debug: looking for hw decoder module matching "any": 1 candidates
    core generic debug: no hw decoder modules matched
    avcodec generic warning: plane 0 not aligned
    avcodec generic warning: disabling direct rendering
    stream_out_transcode stream out debug: decoder aspect is 1.761468:1
    stream_out_transcode stream out debug: source pixel aspect is 0.990826:1
    stream_out_transcode stream out debug: scaled pixel aspect is 0.990826:1
    stream_out_transcode stream out debug: source 1920x1080, destination 1920x1080
    stream_out_transcode stream out debug: source fps 30/1, destination 30/1
    stream_out_transcode stream out: input interval 33333 (base 1)
    stream_out_transcode stream out: output interval 33333 (base 1)
    stream_out_transcode stream out debug: encoder aspect is 1920:1090
    core filter debug: looking for video filter2 module matching "any": 58 candidates
    swscale filter debug: 1920x1080 (1920x1090) chroma: J420 -> 1920x1080 (1920x1090) chroma: RV24 with scaling using Bicubic (good quality)
    core filter debug: using video filter2 module "swscale"
    core stream out debug: Filter 'Swscale' (0089a2cc) appended to chain
    stream_out_transcode stream out debug: destination (after video filters) 1920x1090
    core encoder debug: looking for encoder module matching "any": 20 candidates
    avcodec encoder debug: CPU flags: 0x0107d3db
    avcodec encoder debug: Time base for probing setted to 1/30
    avcodec encoder debug: Time base set to 1/30
    avcodec encoder debug: found encoder Raw video
    core encoder debug: using encoder module "avcodec"
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518755, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518756, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518757, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518758, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518759, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518760, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518761, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518762, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518763, last: 1518769)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518764, last: 1518769)
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518784, last: 1518795)
    live555 demux debug: tk->rtpSource->hasBeenSynchronizedUsingRTCP()
    core input error: ES_OUT_RESET_PCR called
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518785, last: 1518795)
    core input debug: Buffering 0%
    core input debug: Buffering 3%
    core input debug: Buffering 6%
    core input debug: Buffering 10%
    core input debug: Buffering 13%
    core input debug: Buffering 20%
    core input debug: Buffering 23%
    core input debug: Buffering 26%
    core input debug: Buffering 30%
    core input debug: Buffering 33%
    core input debug: Buffering 40%
    core input debug: Buffering 43%
    core input debug: Buffering 46%
    core input debug: Buffering 50%
    core input debug: Buffering 53%
    core input debug: Buffering 60%
    core input debug: Buffering 63%
    core input debug: Buffering 66%
    core input debug: Buffering 70%
    core input debug: Buffering 73%
    core input debug: Buffering 80%
    core input debug: Buffering 83%
    core input debug: Buffering 86%
    core input debug: Buffering 90%
    core input debug: Buffering 93%
    core input debug: Stream buffering done (1002 ms in 817 ms)
    core input debug: Decoder wait done in 0 ms
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518834, last: 1518837)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518835, last: 1518837)
    avcodec encoder warning: almost fed libavcodec with a frame in the past (current: 1518836, last: 1518837)
    avcodec encoder warning: almost fed libavcodec with two frames with the same PTS (1518837)
    stream_out_transcode stream out warning: Reseting video sync
    stream_out_transcode stream out warning: Reseting video sync
  • libavcodec : ffprobe on file encoded with FFV1 codec reports "read_quant_table error"

    20 novembre 2016, par Ali Alidoust

    I’m using the following code to encode a series of frames into an mkv or avi file with FFV1 encoding :

      HRESULT Session::createContext(LPCSTR filename, UINT width, UINT height, UINT fps_num, UINT fps_den) {
       LOG("Exporting to file: ", filename);

       AVCodecID codecId = AV_CODEC_ID_FFV1;
       this->pixelFormat = AV_PIX_FMT_YUV420P;

       this->codec = avcodec_find_encoder(codecId);
       RET_IF_NULL(this->codec, "Could not create codec", E_FAIL);

       this->oformat = av_guess_format(NULL, filename, NULL);
       RET_IF_NULL(this->oformat, "Could not create format", E_FAIL);
       this->oformat->video_codec = codecId;
       this->width = width;
       this->height = height;
       this->codecContext = avcodec_alloc_context3(this->codec);
       RET_IF_NULL(this->codecContext, "Could not allocate context for the codec", E_FAIL);

       this->codecContext->codec = this->codec;
       this->codecContext->codec_id = codecId;

       this->codecContext->pix_fmt = pixelFormat;
       this->codecContext->width = this->width;
       this->codecContext->height = this->height;
       this->codecContext->time_base.num = fps_den;
       this->codecContext->time_base.den = fps_num;

       this->codecContext->gop_size = 1;


       RET_IF_FAILED_AV(avformat_alloc_output_context2(&amp;fmtContext, this->oformat, NULL, NULL), "Could not allocate format context", E_FAIL);
       RET_IF_NULL(this->fmtContext, "Could not allocate format context", E_FAIL);

       this->fmtContext->oformat = this->oformat;
       this->fmtContext->video_codec_id = codecId;

       this->stream = avformat_new_stream(this->fmtContext, this->codec);
       RET_IF_NULL(this->stream, "Could not create new stream", E_FAIL);
       this->stream->time_base = this->codecContext->time_base;
       RET_IF_FAILED_AV(avcodec_parameters_from_context(this->stream->codecpar, this->codecContext), "Could not convert AVCodecContext to AVParameters", E_FAIL);

       if (this->fmtContext->oformat->flags &amp; AVFMT_GLOBALHEADER)
       {
           this->codecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       av_opt_set_int(this->codecContext->priv_data, "coder", 0, 0);
       av_opt_set_int(this->codecContext->priv_data, "context", 1, 0);
       av_opt_set_int(this->codecContext->priv_data, "slicecrc", 1, 0);
       //av_opt_set_int(this->codecContext->priv_data, "slicecrc", 1, 0);
       //av_opt_set_int(this->codecContext->priv_data, "pix_fmt", pixelFormat, 0);

       RET_IF_FAILED_AV(avcodec_open2(this->codecContext, this->codec, NULL), "Could not open codec", E_FAIL);
       RET_IF_FAILED_AV(avio_open(&amp;this->fmtContext->pb, filename, AVIO_FLAG_WRITE), "Could not open output file", E_FAIL);
       RET_IF_NULL(this->fmtContext->pb, "Could not open output file", E_FAIL);
       RET_IF_FAILED_AV(avformat_write_header(this->fmtContext, NULL), "Could not write header", E_FAIL);

       frame = av_frame_alloc();
       RET_IF_NULL(frame, "Could not allocate frame", E_FAIL);
       frame->format = this->codecContext->pix_fmt;
       frame->width = width;
       frame->height = height;
       return S_OK;
    }

    HRESULT Session::writeFrame(IMFSample * pSample) {
       IMFMediaBuffer *mediaBuffer = NULL;
       BYTE *pDataNV12 = NULL;
       DWORD length;

       RET_IF_FAILED(pSample->ConvertToContiguousBuffer(&amp;mediaBuffer), "Could not convert IMFSample to contagiuous buffer", E_FAIL);
       RET_IF_FAILED(mediaBuffer->GetCurrentLength(&amp;length), "Could not get buffer length", E_FAIL);
       RET_IF_FAILED(mediaBuffer->Lock(&amp;pDataNV12, NULL, NULL), "Could not lock the buffer", E_FAIL);
       BYTE *pDataYUV420P = new BYTE[length];
       this->convertNV12toYUV420P(pDataNV12, pDataYUV420P, this->width, this->height);
       RET_IF_FAILED(av_image_fill_arrays(frame->data, frame->linesize, pDataYUV420P, pixelFormat, this->width, this->height, 1), "Could not fill the frame with data from the buffer", E_FAIL);
       LOG_IF_FAILED(mediaBuffer->Unlock(), "Could not unlock the buffer");

       frame->pts = av_rescale_q(this->pts++, this->codecContext->time_base, this->stream->time_base);

       AVPacket pkt;

       av_init_packet(&amp;pkt);
       pkt.data = NULL;
       pkt.size = 0;

       RET_IF_FAILED_AV(avcodec_send_frame(this->codecContext, frame), "Could not send the frame to the encoder", E_FAIL);
       delete[] pDataYUV420P;
       if (SUCCEEDED(avcodec_receive_packet(this->codecContext, &amp;pkt))) {
           RET_IF_FAILED_AV(av_interleaved_write_frame(this->fmtContext, &amp;pkt), "Could not write the received packet.", E_FAIL);
       }

       av_packet_unref(&amp;pkt);

       return S_OK;
    }

    HRESULT Session::endSession() {
       LOG("Ending session...");

       LOG("Closing files...")
       LOG_IF_FAILED_AV(av_write_trailer(this->fmtContext), "Could not finalize the output file.");
       LOG_IF_FAILED_AV(avio_close(this->fmtContext->pb), "Could not close the output file.");
       LOG_IF_FAILED_AV(avcodec_close(this->codecContext), "Could not close the codec.");
       av_free(this->codecContext);
       LOG("Done.")
       return S_OK;
    }

    The problem is that the generated file is not playable in either VLC or MPC-HC. However, MPC-HC reports following info in file properties :

    General
    Unique ID                      : 202978442142665779317960161865934977227 (0x98B439D9BE859109BD5EC00A62A238CB)
    Complete name                  : T:\Test.mkv
    Format                         : Matroska
    Format version                 : Version 4 / Version 2
    File size                      : 24.6 MiB
    Duration                       : 147ms
    Overall bit rate               : 1 401 Mbps
    Writing application            : Lavf57.57.100
    Writing library                : Lavf57.57.100

    Video
    ID                             : 1
    Format                         : FFV1
    Format version                 : Version 0
    Codec ID                       : V_MS/VFW/FOURCC / FFV1
    Duration                       : 147ms
    Width                          : 1 280 pixels
    Height                         : 720 pixels
    Display aspect ratio           : 16:9
    Frame rate mode                : Constant
    Frame rate                     : 1 000.000 fps
    Color space                    : YUV
    Chroma subsampling             : 4:2:0
    Bit depth                      : 8 bits
    Compression mode               : Lossless
    Default                        : Yes
    Forced                         : No
    DURATION                       : 00:00:00.147000000
    coder_type                     : Golomb Rice

    Something to note is that it reports 1000 FPS which is weird since I’ve set AVCodecContext::time_base in the code.

    UPDATE 1 :

    I managed to set the correct fps by setting time_base property of the stream :

    this->stream->time_base.den = fps_num;
    this->stream->time_base.num = fps_den;

    VLC plays the output file but it shows VLC logo instead of the video, as if there is no video stream in the file.

    UPDATE 2 :

    Cleaned up the code. Now if I set codecId = AV_CODEC_ID_MPEG2VIDEO the output file is valid and is played in both VLC and MPC-HC. Using ffprobe on the file with FFV1 encoding yields the following result :

    C:\root\apps\ffmpeg>ffprobe.exe t:\test.avi
    ffprobe version 3.2 Copyright (c) 2007-2016 the FFmpeg developers
     built with gcc 5.4.0 (GCC)
     configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
     libavutil      55. 34.100 / 55. 34.100
     libavcodec     57. 64.100 / 57. 64.100
     libavformat    57. 56.100 / 57. 56.100
     libavdevice    57.  1.100 / 57.  1.100
     libavfilter     6. 65.100 /  6. 65.100
     libswscale      4.  2.100 /  4.  2.100
     libswresample   2.  3.100 /  2.  3.100
     libpostproc    54.  1.100 / 54.  1.100
    [ffv1 @ 00000000006b83a0] read_quant_table error
    Input #0, avi, from 't:\test.avi':
     Metadata:
       encoder         : Lavf57.56.100
     Duration: 00:00:04.94, start: 0.000000, bitrate: 107005 kb/s
       Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1280x720, 107717 kb/s, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.97 tbc
  • Ffmpeg in Android Studio

    7 décembre 2016, par Ahmed Abd-Elmeged

    i’am trying to add Ffmpeg library to use it in Live Streaming app based in Youtube APi when i add it and i use Cmake Build tool the header files only shown in the c native class which i create and i want it to be included in the other header files
    which came with library how can i do it in cmake script or onther way ?

    This my cmake build script

    # Sets the minimum version of CMake required to build the native
    # library. You should either keep the default value or only pass a
    # value of 3.4.0 or lower.

    cmake_minimum_required(VERSION 3.4.1)

    # Creates and names a library, sets it as either STATIC
    # or SHARED, and provides the relative paths to its source code.
    # You can define multiple libraries, and CMake builds it for you.
    # Gradle automatically packages shared libraries with your APK.

    add_library( # Sets the name of the library.
                ffmpeg-jni

                # Sets the library as a shared library.
                SHARED

                # Provides a relative path to your source file(s).
                # Associated headers in the same location as their source
                # file are automatically included.
                src/main/cpp/ffmpeg-jni.c )

    # Searches for a specified prebuilt library and stores the path as a
    # variable. Because system libraries are included in the search path by
    # default, you only need to specify the name of the public NDK library
    # you want to add. CMake verifies that the library exists before
    # completing its build.

    find_library( # Sets the name of the path variable.
                 log-lib

                 # Specifies the name of the NDK library that
                 # you want CMake to locate.
                 log )

    # Specifies libraries CMake should link to your target library. You
    # can link multiple libraries, such as libraries you define in the
    # build script, prebuilt third-party libraries, or system libraries.

    target_link_libraries( # Specifies the target library.
                          ffmpeg-jni

                          # Links the target library to the log library
                          # included in the NDK.
                          ${log-lib} )

    include_directories(src/main/cpp/include/ffmpeglib)

    include_directories(src/main/cpp/include/libavcodec)

    include_directories(src/main/cpp/include/libavformat)

    include_directories(src/main/cpp/include/libavutil)

    This my native class i create as native file i android studio and i also have an error in jintJNIcall not found

    #include <android></android>log.h>
    #include
    #include

    #include "libavcodec/avcodec.h"
    #include "libavformat/avformat.h"
    #include "libavutil/opt.h"



    #ifdef __cplusplus
    extern "C" {
    #endif

    JNIEXPORT jboolean
    JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_init(JNIEnv *env, jobject thiz,
                                                            jint width, jint height,
                                                            jint audio_sample_rate,
                                                            jstring rtmp_url);
    JNIEXPORT void JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_shutdown(JNIEnv
                                                                               *env,
                                                                               jobject thiz
    );
    JNIEXPORT jintJNICALL
           Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeVideoFrame(JNIEnv
                                                                        *env,
                                                                        jobject thiz,
                                                                        jbyteArray
                                                                        yuv_image);
    JNIEXPORT jint
    JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeAudioFrame(JNIEnv *env,
                                                                        jobject thiz,
                                                                        jshortArray audio_data,
                                                                        jint length);

    #ifdef __cplusplus
    }
    #endif

    #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "ffmpeg-jni", __VA_ARGS__)
    #define URL_WRONLY 2
    static AVFormatContext *fmt_context;
    static AVStream *video_stream;
    static AVStream *audio_stream;

    static int pts
           = 0;
    static int last_audio_pts = 0;

    // Buffers for UV format conversion
    static unsigned char *u_buf;
    static unsigned char *v_buf;

    static int enable_audio = 1;
    static int64_t audio_samples_written = 0;
    static int audio_sample_rate = 0;

    // Stupid buffer for audio samples. Not even a proper ring buffer
    #define AUDIO_MAX_BUF_SIZE 16384  // 2x what we get from Java
    static short audio_buf[AUDIO_MAX_BUF_SIZE];
    static int audio_buf_size = 0;

    void AudioBuffer_Push(const short *audio, int num_samples) {
       if (audio_buf_size >= AUDIO_MAX_BUF_SIZE - num_samples) {
           LOGI("AUDIO BUFFER OVERFLOW: %i + %i > %i", audio_buf_size, num_samples,
                AUDIO_MAX_BUF_SIZE);
           return;
       }
       for (int i = 0; i &lt; num_samples; i++) {
           audio_buf[audio_buf_size++] = audio[i];
       }
    }

    int AudioBuffer_Size() { return audio_buf_size; }

    short *AudioBuffer_Get() { return audio_buf; }

    void AudioBuffer_Pop(int num_samples) {
       if (num_samples > audio_buf_size) {
           LOGI("Audio buffer Pop WTF: %i vs %i", num_samples, audio_buf_size);
           return;
       }
       memmove(audio_buf, audio_buf + num_samples, num_samples * sizeof(short));
       audio_buf_size -= num_samples;
    }

    void AudioBuffer_Clear() {
       memset(audio_buf, 0, sizeof(audio_buf));
       audio_buf_size = 0;
    }

    static void log_callback(void *ptr, int level, const char *fmt, va_list vl) {
       char x[2048];
       vsnprintf(x, 2048, fmt, vl);
       LOGI(x);
    }

    JNIEXPORT jboolean
    JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_init(JNIEnv *env, jobject thiz,
                                                            jint width, jint height,
                                                            jint audio_sample_rate_param,
                                                            jstring rtmp_url) {
       avcodec_register_all();
       av_register_all();
       av_log_set_callback(log_callback);

       fmt_context = avformat_alloc_context();
       AVOutputFormat *ofmt = av_guess_format("flv", NULL, NULL);
       if (ofmt) {
           LOGI("av_guess_format returned %s", ofmt->long_name);
       } else {
           LOGI("av_guess_format fail");
           return JNI_FALSE;
       }

       fmt_context->oformat = ofmt;
       LOGI("creating video stream");
       video_stream = av_new_stream(fmt_context, 0);

       if (enable_audio) {
           LOGI("creating audio stream");
           audio_stream = av_new_stream(fmt_context, 1);
       }

       // Open Video Codec.
       // ======================
       AVCodec *video_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
       if (!video_codec) {
           LOGI("Did not find the video codec");
           return JNI_FALSE;  // leak!
       } else {
           LOGI("Video codec found!");
       }
       AVCodecContext *video_codec_ctx = video_stream->codec;
       video_codec_ctx->codec_id = video_codec->id;
       video_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
       video_codec_ctx->level = 31;

       video_codec_ctx->width = width;
       video_codec_ctx->height = height;
       video_codec_ctx->pix_fmt = PIX_FMT_YUV420P;
       video_codec_ctx->rc_max_rate = 0;
       video_codec_ctx->rc_buffer_size = 0;
       video_codec_ctx->gop_size = 12;
       video_codec_ctx->max_b_frames = 0;
       video_codec_ctx->slices = 8;
       video_codec_ctx->b_frame_strategy = 1;
       video_codec_ctx->coder_type = 0;
       video_codec_ctx->me_cmp = 1;
       video_codec_ctx->me_range = 16;
       video_codec_ctx->qmin = 10;
       video_codec_ctx->qmax = 51;
       video_codec_ctx->keyint_min = 25;
       video_codec_ctx->refs = 3;
       video_codec_ctx->trellis = 0;
       video_codec_ctx->scenechange_threshold = 40;
       video_codec_ctx->flags |= CODEC_FLAG_LOOP_FILTER;
       video_codec_ctx->me_method = ME_HEX;
       video_codec_ctx->me_subpel_quality = 6;
       video_codec_ctx->i_quant_factor = 0.71;
       video_codec_ctx->qcompress = 0.6;
       video_codec_ctx->max_qdiff = 4;
       video_codec_ctx->time_base.den = 10;
       video_codec_ctx->time_base.num = 1;
       video_codec_ctx->bit_rate = 3200 * 1000;
       video_codec_ctx->bit_rate_tolerance = 0;
       video_codec_ctx->flags2 |= 0x00000100;

       fmt_context->bit_rate = 4000 * 1000;

       av_opt_set(video_codec_ctx, "partitions", "i8x8,i4x4,p8x8,b8x8", 0);
       av_opt_set_int(video_codec_ctx, "direct-pred", 1, 0);
       av_opt_set_int(video_codec_ctx, "rc-lookahead", 0, 0);
       av_opt_set_int(video_codec_ctx, "fast-pskip", 1, 0);
       av_opt_set_int(video_codec_ctx, "mixed-refs", 1, 0);
       av_opt_set_int(video_codec_ctx, "8x8dct", 0, 0);
       av_opt_set_int(video_codec_ctx, "weightb", 0, 0);

       if (fmt_context->oformat->flags &amp; AVFMT_GLOBALHEADER)
           video_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;

       LOGI("Opening video codec");
       AVDictionary *vopts = NULL;
       av_dict_set(&amp;vopts, "profile", "main", 0);
       //av_dict_set(&amp;vopts, "vprofile", "main", 0);
       av_dict_set(&amp;vopts, "rc-lookahead", 0, 0);
       av_dict_set(&amp;vopts, "tune", "film", 0);
       av_dict_set(&amp;vopts, "preset", "ultrafast", 0);
       av_opt_set(video_codec_ctx->priv_data, "tune", "film", 0);
       av_opt_set(video_codec_ctx->priv_data, "preset", "ultrafast", 0);
       av_opt_set(video_codec_ctx->priv_data, "tune", "film", 0);
       int open_res = avcodec_open2(video_codec_ctx, video_codec, &amp;vopts);
       if (open_res &lt; 0) {
           LOGI("Error opening video codec: %i", open_res);
           return JNI_FALSE;   // leak!
       }

       // Open Audio Codec.
       // ======================

       if (enable_audio) {
           AudioBuffer_Clear();
           audio_sample_rate = audio_sample_rate_param;
           AVCodec *audio_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
           if (!audio_codec) {
               LOGI("Did not find the audio codec");
               return JNI_FALSE;  // leak!
           } else {
               LOGI("Audio codec found!");
           }
           AVCodecContext *audio_codec_ctx = audio_stream->codec;
           audio_codec_ctx->codec_id = audio_codec->id;
           audio_codec_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
           audio_codec_ctx->bit_rate = 128000;
           audio_codec_ctx->bit_rate_tolerance = 16000;
           audio_codec_ctx->channels = 1;
           audio_codec_ctx->profile = FF_PROFILE_AAC_LOW;
           audio_codec_ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
           audio_codec_ctx->sample_rate = 44100;

           LOGI("Opening audio codec");
           AVDictionary *opts = NULL;
           av_dict_set(&amp;opts, "strict", "experimental", 0);
           open_res = avcodec_open2(audio_codec_ctx, audio_codec, &amp;opts);
           LOGI("audio frame size: %i", audio_codec_ctx->frame_size);

           if (open_res &lt; 0) {
               LOGI("Error opening audio codec: %i", open_res);
               return JNI_FALSE;   // leak!
           }
       }

       const jbyte *url = (*env)->GetStringUTFChars(env, rtmp_url, NULL);

       // Point to an output file
       if (!(ofmt->flags &amp; AVFMT_NOFILE)) {
           if (avio_open(&amp;fmt_context->pb, url, URL_WRONLY) &lt; 0) {
               LOGI("ERROR: Could not open file %s", url);
               return JNI_FALSE;  // leak!
           }
       }
       (*env)->ReleaseStringUTFChars(env, rtmp_url, url);

       LOGI("Writing output header.");
       // Write file header
       if (avformat_write_header(fmt_context, NULL) != 0) {
           LOGI("ERROR: av_write_header failed");
           return JNI_FALSE;
       }

       pts = 0;
       last_audio_pts = 0;
       audio_samples_written = 0;

       // Initialize buffers for UV format conversion
       int frame_size = video_codec_ctx->width * video_codec_ctx->height;
       u_buf = (unsigned char *) av_malloc(frame_size / 4);
       v_buf = (unsigned char *) av_malloc(frame_size / 4);

       LOGI("ffmpeg encoding init done");
       return JNI_TRUE;
    }

    JNIEXPORT void JNICALL
    Java_com_example_venrto_ffmpegtest_Ffmpeg_shutdown(JNIEnv
                                                        *env,
                                                        jobject thiz
    ) {
       av_write_trailer(fmt_context);
       avio_close(fmt_context
                          ->pb);
       avcodec_close(video_stream
                             ->codec);
       if (enable_audio) {
           avcodec_close(audio_stream
                                 ->codec);
       }
       av_free(fmt_context);
       av_free(u_buf);
       av_free(v_buf);

       fmt_context = NULL;
       u_buf = NULL;
       v_buf = NULL;
    }

    JNIEXPORT jintJNICALL
    Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeVideoFrame(JNIEnv
                                                                *env,
                                                                jobject thiz,
                                                                jbyteArray
                                                                yuv_image) {
       int yuv_length = (*env)->GetArrayLength(env, yuv_image);
       unsigned char *yuv_data = (*env)->GetByteArrayElements(env, yuv_image, 0);

       AVCodecContext *video_codec_ctx = video_stream->codec;
    //LOGI("Yuv size: %i w: %i h: %i", yuv_length, video_codec_ctx->width, video_codec_ctx->height);

       int frame_size = video_codec_ctx->width * video_codec_ctx->height;

       const unsigned char *uv = yuv_data + frame_size;

    // Convert YUV from NV12 to I420. Y channel is the same so we don't touch it,
    // we just have to deinterleave UV.
       for (
               int i = 0;
               i &lt; frame_size / 4; i++) {
           v_buf[i] = uv[i * 2];
           u_buf[i] = uv[i * 2 + 1];
       }

       AVFrame source;
       memset(&amp;source, 0, sizeof(AVFrame));
       source.data[0] =
               yuv_data;
       source.data[1] =
               u_buf;
       source.data[2] =
               v_buf;
       source.linesize[0] = video_codec_ctx->
               width;
       source.linesize[1] = video_codec_ctx->width / 2;
       source.linesize[2] = video_codec_ctx->width / 2;

    // only for bitrate regulation. irrelevant for sync.
       source.
               pts = pts;
       pts++;

       int out_length = frame_size + (frame_size / 2);
       unsigned char *out = (unsigned char *) av_malloc(out_length);
       int compressed_length = avcodec_encode_video(video_codec_ctx, out, out_length, &amp;source);

       (*env)->
               ReleaseByteArrayElements(env, yuv_image, yuv_data,
                                        0);

    // Write to file too
       if (compressed_length > 0) {
           AVPacket pkt;
           av_init_packet(&amp;pkt);
           pkt.
                   pts = last_audio_pts;
           if (video_codec_ctx->coded_frame &amp;&amp; video_codec_ctx->coded_frame->key_frame) {
               pkt.flags |= 0x0001;
           }
           pkt.
                   stream_index = video_stream->index;
           pkt.
                   data = out;
           pkt.
                   size = compressed_length;
           if (
                   av_interleaved_write_frame(fmt_context,
                                              &amp;pkt) != 0) {
               LOGI("Error writing video frame");
           }
       } else {
           LOGI("??? compressed_length &lt;= 0");
       }

       last_audio_pts++;

       av_free(out);
       return
               compressed_length;
    }

    JNIEXPORT jintJNICALL
    Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeAudioFrame(JNIEnv
                                                                *env,
                                                                jobject thiz,
                                                                jshortArray
                                                                audio_data,
                                                                jint length
    ) {
       if (!enable_audio) {
           return 0;
       }

       short *audio = (*env)->GetShortArrayElements(env, audio_data, 0);
    //LOGI("java audio buffer size: %i", length);

       AVCodecContext *audio_codec_ctx = audio_stream->codec;

       unsigned char *out = av_malloc(128000);

       AudioBuffer_Push(audio, length
       );

       int total_compressed = 0;
       while (

               AudioBuffer_Size()

               >= audio_codec_ctx->frame_size) {
           AVPacket pkt;
           av_init_packet(&amp;pkt);

           int compressed_length = avcodec_encode_audio(audio_codec_ctx, out, 128000,
                                                        AudioBuffer_Get());

           total_compressed +=
                   compressed_length;
           audio_samples_written += audio_codec_ctx->
                   frame_size;

           int new_pts = (audio_samples_written * 1000) / audio_sample_rate;
           if (compressed_length > 0) {
               pkt.
                       size = compressed_length;
               pkt.
                       pts = new_pts;
               last_audio_pts = new_pts;
    //LOGI("audio_samples_written: %i  comp_length: %i   pts: %i", (int)audio_samples_written, (int)compressed_length, (int)new_pts);
               pkt.flags |= 0x0001;
               pkt.
                       stream_index = audio_stream->index;
               pkt.
                       data = out;
               if (
                       av_interleaved_write_frame(fmt_context,
                                                  &amp;pkt) != 0) {
                   LOGI("Error writing audio frame");
               }
           }
           AudioBuffer_Pop(audio_codec_ctx
                                   ->frame_size);
       }

       (*env)->
               ReleaseShortArrayElements(env, audio_data, audio,
                                         0);

       av_free(out);
       return
               total_compressed;
    }

    this an example for a header file which i have an error include

    #include "libavutil/samplefmt.h"
    #include "libavutil/avutil.h"
    #include "libavutil/cpu.h"
    #include "libavutil/dict.h"
    #include "libavutil/log.h"
    #include "libavutil/pixfmt.h"
    #include "libavutil/rational.h"

    #include "libavutil/version.h"

    in the libavcodec/avcodec.h

    This code based in this example :
    https://github.com/youtube/yt-watchme