Recherche avancée

Médias (1)

Mot : - Tags -/publicité

Autres articles (61)

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

  • Submit bugs and patches

    13 avril 2011

    Unfortunately a software is never perfect.
    If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
    If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
    You may also (...)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

Sur d’autres sites (9203)

  • Unable to use Makefile on ffmpegthumbnailer setup files with Cygwin for Windows 10

    21 août 2018, par Cole Phiper

    I am currently trying to build the exe/binary files to support ffmpegthumbnailer on Windows 10. I read multiple posts on getting it to work, but none seem to satisfy my needs. I currently have ffmpegthumbnailer-2.2.0 stored at C :\ffmpegthumbnailer-2.2.0 I see a folder named CMakeFiles, dist, kffmpegthumbnailer, libffmpegthumbnailer, man, test and thunar files. When I run make in the directory, I receive

    User@User-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0/man
    $ make
    make: *** No targets specified and no makefile found.  Stop.

    How do I build/make the exec files, so that I can use the PATH variable to find ffmpegthumbnailer ?

    UPDATE 1 :
    I tried the automake command, but I received the message below

    $ automake
    /cygdrive/c/RubyDevKit/mingw/bin/automake: /cygdrive/c/RubyDevKit/mingw/bin/automake-1.11: /bin/perl: bad interpreter: No such file or directory
    /cygdrive/c/RubyDevKit/mingw/bin/automake: line 156: /cygdrive/c/RubyDevKit/mingw/bin/automake-1.11: No error

    UPDATE 2 :

    I ran cmake and received the message below.

    Coder@Coder-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build
    $ cmake ../
    -- Building for: Visual Studio 15 2017
    -- The C compiler identification is MSVC 19.14.26428.1
    -- The CXX compiler identification is MSVC 19.14.26428.1
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studo/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studo/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
    -- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
    -- Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
    -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
    CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmke:489 (message):
     pkg-config tool not found
    Call Stack (most recent call first):
     C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmake:602 (_pkgcheck_modules_internal)
     CMakeLists.txt:58 (PKG_CHECK_MODULES)


    CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmke:489 (message):
     pkg-config tool not found
    Call Stack (most recent call first):
     C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmake:602 (_pkgcheck_modules_internal)
     CMakeLists.txt:59 (PKG_CHECK_MODULES)


    CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmke:489 (message):
     pkg-config tool not found
    Call Stack (most recent call first):
     C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmake:602 (_pkgcheck_modules_internal)
     CMakeLists.txt:60 (PKG_CHECK_MODULES)


    CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmke:489 (message):
     pkg-config tool not found
    Call Stack (most recent call first):
     C:/Program Files/CMake/share/cmake-3.12/Modules/FindPkgConfig.cmake:602 (_pkgcheck_modules_internal)
     CMakeLists.txt:61 (PKG_CHECK_MODULES)


    --
    -- CONFIGURATION SUMMARY
    -- png support          : disabled
    -- jpeg support         : disabled
    -- gio support          : disabled
    -- register thumbnailer : disabled
    -- unittests            : enabled
    -- debug mode           : disabled
    CMake Error: The following variables are used in this project, but they are setto NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake fils:
    AVCODEC_INCLUDE_DIR
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
    AVCODEC_LIBRARY
       linked by target "libffmpegthumbnailer" in directory C:/ffmpegthumbnailer-22.0
    AVFILTER_INCLUDE_DIR
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
    AVFILTER_LIBRARY
       linked by target "libffmpegthumbnailer" in directory C:/ffmpegthumbnailer-22.0
    AVFORMAT_INCLUDE_DIR
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
    AVFORMAT_LIBRARY
       linked by target "libffmpegthumbnailer" in directory C:/ffmpegthumbnailer-22.0
    AVUTIL_INCLUDE_DIR
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
      used as include directory in directory C:/ffmpegthumbnailer-2.2.0/test
    AVUTIL_LIBRARY
       linked by target "libffmpegthumbnailer" in directory C:/ffmpegthumbnailer-22.0

    -- Configuring incomplete, errors occurred!
    See also "C:/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build/CMakeFiles/CMakeOuput.log".

    Coder@Coder-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build
    $

    UPDATE 3

    Coder@Coder-WIN10 ~
    $ cd C:\ffmpegthumbnailer-2.2.0

    Coder@Coder-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0
    $ cd ffmpegthumbnailer_build

    Coder@Coder-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build
    $ cmake ../
    -- The C compiler identification is GNU 7.3.0
    -- The CXX compiler identification is GNU 7.3.0
    CMake Warning at /usr/share/cmake-3.6.2/Modules/Platform/CYGWIN.cmake:15 (message):
     CMake no longer defines WIN32 on Cygwin!

     (1) If you are just trying to build this project, ignore this warning or
     quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
     the CMake cache.  If later configuration or build errors occur then this
     project may have been written under the assumption that Cygwin is WIN32.
     In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.

     (2) If you are developing this project, add the line

       set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required

     at the top of your top-level CMakeLists.txt file or set the minimum
     required version of CMake to 2.8.4 or higher.  Then teach your project to
     build on Cygwin without WIN32.
    Call Stack (most recent call first):
     /usr/share/cmake-3.6.2/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
     CMakeLists.txt:26 (PROJECT)


    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++.exe
    -- Check for working CXX compiler: /usr/bin/c++.exe -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Found JPEG: /usr/lib/libjpeg.dll.a
    -- Found ZLIB: /usr/lib/libz.dll.a (found version "1.2.11")
    -- Found PNG: /usr/lib/libpng.dll.a (found version "1.6.34")
    -- Found PkgConfig: /usr/bin/pkg-config.exe (found version "0.29.1")
    -- Checking for module 'libavcodec'
    --   No package 'libavcodec' found
    CMake Error at /usr/share/cmake-3.6.2/Modules/FindPkgConfig.cmake:424 (message):
     A required package was not found
    Call Stack (most recent call first):
     /usr/share/cmake-3.6.2/Modules/FindPkgConfig.cmake:597 (_pkg_check_modules_internal)
     CMakeLists.txt:58 (PKG_CHECK_MODULES)


    -- Configuring incomplete, errors occurred!
    See also "/cygdrive/c/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build/CMakeFiles/CMakeOutput.log".

    Coder@Coder-WIN10 /cygdrive/c/ffmpegthumbnailer-2.2.0/ffmpegthumbnailer_build
    $
  • Mux raw H264 into MP4 using ffmpeg API

    2 décembre 2016, par user1886318

    I try to mux raw H264 frames into MP4 container using ffmpeg in order to play the video with Media Source Extension in a web browser.

    The following command works like a charm :

    ffmpeg -i video.h264 -movflags frag_keyframe+empty_moov fragmented.mp4

    Now, I would like to do the same thing using the FFmpeg C++ API.

    I wrote the following source code :

    #ifdef _WIN32
    #define snprintf _snprintf
    #endif
    #include
    #include
    #include
    #include
    #include

    extern "C" {
    #include <libavutil></libavutil>avassert.h>
    #include <libavutil></libavutil>channel_layout.h>
    #include <libavutil></libavutil>opt.h>
    #include <libavutil></libavutil>mathematics.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libswscale></libswscale>swscale.h>
    #include <libswresample></libswresample>swresample.h>

    }

    #include

    #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
    #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
    #else
    #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
    #endif

    struct timezone
    {
     int  tz_minuteswest; /* minutes W of Greenwich */
     int  tz_dsttime;     /* type of dst correction */
    };

    #ifdef WIN32
    #include
    #include <sys></sys>timeb.h>
    int gettimeofday(struct timeval *tp, void *tz)
    {
     struct _timeb timebuffer;
     _ftime(&amp;timebuffer);
     tp->tv_sec = timebuffer.time;
     tp->tv_usec = timebuffer.millitm * 1000;
     return 0;
    }
    #endif

    // a wrapper around a single output AVStream
    typedef struct OutputStream {
     AVStream *st;
    } OutputStream;

    static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
    {
     return av_interleaved_write_frame(fmt_ctx, pkt);
    }

    /* Add an output stream. */
    static void add_stream(OutputStream *ost, AVFormatContext *oc,
     AVCodec **codec,
    enum AVCodecID codec_id)
    {
     AVCodecContext *c;

     *codec = avcodec_find_encoder(codec_id);
     printf("avformat_new_stream\n");

     ost->st = avformat_new_stream(oc, *codec);
     if (!ost->st) {
       fprintf(stderr, "Could not allocate stream\n");
       exit(1);
     }
     ost->st->id = oc->nb_streams - 1;
     c = ost->st->codec;

     switch ((*codec)->type) {
     case AVMEDIA_TYPE_VIDEO:
       c->codec_id = codec_id;

       c->width = 352;
       c->height = 288;
       ost->st->time_base = { 1, 15 };
       c->time_base = ost->st->time_base;
       c->pix_fmt = AV_PIX_FMT_YUV420P;
       c->profile = FF_PROFILE_H264_BASELINE;

       break;

     default:
       break;
     }

     /* Some formats want stream headers to be separate. */
     if (oc->oformat->flags &amp; AVFMT_GLOBALHEADER)
       c->flags |= CODEC_FLAG_GLOBAL_HEADER;
    }

    uint64_t begin_timestamp_us = 0;

    static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
    {
     int ret = 0;
     AVCodecContext *c;
     c = ost->st->codec;

     struct timeval now;
     gettimeofday(&amp;now, NULL);
     uint64_t timestamp_us = (now.tv_sec * 1000000LL + now.tv_usec - begin_timestamp_us);

     {
         {
           AVFormatContext *fmt_ctx = oc;
           const AVRational *time_base = &amp;c->time_base;
           AVStream *st = ost->st;

           char* buf;

           AVPacket pkt = { 0 };
           av_init_packet(&amp;pkt);

           char filename[256];
           static int pts = 0;

           snprintf(filename, 256, "avc_raw\\avc_raw_%03d.h264", pts);

           FILE *f = fopen(filename, "rb");
           int len = 0;
           if (f){
             fseek(f, 0, SEEK_END); // seek to end of file
             len = ftell(f); // get current file pointer
             //fseek(f, 0, SEEK_SET); // seek back to beginning of file
             rewind(f);
             buf = new char[len + 1]; // to delete
             fread(buf, 1, len, f);
             fclose(f);
           }
           else{
             return 1;
           }

           int nal_type = buf[4] &amp; 0x0f;
           int is_IDR_nal = 0;
           if (nal_type == 0x7){
             //7 sps; 8 pps; IDR frame follow with sps
             is_IDR_nal = 1;
             pkt.flags |= AV_PKT_FLAG_KEY;
             printf("frame %d is IDR\n", pts);
           }
           pkt.stream_index = ost->st->index;
           pkt.data = (uint8_t*)buf;
           pkt.size = len;

           pkt.dts = pkt.pts = timestamp_us;

           pts++;

           write_frame(fmt_ctx, &amp;c->time_base, st, &amp;pkt);
         }

     }

     if (ret &lt; 0) {
       fprintf(stderr, "Error while writing video frame: %s\n", ret);
       exit(1);
     }

     return 0;
    }

    /**************************************************************/
    /* media file output */

    int main(int argc, char **argv)
    {
     OutputStream video_st = { 0 };
     const char *filename;
     AVOutputFormat *fmt;
     AVFormatContext *oc;
     AVCodec *video_codec;
     int ret;
     int encode_video = 0;
     AVDictionary *opt = NULL;

     /* Initialize libavcodec, and register all codecs and formats. */
     av_register_all();

     if (argc &lt; 2) {
       return 1;
     }

     filename = argv[1];

     oc = avformat_alloc_context();
     if (!oc) {
       fprintf(stderr, "Memory error\n");
       exit(1);
     }

     // auto detect the output format from the name. default is mpeg.
     AVOutputFormat * avOutputFormat = av_guess_format(NULL, filename, NULL);
     if (!avOutputFormat) {
       printf("Could not deduce output format from file extension: using MPEG.\n");
       avOutputFormat = av_guess_format("mpeg", NULL, NULL);
     }
     if (!avOutputFormat) {
       fprintf(stderr, "Could not find suitable output format\n");
       exit(1);
     }
     oc->oformat = avOutputFormat;
     avOutputFormat->video_codec = AV_CODEC_ID_H264;
     avOutputFormat->audio_codec = AV_CODEC_ID_NONE;
     fmt = avOutputFormat;

     /* Add the audio and video streams using the default format codecs
     * and initialize the codecs. */
     if (fmt->video_codec != AV_CODEC_ID_NONE) {
       add_stream(&amp;video_st, oc, &amp;video_codec, fmt->video_codec);
       encode_video = 1;
     }

     av_dump_format(oc, 0, filename, 1);

     /* open the output file, if needed */
     if (!(fmt->flags &amp; AVFMT_NOFILE)) {
       ret = avio_open(&amp;oc->pb, filename, AVIO_FLAG_WRITE);
       if (ret &lt; 0) {
         fprintf(stderr, "Could not open '%s': %s\n", filename,
           ret);
         return 1;
       }
     }

     // Fragmented MP4
     av_dict_set(&amp;opt, "movflags", "empty_moov+frag_keyframe", 0);

     /* Write the stream header, if any. */
     ret = avformat_write_header(oc, &amp;opt);
     if (ret &lt; 0) {
       fprintf(stderr, "Error occurred when opening output file: %s\n",
         ret);
       return 1;
     }

     struct timeval now;
     gettimeofday(&amp;now, NULL);
     begin_timestamp_us = (now.tv_sec * 1000000LL + now.tv_usec);

     while (encode_video) {
       encode_video = !write_video_frame(oc, &amp;video_st);
       _sleep(1);
     }

     av_write_trailer(oc);

     if (!(fmt->flags &amp; AVFMT_NOFILE))
       /* Close the output file. */
       avio_close(oc->pb);

     /* free the stream */
     avformat_free_context(oc);
     _sleep(1000);
     return 0;
    }

    H264 files can be downloaded from the link : https://github.com/gjwang/ffmpeg_mp4_mux/tree/master/avc_raw

    This generates a MP4 video that I can play using Chrome and VLC, but Firefox and some tools (like Windows Media Player) say the video is corrupted.

    Here is a link to the generated video : https://ufile.io/5b3241

    Thanks for your help.

  • FFmpeg RTP streaming

    19 juillet 2016, par Johnnylin

    Can anyone show me an example code of how to use FFmpeg to encode a ".mp4" video and then output to network stream using RTP(rtp ://127.0.0.1:6666). I have searched for it on google but most of them are just command line. Thanks very much.

    UPDATED :

               extern "C"{
               #include <libavcodec></libavcodec>avcodec.h>
               #include <libavformat></libavformat>avformat.h>
               #include <libswscale></libswscale>swscale.h>
               #include <libavutil></libavutil>avutil.h>
               #include <libavutil></libavutil>opt.h>
               #include <libavutil></libavutil>time.h>

               }
               #include
               #include <iostream>
               #include <string>
               using namespace std;

               // compatibility with newer API
               #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1)
               #define av_frame_alloc avcodec_alloc_frame
               #define av_frame_free avcodec_free_frame
               #endif
               #define RNDTO2(X) ( ( (X) &amp; 0xFFFFFFFE ))
               #define RNDTO32(X) ( ( (X) % 32 ) ? ( ( (X) + 32 ) &amp; 0xFFFFFFE0 ) : (X) )

               //avcodec_alloc_frame is an old name


               int main(int argc, char *argv[]) {
                   // Initalizing these to NULL prevents segfaults!
                   AVFormatContext   *pFormatCtx = NULL;
                   int               i, videoStream;
                   AVCodecContext    *pCodecCtxOrig = NULL;
                   AVCodecContext    *pCodecCtx = NULL;
                   AVCodec           *pCodec = NULL;
                   AVFrame           *pFrame = NULL;
                   AVPacket          packet;
                   int               frameFinished;
                   int               numBytes;
                   struct SwsContext *sws_ctx = NULL;
                   int frame_index=0;

                   if(argc &lt; 2) {
                   printf("Please provide a movie file\n");
                   return -1;
                   }

                   // Register all formats and codecs
                   av_register_all();

                   //initialize network video
                   avformat_network_init();


                   int errorStatus = 0;
                   char errorLog[128] = { 0 };
                   av_log_set_level(AV_LOG_TRACE);


                   //------------------ This is for local video file --------------
                   // Open video file
                   if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL)!=0)
                   return -1; // Couldn't open file

                   // Retrieve stream information
                   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)
                   return -1; // Couldn't find stream information

                   // Find the first video stream
                   videoStream=-1;
                   for(i=0; inb_streams; i++)
                   if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
                     videoStream=i;
                     break;
                   }

                   // Dump information about file onto standard error
                   av_dump_format(pFormatCtx, 0, argv[1], 0);


                   if(videoStream==-1)
                       return -1; // Didn't find a video stream

                   // Get a pointer to the codec context for the video stream
                   pCodecCtxOrig=pFormatCtx->streams[videoStream]->codec;
                   // Find the decoder for the video stream
                   pCodec=avcodec_find_decoder(pCodecCtxOrig->codec_id);
                   if(pCodec==NULL) {
                   fprintf(stderr, "Unsupported codec!\n");
                   return -1; // Codec not found
                   }

                   // Copy context
                   pCodecCtx = avcodec_alloc_context3(pCodec);
                   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
                   fprintf(stderr, "Couldn't copy codec context");
                   return -1; // Error copying codec context
                   }

                   // Open codec
                   if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)
                       return -1; // Could not open codec

                   // Allocate video frame
                   pFrame=av_frame_alloc();


                   // use nvidia codec
                   AVCodec* en_codec = avcodec_find_encoder_by_name("nvenc");
                   //AVCodec* en_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
                   AVCodecContext* nv_codec_context = avcodec_alloc_context3(en_codec);

                   nv_codec_context->bit_rate = 1244179;
                   nv_codec_context->width = 1920;                              
                   nv_codec_context->height = 1080;
                   nv_codec_context->time_base.num = 1;                                
                   nv_codec_context->time_base.den = 30;                              
                   nv_codec_context->gop_size = 10;                                    
                   nv_codec_context->max_b_frames = 1;                                  
                   nv_codec_context->keyint_min = 1;                                    
                   nv_codec_context->i_quant_factor = (float)0.71;                      
                   nv_codec_context->b_frame_strategy = 20;                            
                   nv_codec_context->qcompress = (float)0.6;                              
                   nv_codec_context->qmin = 20;                                      
                   nv_codec_context->qmax = 51;                                        
                   nv_codec_context->max_qdiff = 4;                                      
                   nv_codec_context->refs = 4;                                        
                   nv_codec_context->trellis = 1;                                        
                   nv_codec_context->pix_fmt = AV_PIX_FMT_YUV420P;                      
                   //nv_codec_context->codec_id = AV_CODEC_ID_H264;
                   //nv_codec_context->codec_type = AVMEDIA_TYPE_VIDEO;

                   if (avcodec_open2(nv_codec_context, en_codec,NULL) &lt; 0) {
                       fprintf(stderr, "Could not open codec\n");
                       exit(1);
                   }else printf("\nH264 codec opened\n");


                   /******stream*******/

                   string m_output("rtp://147.8.179.229:6666");
                   AVFormatContext* m_formatContext = NULL;
                   AVStream* m_stream = NULL;
                   if (avformat_alloc_output_context2(&amp;m_formatContext, NULL, "H264", m_output.c_str()) &lt; 0) {
                          cerr &lt;&lt; "Cannot allocate output context: "
                               &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                          return -1;
                   }

                   //AVCodec* tmp_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
                   m_stream = avformat_new_stream(m_formatContext, en_codec);
                     if (!m_stream) {
                         cerr &lt;&lt; "Cannot create a new stream: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   av_dump_format(m_formatContext, 0, m_output.c_str(), 1);

                   m_stream->codec->pix_fmt = AV_PIX_FMT_YUV420P;
                   m_stream->codec->width = 1920;
                   m_stream->codec->height = 1080;
                   //m_stream->codec->codec_id = AV_CODEC_ID_H264;
                   m_stream->codec->bit_rate = 40000;
                   m_stream->codec->time_base.den = 30;
                   m_stream->codec->time_base.num = 1;
                   m_stream->time_base.den = 30;
                   m_stream->time_base.num = 1;

                   m_stream->codec->codec_tag = 0;
                   if (m_formatContext->oformat->flags &amp; AVFMT_GLOBALHEADER)
                       m_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;


                   if (!(m_formatContext->oformat->flags &amp; AVFMT_NOFILE))
                       errorStatus = avio_open(&amp;m_formatContext->pb, m_output.c_str(), AVIO_FLAG_WRITE);



                   if ((errorStatus) &lt; 0) {
                       cerr &lt;&lt; "Cannot open output: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   if (avformat_write_header(m_formatContext, NULL) &lt; 0) {
                       cerr &lt;&lt; "Cannot write header to stream: "
                            &lt;&lt; av_make_error_string(errorLog, 128, errorStatus) &lt;&lt; endl;
                       return -1;
                   }


                   /******stream*******/

                   FILE *fp_yuv = NULL;
                   fp_yuv=fopen("output.yuv","wb+");

                   // Read frames and save first five frames to disk
                   i=0;

                   while(av_read_frame(pFormatCtx, &amp;packet)>=0) {
                   // Is this a packet from the video stream?
                       if(packet.stream_index==videoStream) {

                           // Decode video frame
                           avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);

                           // Did we get a video frame?
                           if(frameFinished) {

                               AVPacket Outpacket;
                               int got_packet_ptr;
                               av_init_packet(&amp;Outpacket);
                               Outpacket.data = NULL;
                               Outpacket.size = 0;
                               int out_size = avcodec_encode_video2(nv_codec_context, &amp;Outpacket, pFrame, &amp;got_packet_ptr);
                               Outpacket.pts = av_rescale_q(pFrame->pts, m_stream->codec->time_base, m_stream->time_base);

                               fwrite(Outpacket.data,1,Outpacket.size,fp_yuv);

                               //av_write_frame(m_formatContext, &amp;Outpacket);
                               av_interleaved_write_frame(m_formatContext, &amp;Outpacket);

                               //Free the packet that was allocated by encoder
                               av_packet_unref(&amp;Outpacket);
                     }
                   }

                   // Free the packet that was allocated by av_read_frame
                   av_packet_unref(&amp;packet);
                   }

                   fclose(fp_yuv);


                   // Free the YUV frame
                   av_frame_free(&amp;pFrame);

                   // Close the codecs
                   avcodec_close(pCodecCtx);
                   avcodec_close(pCodecCtxOrig);
                   avcodec_close(m_stream->codec);
                   avformat_free_context(m_formatContext);

                   // Close the video file
                   avformat_close_input(&amp;pFormatCtx);


                   return 0;
               }
    </string></iostream>

    Above is my code for decoding a .mp4 file, outputting to a network stream through RTP. But it does not work. On the client side, I call VLC library to decode the stream ( VlcMedia(url, _instance) where url is rtp/h264 ://@147.8.179.229:6666 ). When I change the protocal to UDP, it works. However, it is not stable. The frames jumps and probably the frame lost or something wrong with the pts setting ?

    Can anyone help ? Thanks very much.