Recherche avancée

Médias (39)

Mot : - Tags -/audio

Autres articles (78)

  • Dépôt de média et thèmes par FTP

    31 mai 2013, par

    L’outil MédiaSPIP traite aussi les média transférés par la voie FTP. Si vous préférez déposer par cette voie, récupérez les identifiants d’accès vers votre site MédiaSPIP et utilisez votre client FTP favori.
    Vous trouverez dès le départ les dossiers suivants dans votre espace FTP : config/ : dossier de configuration du site IMG/ : dossier des média déjà traités et en ligne sur le site local/ : répertoire cache du site web themes/ : les thèmes ou les feuilles de style personnalisées tmp/ : dossier de travail (...)

  • Qualité du média après traitement

    21 juin 2013, par

    Le bon réglage du logiciel qui traite les média est important pour un équilibre entre les partis ( bande passante de l’hébergeur, qualité du média pour le rédacteur et le visiteur, accessibilité pour le visiteur ). Comment régler la qualité de son média ?
    Plus la qualité du média est importante, plus la bande passante sera utilisée. Le visiteur avec une connexion internet à petit débit devra attendre plus longtemps. Inversement plus, la qualité du média est pauvre et donc le média devient dégradé voire (...)

  • Le plugin : Podcasts.

    14 juillet 2010, par

    Le problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
    Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
    Types de fichiers supportés dans les flux
    Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...)

