Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

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

Autres articles (102)

Sur d’autres sites (17313)

  • avcodec/mjpegdec : dont try to combine fields for decimated multiscope 2 material

    21 juin 2015, par Michael Niedermayer
    avcodec/mjpegdec : dont try to combine fields for decimated multiscope 2 material
    

    Fixes Ticket4535

    Signed-off-by : Michael Niedermayer <michaelni@gmx.at>

    • [DH] libavcodec/mjpegdec.c
    • [DH] libavcodec/mjpegdec.h
  • 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) &lt; 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) &lt; 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 &lt; 0) {
                 throw std::runtime_error("Could not allocate raw picture buffer\n");
             }
         }
    }

    read mat images

    void video_encode_example(const cv::Mat&amp; fin)
    {
       AVPacket pkt;
       /* encode 1 second of video */
       av_init_packet(&amp;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(&amp;res, frame);
       frame->pts = i;

       /* encode the image */
       int ret = avcodec_encode_video2(c, &amp;pkt, frame, &amp;got_output);
       if (ret &lt; 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(&amp;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, &amp;pkt, NULL, &amp;got_output);
               if (ret &lt; 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(&amp;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(&amp;frame->data[0]);
           avcodec_free_frame(&amp;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;
       }
  • find text cointain in folder name and skip it's

    27 février 2014, par pasaico
    for subdir in */ ; do
    cd $subdir
    ffmpeg -i mycode

    how do I exclude the ffmpeg command if the folder name contains foo ?

    i use command find, is correctly ?

    find . -name *foo* -print

    but I can not implement it in bash for loop.

    I tried this code :

    for subdir in */ ; do
    foo=$(find -type d -name &#39;*foo*&#39;)
    if [[ $subdir =~ $foo ] ; then
       echo yes
       ffmpeg -i mycode
    else
       echo no
    fi
    done