Recherche avancée

Médias (0)

Mot : - Tags -/publication

Aucun média correspondant à vos critères n’est disponible sur le site.

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 (8697)

  • FFmpeg RTP example error

    20 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 ?

    UPDATED :

    When I use UDP, I got this error message.
    enter image description here

    When I use RTP, I got this error message :
    enter image description here

    Not sure about how to solve this problem, Can anyone help ? Thanks very much.

  • FFmpeg H264 RTP streaming error

    20 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 ?

    When I use UDP, I got this error message :
    enter image description here

    When I change it to RTP, I got this error message :
    enter image description here

    Not sure about how to solve this problem, Can anyone help ? Thanks very much.

  • How to find the memory leak in ios xcode ?

    12 août 2014, par Ajin Chacko

    It’s my RTSP streaming ios application with FFMPEG decoder and it streaming fine, But the memory continuously increasing while running. Please help me, Is it a memory leak ?. And how can I track the leak ?.

    Its my video streaming class : RTSPPlayer.m

    #import "RTSPPlayer.h"
    #import "Utilities.h"
    #import "AudioStreamer.h"

    @interface RTSPPlayer ()
    @property (nonatomic, retain) AudioStreamer *audioController;
    @end

    @interface RTSPPlayer (private)
    -(void)convertFrameToRGB;
    -(UIImage *)imageFromAVPicture:(AVPicture)pict width:(int)width height:(int)height;
    -(void)setupScaler;
    @end

    @implementation RTSPPlayer

    @synthesize audioController = _audioController;
    @synthesize audioPacketQueue,audioPacketQueueSize;
    @synthesize _audioStream,_audioCodecContext;
    @synthesize emptyAudioBuffer;

    @synthesize outputWidth, outputHeight;

    - (void)setOutputWidth:(int)newValue
    {
       if (outputWidth != newValue) {
           outputWidth = newValue;
           [self setupScaler];
       }
    }

    - (void)setOutputHeight:(int)newValue
    {
       if (outputHeight != newValue) {
           outputHeight = newValue;
           [self setupScaler];
       }
    }

    - (UIImage *)currentImage
    {
       if (!pFrame->data[0]) return nil;
       [self convertFrameToRGB];
       return [self imageFromAVPicture:picture width:outputWidth height:outputHeight];
    }

    - (double)duration
    {
       return (double)pFormatCtx->duration / AV_TIME_BASE;
    }

    - (double)currentTime
    {
       AVRational timeBase = pFormatCtx->streams[videoStream]->time_base;
       return packet.pts * (double)timeBase.num / timeBase.den;
    }

    - (int)sourceWidth
    {
       return pCodecCtx->width;
    }

    - (int)sourceHeight
    {
       return pCodecCtx->height;
    }

    - (id)initWithVideo:(NSString *)moviePath usesTcp:(BOOL)usesTcp
    {
       if (!(self=[super init])) return nil;

       AVCodec         *pCodec;

       // Register all formats and codecs
       avcodec_register_all();
       av_register_all();
       avformat_network_init();

       // Set the RTSP Options
       AVDictionary *opts = 0;
       if (usesTcp)
           av_dict_set(&amp;opts, "rtsp_transport", "tcp", 0);


       if (avformat_open_input(&amp;pFormatCtx, [moviePath UTF8String], NULL, &amp;opts) !=0 ) {
           av_log(NULL, AV_LOG_ERROR, "Couldn't open file\n");
           goto initError;
       }

       // Retrieve stream information
       if (avformat_find_stream_info(pFormatCtx,NULL) &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information\n");
           goto initError;
       }

       // Find the first video stream
       videoStream=-1;
       audioStream=-1;

       for (int i=0; inb_streams; i++) {
           if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
               NSLog(@"found video stream");
               videoStream=i;
           }

           if (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
               audioStream=i;
               NSLog(@"found audio stream");
           }
       }

       if (videoStream==-1 &amp;&amp; audioStream==-1) {
           goto initError;
       }

       // Get a pointer to the codec context for the video stream
       pCodecCtx = pFormatCtx->streams[videoStream]->codec;

       // Find the decoder for the video stream
       pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
       if (pCodec == NULL) {
           av_log(NULL, AV_LOG_ERROR, "Unsupported codec!\n");
           goto initError;
       }

       // Open codec
       if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0) {
           av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n");
           goto initError;
       }

       if (audioStream > -1 ) {
           NSLog(@"set up audiodecoder");
           [self setupAudioDecoder];
       }

       // Allocate video frame
       pFrame = avcodec_alloc_frame();

       outputWidth = pCodecCtx->width;
       self.outputHeight = pCodecCtx->height;

       return self;

    initError:
    //  [self release];
       return nil;
    }


    - (void)setupScaler
    {
       // Release old picture and scaler
       avpicture_free(&amp;picture);
       sws_freeContext(img_convert_ctx);  

       // Allocate RGB picture
       avpicture_alloc(&amp;picture, PIX_FMT_RGB24, outputWidth, outputHeight);

       // Setup scaler
       static int sws_flags =  SWS_FAST_BILINEAR;
       img_convert_ctx = sws_getContext(pCodecCtx->width,
                                        pCodecCtx->height,
                                        pCodecCtx->pix_fmt,
                                        outputWidth,
                                        outputHeight,
                                        PIX_FMT_RGB24,
                                        sws_flags, NULL, NULL, NULL);

    }

    - (void)seekTime:(double)seconds
    {
       AVRational timeBase = pFormatCtx->streams[videoStream]->time_base;
       int64_t targetFrame = (int64_t)((double)timeBase.den / timeBase.num * seconds);
       avformat_seek_file(pFormatCtx, videoStream, targetFrame, targetFrame, targetFrame, AVSEEK_FLAG_FRAME);
       avcodec_flush_buffers(pCodecCtx);
    }

    - (void)dealloc
    {
       // Free scaler
       sws_freeContext(img_convert_ctx);  

       // Free RGB picture
       avpicture_free(&amp;picture);

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

       // Free the YUV frame
       av_free(pFrame);

       // Close the codec
       if (pCodecCtx) avcodec_close(pCodecCtx);

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

       [_audioController _stopAudio];
      // [_audioController release];
       _audioController = nil;

     //  [audioPacketQueue release];
       audioPacketQueue = nil;

    //   [audioPacketQueueLock release];
       audioPacketQueueLock = nil;

    //  [super dealloc];
    }

    - (BOOL)stepFrame
    {
       // AVPacket packet;
       int frameFinished=0;

       while (!frameFinished &amp;&amp; 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);
           }

           if (packet.stream_index==audioStream) {
               // NSLog(@"audio stream");
               [audioPacketQueueLock lock];

               audioPacketQueueSize += packet.size;
               [audioPacketQueue addObject:[NSMutableData dataWithBytes:&amp;packet length:sizeof(packet)]];

               [audioPacketQueueLock unlock];

               if (!primed) {
                   primed=YES;
                   [_audioController _startAudio];
               }

               if (emptyAudioBuffer) {
                   [_audioController enqueueBuffer:emptyAudioBuffer];
               }
           }
       }

       return frameFinished!=0;
    }

    - (void)convertFrameToRGB
    {
       sws_scale(img_convert_ctx,
                 pFrame->data,
                 pFrame->linesize,
                 0,
                 pCodecCtx->height,
                 picture.data,
                 picture.linesize);
    }

    - (UIImage *)imageFromAVPicture:(AVPicture)pict width:(int)width height:(int)height
    {
       CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
       CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, pict.data[0], pict.linesize[0]*height,kCFAllocatorNull);
       CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
       CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
       CGImageRef cgImage = CGImageCreate(width,
                                          height,
                                          8,
                                          24,
                                          pict.linesize[0],
                                          colorSpace,
                                          bitmapInfo,
                                          provider,
                                          NULL,
                                          NO,
                                          kCGRenderingIntentDefault);
       CGColorSpaceRelease(colorSpace);
       UIImage *image = [UIImage imageWithCGImage:cgImage];

       CGImageRelease(cgImage);
       CGDataProviderRelease(provider);
       CFRelease(data);

       return image;
    }

    - (void)setupAudioDecoder
    {    
       if (audioStream >= 0) {
           _audioBufferSize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
           _audioBuffer = av_malloc(_audioBufferSize);
           _inBuffer = NO;

           _audioCodecContext = pFormatCtx->streams[audioStream]->codec;
           _audioStream = pFormatCtx->streams[audioStream];

           AVCodec *codec = avcodec_find_decoder(_audioCodecContext->codec_id);
           if (codec == NULL) {
               NSLog(@"Not found audio codec.");
               return;
           }

           if (avcodec_open2(_audioCodecContext, codec, NULL) &lt; 0) {
               NSLog(@"Could not open audio codec.");
               return;
           }

           if (audioPacketQueue) {
             //  [audioPacketQueue release];
               audioPacketQueue = nil;
           }        
           audioPacketQueue = [[NSMutableArray alloc] init];

           if (audioPacketQueueLock) {
           //    [audioPacketQueueLock release];
               audioPacketQueueLock = nil;
           }
           audioPacketQueueLock = [[NSLock alloc] init];

           if (_audioController) {
               [_audioController _stopAudio];
            //   [_audioController release];
               _audioController = nil;
           }
           _audioController = [[AudioStreamer alloc] initWithStreamer:self];
       } else {
           pFormatCtx->streams[audioStream]->discard = AVDISCARD_ALL;
           audioStream = -1;
       }
    }

    - (void)nextPacket
    {
       _inBuffer = NO;
    }

    - (AVPacket*)readPacket
    {
       if (_currentPacket.size > 0 || _inBuffer) return &amp;_currentPacket;

       NSMutableData *packetData = [audioPacketQueue objectAtIndex:0];
       _packet = [packetData mutableBytes];

       if (_packet) {
           if (_packet->dts != AV_NOPTS_VALUE) {
               _packet->dts += av_rescale_q(0, AV_TIME_BASE_Q, _audioStream->time_base);
           }

           if (_packet->pts != AV_NOPTS_VALUE) {
               _packet->pts += av_rescale_q(0, AV_TIME_BASE_Q, _audioStream->time_base);
           }

           [audioPacketQueueLock lock];
           audioPacketQueueSize -= _packet->size;
           if ([audioPacketQueue count] > 0) {
               [audioPacketQueue removeObjectAtIndex:0];
           }
           [audioPacketQueueLock unlock];

           _currentPacket = *(_packet);
       }

       return &amp;_currentPacket;  
    }

    - (void)closeAudio
    {
       [_audioController _stopAudio];
       primed=NO;
    }

    @end