Sur d’autres sites (6466)

  • conversion from cv::mat to avframe

    14 novembre 2014, par danics

    i create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance !

    void processToFrame(cv::Mat* _mat, AVFrame* oframe)
     {
         // Create and allocate the conversion frame.
         if (_oframe == nullptr) {
             _oframe = avcodec_alloc_frame();  
             if (_oframe == nullptr)
                 throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");

             avpicture_alloc(reinterpret_cast(_oframe),
                 PIX_FMT_BGR24, _mat->cols, _mat->rows);            
         }

         avpicture_fill(reinterpret_cast(_oframe),
             (uint8_t *)_mat->data,
             AV_PIX_FMT_BGR24,
             _mat->cols,
             _mat->rows);

         // Convert the image from its native format to BGR.
         if (_convCtx == nullptr) {
             _convCtx = sws_getContext(
                 oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
                 _oframe->width, _oframe->height, PIX_FMT_BGR24,
                 SWS_BICUBIC, nullptr, nullptr, nullptr);
         }
         if (_convCtx == nullptr)
             throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");  

         // Scales the source data according to our SwsContext settings.
         if (sws_scale(_convCtx,
             _oframe->data, _oframe->linesize, 0, _oframe->height,
             oframe->data, oframe->linesize) < 0)
             throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
     }

    edit : create oframe

    void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
     {
         /* find the mpeg1 video encoder */
         if(codec == nullptr)
         {
             /* find the mpeg1 video encoder */
             codec = avcodec_find_encoder((AVCodecID)codec_id);
             if (!codec) {
                 throw std::runtime_error("codec not found\n");
             }
         }

         if(c == nullptr)
         {
             c = avcodec_alloc_context3(codec);
             if(!c)
             {
                 throw std::runtime_error("Could not allocate video codec context\n");
             }
             /* put sample parameters */
             c->bit_rate = 400000;
             /* resolution must be a multiple of two */
             c->width = 2 * (w / 2);
             c->height = 2 * (h / 2);
             /* frames per second */
             AVRational ar;
             ar.den = 1;
             ar.num = fps;

             c->time_base= ar; //(AVRational){1,25};
             c->gop_size = 10; /* emit one intra frame every ten frames */
             c->max_b_frames=1;
             c->pix_fmt = PIX_FMT_YUV420P;

             if(codec_id == AV_CODEC_ID_H264)
                 av_opt_set(c->priv_data, "preset", "slow", 0);

             /* open it */
             if (avcodec_open2(c, codec, NULL) < 0) {
                 throw std::runtime_error("Could not open codec\n");
             }

             f = fopen(filename, "wb");
             if (!f) {
                 throw std::runtime_error("could not open file\n");
             }

             frame = avcodec_alloc_frame();
             if (!frame) {
                 throw std::runtime_error("Could not allocate video frame\n");
             }
             frame->format = c->pix_fmt;
             frame->width  = c->width;
             frame->height = c->height;

             /* the image can be allocated by any means and av_image_alloc() is
              * just the most convenient way if av_malloc() is to be used */

             int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

             if (ret < 0) {
                 throw std::runtime_error("Could not allocate raw picture buffer\n");
             }
         }
    }

    read mat images

    void video_encode_example(const cv::Mat& fin)
    {
       AVPacket pkt;
       /* encode 1 second of video */
       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);

       cv::Mat res;
       cv::resize(fin, res, cv::Size(c->width, c->height));

       processToFrame(&res, frame);
       frame->pts = i;

       /* encode the image */
       int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
       throw std::runtime_error("Error encoding frame\n");
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
       i++;
       /* get the delayed frames */
       /*for (got_output = 1; got_output; i++) {
           fflush(stdout);

           ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
           if (ret < 0) {
               throw std::runtime_error("Error encoding frame\n");
           }

           if (got_output) {
               printf("Write frame %3d (size=%5d)\n", i, pkt.size);
               fwrite(pkt.data, 1, pkt.size, f);
               av_free_packet(&pkt);
           }
       }*/
    }
  • conversion from cv::mat to avframe, encode in h264 dont writing correctly [on hold]

    15 novembre 2014, par danics

    i create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance ! ((i solve this)) but i have another probelm in end of this question please

    void processToFrame(cv::Mat* _mat, AVFrame* oframe)
     {
         // Create and allocate the conversion frame.
         if (_oframe == nullptr) {
             _oframe = avcodec_alloc_frame();  
             if (_oframe == nullptr)
                 throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");

             avpicture_alloc(reinterpret_cast(_oframe),
                 PIX_FMT_BGR24, _mat->cols, _mat->rows);            
         }

         avpicture_fill(reinterpret_cast(_oframe),
             (uint8_t *)_mat->data,
             AV_PIX_FMT_BGR24,
             _mat->cols,
             _mat->rows);

         // Convert the image from its native format to BGR.
         if (_convCtx == nullptr) {
             _convCtx = sws_getContext(
                 oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
                 _oframe->width, _oframe->height, PIX_FMT_BGR24,
                 SWS_BICUBIC, nullptr, nullptr, nullptr);
         }
         if (_convCtx == nullptr)
             throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");  

         // Scales the source data according to our SwsContext settings.
         if (sws_scale(_convCtx,
             _oframe->data, _oframe->linesize, 0, _oframe->height,
             oframe->data, oframe->linesize) < 0)
             throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
     }

    create oframe

    void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
     {
         /* find the mpeg1 video encoder */
         if(codec == nullptr)
         {
             /* find the mpeg1 video encoder */
             codec = avcodec_find_encoder((AVCodecID)codec_id);
             if (!codec) {
                 throw std::runtime_error("codec not found\n");
             }
         }

         if(c == nullptr)
         {
             c = avcodec_alloc_context3(codec);
             if(!c)
             {
                 throw std::runtime_error("Could not allocate video codec context\n");
             }
             /* put sample parameters */
             c->bit_rate = 400000;
             /* resolution must be a multiple of two */
             c->width = 2 * (w / 2);
             c->height = 2 * (h / 2);
             /* frames per second */
             AVRational ar;
             ar.den = 1;
             ar.num = fps;

             c->time_base= ar; //(AVRational){1,25};
             c->gop_size = 10; /* emit one intra frame every ten frames */
             c->max_b_frames=1;
             c->pix_fmt = PIX_FMT_YUV420P;

             if(codec_id == AV_CODEC_ID_H264)
                 av_opt_set(c->priv_data, "preset", "slow", 0);

             /* open it */
             if (avcodec_open2(c, codec, NULL) < 0) {
                 throw std::runtime_error("Could not open codec\n");
             }

             f = fopen(filename, "wb");
             if (!f) {
                 throw std::runtime_error("could not open file\n");
             }

             frame = avcodec_alloc_frame();
             if (!frame) {
                 throw std::runtime_error("Could not allocate video frame\n");
             }
             frame->format = c->pix_fmt;
             frame->width  = c->width;
             frame->height = c->height;

             /* the image can be allocated by any means and av_image_alloc() is
              * just the most convenient way if av_malloc() is to be used */

             int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

             if (ret < 0) {
                 throw std::runtime_error("Could not allocate raw picture buffer\n");
             }
         }
    }

    read mat images

    void video_encode_example(const cv::Mat& fin)
    {
       AVPacket pkt;
       /* encode 1 second of video */
       av_init_packet(&pkt);
       pkt.data = NULL;    // packet data will be allocated by the encoder
       pkt.size = 0;

       fflush(stdout);

       cv::Mat res;
       cv::resize(fin, res, cv::Size(c->width, c->height));

       processToFrame(&res, frame);
       frame->pts = i;

       /* encode the image */
       int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
       if (ret < 0) {
       throw std::runtime_error("Error encoding frame\n");
       }

       if (got_output) {
           printf("Write frame %3d (size=%5d)\n", i, pkt.size);
           fwrite(pkt.data, 1, pkt.size, f);
           av_free_packet(&pkt);
       }
       i++;
    }

    update :

    i can solve the conversion problem by setting of _oframe.width = _mat.cols and _oframe.height = _mat.rows, avpicture_alloc dont set this value itself.

    now i have the other problem my videowriting class seems write ok because windows slideshow show one of frames, but i cant view video in my players, this is my release function, i dont know whats wrong endcoding or endcoder structure parameter like pts and else.

    void video_release()
       {
           /* get the delayed frames */
           for (got_output = 1; got_output; i++) {
               fflush(stdout);

               int ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
               if (ret < 0) {
                   throw std::runtime_error("Error encoding frame\n");
               }

               if (got_output) {
                   printf("Write frame %3d (size=%5d)\n", i, pkt.size);
                   fwrite(pkt.data, 1, pkt.size, f);
                   av_free_packet(&pkt);
               }
           }

           uint8_t endcode[] = { 0, 0, 1, 0xb7 };

           /* add sequence end code to have a real mpeg file */
           fwrite(endcode, 1, sizeof(endcode), f);
           fclose(f);

           avcodec_close(c);
           av_free(c);
           av_freep(&frame->data[0]);
           avcodec_free_frame(&frame);

           c = nullptr;
           codec = nullptr;
           frame = nullptr;

           if (_convCtx)
               sws_freeContext(_convCtx);

           if (_oframe) {
               //if (_oframe->data)
                   //av_free(_oframe->data[0]);
               av_free(_oframe);
           }

           _oframe = nullptr;
           _convCtx = nullptr;
       }
  • FFmpeg muxing to avi

    2 septembre 2015, par Uncia

    sI have program, that succefully shows h264 stream using SDL : I’m getting h264 frame, decode it using ffmpeg and draw using SDL.
    Also I can write frames to file (using fwrite) and play this file through ffplay.

    But I want to mux data to the avi and face some problems in av_write_frame.

    Here is my code :

    ...
    /*Initializing format context - outFormatContext is the member of my class*/
    AVOutputFormat *outFormat;
    outFormat = av_guess_format(NULL,"out.avi",NULL);
    outFormat->video_codec = AV_CODEC_ID_H264;
    outFormat->audio_codec = AV_CODEC_ID_NONE;
    avformat_alloc_output_context2(&outFormatContext, outFormat, NULL, "out.avi");
    AVCodec *outCodec;
    AVStream *outStream = add_stream(outFormatContext, &outCodec, outFormatContext->oformat->video_codec);
    avcodec_open2(outStream->codec, outCodec, NULL);
    av_dump_format(outFormatContext, 0, "out.avi", 1);
    if (avio_open(&outFormatContext->pb, "out.avi", AVIO_FLAG_WRITE) < 0)
       throw Exception("Couldn't open file");
    if (avformat_write_header(outFormatContext, NULL) < 0)
       throw Exception("Couldn't write to file");
    //I don't have exceptions here - so there is 6KB header in out.avi.
    ...

    static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec,
                           enum AVCodecID codec_id)
    {
    AVCodecContext *c;
    AVStream *st;
    /* find the encoder */
    *codec = avcodec_find_encoder(codec_id);
    if (!(*codec))
       throw("Could not find encoder");
    st = avformat_new_stream(oc, *codec);
    if (!st)
       throw ("Could not allocate stream");
    st->id = oc->nb_streams-1;
    c = st->codec;
    c->bit_rate = 400000;
    /* Resolution must be a multiple of two. */
    c->width    = 1920;
    c->height   = 1080;
    c->pix_fmt  = PIX_FMT_YUV420P;
    c->flags = 0;
    c->time_base.num = 1;
    c->time_base.den = 25;
    c->gop_size      = 12; /* emit one intra frame every twelve frames at most */
    return st;
    }
    ...
    /* Part of decoding loop. There is AVPacket packet - h264 packet;
    int ret = av_write_frame(outFormatContext, &packet); //it return -22 code - Invadlid argument;
    if (avcodec_decode_video2(pCodecCtx, pFrame, &frameDecoded, &packet) < 0)
       return;
    if (frameDecoded)
    {
      //SDL stuff
    }

    Also i tried to use avcodec_encode_video2 (encode pFrame back to the H264) next to the SDL stuff but encoding is not working - i’ve got empty packets :( It is the second problem.

    Using av_interleaved_write_frame causes acces violation.

    Code of the muxing part i copied from ffmpeg muxing example (https://www.ffmpeg.org/doxygen/2.1/doc_2examples_2muxing_8c-example.html)