Recherche avancée

Médias (3)

Mot : - Tags -/spip

Autres articles (46)

  • Keeping control of your media in your hands

    13 avril 2011, par

    The vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
    While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
    MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
    MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)

  • 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 (...)

  • 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 (...)

Sur d’autres sites (5335)

  • FFMPEG, leaking memory

    8 juin 2016, par Nyaruko

    I use the following code to open a MP4 file. Each time the MP4 file is opened successfully by calling QVideoDecoder::openFile(QString filename).
    The initCode is called at the beginning of the program.

    However, each time I run the openFile(QString filename) function on the same file. There are some memory leak. What is wrong with my code ?

    void QVideoDecoder::InitVars()
    {
       //Input
       //-------------------
       ok = false;
       pFormatCtx = 0;
       pCodecCtx = 0;
       pCodec = 0;
       pFrame = 0;
       pFrameRGB = 0;
       buffer = 0;
       img_convert_ctx = 0;
       th = 0;
    }

    void QVideoDecoder::close()
    {
      // Free the RGB image
      if(buffer)
         delete [] buffer;

      // Free the YUV frame
      if(pFrame)
         av_free(pFrame);

      // Free the RGB frame
      if(pFrameRGB)
         av_free(pFrameRGB);

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

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

      // Close the timeout handler
      if (th)
          delete th;

      InitVars();
    }

    bool QVideoDecoder::initCodec()
    {

      ffmpeg::avcodec_register_all();
      ffmpeg::av_register_all();
      ffmpeg::avdevice_register_all();
      ffmpeg::avformat_network_init();

      printf("License: %s\n",ffmpeg::avformat_license());
      printf("AVCodec version %d\n",ffmpeg::avformat_version());
      printf("AVFormat configuration: %s\n",ffmpeg::avformat_configuration());

      return true;
    }

    bool QVideoDecoder::openFile(QString filename)
    {
       // Close the last video
       //----------------------------------------------
       close();

       // Initialize the params
       // ---------------------------------------------
       ffmpeg::AVInputFormat *iformat = NULL;
       ffmpeg::AVDictionary *opts = NULL;          
       ffmpeg::av_dict_set(&opts, "rtsp_transport", "tcp", NULL);
       ffmpeg::av_dict_set(&opts, "rtbufsize", "102400", NULL);
       ffmpeg::av_dict_set(&opts, "allowed_media_types", "video", NULL);


       //set the timeout handler for pFormatCtx
       //----------------------------------------------
       pFormatCtx = ffmpeg::avformat_alloc_context();
       th = new timeout_handler(3000000);
       pFormatCtx->interrupt_callback.opaque = (void*)th;
       pFormatCtx->interrupt_callback.callback = &timeout_handler::check_interrupt;

       // Open video file
       //---------------------------------------------
       th->reset(3000000);
       avformat_open_input(&pFormatCtx, filename.toStdString().c_str(), iformat, &opts) != 0)
       av_dict_free(&opts);

       // Retrieve stream information
       //---------------------------------------------
       th->reset(3000000);
       avformat_find_stream_info(pFormatCtx, NULL);

       // Dump information about file onto standard error
       //---------------------------------------------
       av_dump_format(pFormatCtx, 0, filename.toStdString().c_str(), false);

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

       // 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);

       // Set thread type to 0 seems decrease the amount of delay
       //--------------------------------------------
       pCodecCtx->thread_type = 0;
    // Open codec
    //--------------------------------------------
    avcodec_open2(pCodecCtx, pCodec, NULL);

    // Allocate video frame
    //--------------------------------------------
    pFrame = ffmpeg::avcodec_alloc_frame();

    // Allocate an AVFrame structure
    //--------------------------------------------
    pFrameRGB = ffmpeg::avcodec_alloc_frame();

    // Determine required buffer size and allocate buffer
    //--------------------------------------------
    numBytes = ffmpeg::avpicture_get_size(ffmpeg::PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
    buffer = new uint8_t[numBytes];

    // Assign appropriate parts of buffer to image planes in pFrameRGB
    //--------------------------------------------
    avpicture_fill((ffmpeg::AVPicture *)pFrameRGB, buffer, ffmpeg::PIX_FMT_RGB24,
       pCodecCtx->width, pCodecCtx->height);

    return true;
    }
  • libopusenc : Add channel mapping family argument

    15 juin 2016, par Michael Graczyk
    libopusenc : Add channel mapping family argument
    

    The default value of -1 indicates that ffmpeg should determine the channel
    mapping automatically, which was the behavior before this commit.

    Unless the -mapping_family argument is provided, behavior is unchanged.

    Signed-off-by : Michael Niedermayer <michael@niedermayer.cc>

    • [DH] doc/encoders.texi
    • [DH] libavcodec/libopusenc.c
  • Could not open encoder using ffmpeg C APi for MOV format

    22 juin 2016, par lupod

    Context

    I am writing a program for doing some video processing on an input file. I wrote two classes for handling the "reading/writing frames" part that essentially wrap the functions of ffmpeg. These classes may be instantiated by providing an input and output file name, and in their constructor I initialize everything that is needed (or at least I hope so).

    This are the two routines that are called inside the constructors :

    // InputVideoHandler.cpp
    void InputVideoHandler::init(char* name) {
     streamIndex = -1;
     int numStreams;

     if (avformat_open_input(&amp;formatCtx, name, NULL, NULL) != 0)
       throw std::exception("Invalid input file name.");

     if (avformat_find_stream_info(formatCtx, NULL)&lt;0)
       throw std::exception("Could not find stream information.");

     numStreams = formatCtx->nb_streams;

     if (numStreams &lt; 0)
       throw std::exception("No streams in input video file.");

     for (int i = 0; i &lt; numStreams; i++) {
       if (formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
         streamIndex = i;
         break;
       }
     }

     if (streamIndex &lt; 0)
       throw std::exception("No video stream in input video file.");

     // find decoder using id
     codec = avcodec_find_decoder(formatCtx->streams[streamIndex]->codec->codec_id);
     if (codec == nullptr)
       throw std::exception("Could not find suitable decoder for input file.");

     // copy context from input stream
     codecCtx = avcodec_alloc_context3(codec);
     if (avcodec_copy_context(codecCtx, formatCtx->streams[streamIndex]->codec) != 0)
       throw std::exception("Could not copy codec context from input stream.");

     if (avcodec_open2(codecCtx, codec, NULL) &lt; 0)
       throw std::exception("Could not open decoder.");

     codecCtx->refcounted_frames = 1;
    }

    // OutputVideoBuilder.cpp
    void OutputVideoBuilder::init(char* name, AVCodecContext* inputCtx) {
     if (avformat_alloc_output_context2(&amp;formatCtx, NULL, NULL, name) &lt; 0)
       throw std::exception("Could not determine file extension from provided name.");

     codec = avcodec_find_encoder(inputCtx->codec_id);
     if (codec == nullptr) {
       throw std::exception("Could not find suitable encoder.");
     }

     codecCtx = avcodec_alloc_context3(codec);
     if (avcodec_copy_context(codecCtx, inputCtx) &lt; 0)
       throw std::exception("Could not copy output codec context from input");

     codecCtx->time_base = inputCtx->time_base;

     if (avcodec_open2(codecCtx, codec, NULL) &lt; 0)
       throw std::exception("Could not open encoder.");

     stream = avformat_new_stream(formatCtx, codec);
     if (stream == nullptr) {
       throw std::exception("Could not allocate stream.");
     }

     stream->id = formatCtx->nb_streams - 1;
     stream->codec = codecCtx;
     stream->time_base = codecCtx->time_base;

     av_dump_format(formatCtx, 0, name, 1);
     if (!(formatCtx->oformat->flags &amp; AVFMT_NOFILE)) {
       if (avio_open(&amp;formatCtx->pb, name, AVIO_FLAG_WRITE) &lt; 0) {
         throw std::exception("Could not open output file.");
       }
     }

     if (avformat_write_header(formatCtx, NULL) &lt; 0) {
       throw std::exception("Error occurred when opening output file.");
     }

    }

    As you see, for the Init function of the output handler I require that an AVCodecContext must be provided. In my code, I pass to the constructor the AVCodecContext that is stored in the input handler and that was previously created.

    Question :

    The two functions work fine when I test my program with some video formats, like .mpg or .avi. When I try to process .mov/.mp4 files, however, my code throws the exception that I labeled "Could not open encoder." in OutputVideoBuilder::Init(). Why is this happening ? I read from the General documentation of ffmpeg that that format should be supported as well by ffmpeg. I am assuming that I am doing something wrong in my code, which I do not completely understand because it was created by trying to adapt the tutorials of the documentation to my specific case. Also for this reason, any comments on things that are useless or things that are missing will be greatly appreciated.