Recherche avancée

Médias (91)

Autres articles (103)

  • ANNEXE : Les plugins utilisés spécifiquement pour la ferme

    5 mars 2010, par

    Le site central/maître de la ferme a besoin d’utiliser plusieurs plugins supplémentaires vis à vis des canaux pour son bon fonctionnement. le plugin Gestion de la mutualisation ; le plugin inscription3 pour gérer les inscriptions et les demandes de création d’instance de mutualisation dès l’inscription des utilisateurs ; le plugin verifier qui fournit une API de vérification des champs (utilisé par inscription3) ; le plugin champs extras v2 nécessité par inscription3 (...)

  • Qu’est ce qu’un éditorial

    21 juin 2013, par

    Ecrivez votre de point de vue dans un article. Celui-ci sera rangé dans une rubrique prévue à cet effet.
    Un éditorial est un article de type texte uniquement. Il a pour objectif de ranger les points de vue dans une rubrique dédiée. Un seul éditorial est placé à la une en page d’accueil. Pour consulter les précédents, consultez la rubrique dédiée.
    Vous pouvez personnaliser le formulaire de création d’un éditorial.
    Formulaire de création d’un éditorial Dans le cas d’un document de type éditorial, les (...)

  • Activation de l’inscription des visiteurs

    12 avril 2011, par

    Il est également possible d’activer l’inscription des visiteurs ce qui permettra à tout un chacun d’ouvrir soit même un compte sur le canal en question dans le cadre de projets ouverts par exemple.
    Pour ce faire, il suffit d’aller dans l’espace de configuration du site en choisissant le sous menus "Gestion des utilisateurs". Le premier formulaire visible correspond à cette fonctionnalité.
    Par défaut, MediaSPIP a créé lors de son initialisation un élément de menu dans le menu du haut de la page menant (...)

Sur d’autres sites (11604)

  • sws/output/yuv2gbrp_full_X_c() : silence warning about uninitialized variable

    10 mai 2013, par Michael Niedermayer
    sws/output/yuv2gbrp_full_X_c() : silence warning about uninitialized variable
    

    clang did not show this one, so i missed it in the last batch

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

    • [DH] libswscale/output.c
  • Why do I get a crash only sometimes when closing input file with ffmpeg

    1er mai 2013, par Bradley

    I have a problem where only sometimes when I call avformat_close_input(&amp;pFormatCtx) and it results in malloc check failed and my application crashes.

    I really need to use ffmpeg because I need to grab a thumbnail of a video to show in a list and I cannot find an alternative library.

    Can anybody see something in my code where I am doing something wrong when using this library which may cause this malloc check failed problem ?

    bool MuteCamera::PullFrame(  )
    {



    pMJPEGCodec  = avcodec_find_encoder(CODEC_ID_MJPEG );


    bool bRet = false;
    int videoStream   = -1;
    AVFrame *pFrame=NULL;
    AVFrame *pFrameRGB=NULL;
    AVPacket packet;
    int frameFinished=0;

    //AVDictionary *optionsDict = NULL;
    AVInputFormat   *pFormat = NULL;
    const char      formatName[] = "mp4";

    if (!(pFormat = av_find_input_format(formatName))) {
       printf("can&#39;t find input format %s\n", formatName);
       return -1;
    }

    AVFormatContext *pFormatCtx = NULL;
    pFormatCtx=avformat_alloc_context();

    if(pFormatCtx == NULL)
    {
       printf("\n NULL CONTEXT \n ");
       return -1;
    }
    if(avformat_open_input (&amp;pFormatCtx, capturedUrl.data(), pFormat, NULL) == 0 )
    {
       for(int i=0; i&lt;(int)pFormatCtx->nb_streams; i++)
       {
           if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
           {
               videoStream=i;
               break;
           }
       }
       if(videoStream >= 0 )
       {
           AVCodecContext *pCodecCtx = pFormatCtx->streams[videoStream]->codec;
           AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
           if(pCodec != NULL)
           {
               if( avcodec_open2(pCodecCtx, pCodec, NULL) >= 0 )
               {

                   pFrame=avcodec_alloc_frame();

                   if(pFrame != NULL)
                   {


                       frameFinished = 0;

                       while(av_read_frame(pFormatCtx, &amp;packet)>=0)
                       {


                           if(packet.stream_index==videoStream)
                           {

                               avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);

                               if(frameFinished)
                               {

                                   printf("\n FRAMEFINISHED \n ");
                                   QString *uu = new QString(capturedUrl.data());//
                                   uu->replace(".mp4", "thumbnail.jpg");
                                   WriteJPEG(pCodecCtx, pFrame, uu->toLatin1().data(), PIX_FMT_YUVJ420P);

                                   if(viewingVideos &amp;&amp; viewingFromDifferent)
                                   {
                                       QVariantMap map = QVariantMap();
                                       map["title"] = actualFilename;

                                       map["path"] =  actualFilename.replace(".mp4", "thumbnail.jpg");// QString("asset:///white_photo.png");
                                       m_listDataModel &lt;&lt; map;

                                   }
                                   delete uu;
                                   av_free_packet(&amp;packet);
                                   break;



                               }
                               else
                               {
                                   printf("\n FRAMENOTFINISHED \n ");
                               }
                           }
                           av_free_packet(&amp;packet);

                       }




                       av_free(pFrameRGB);

                       av_free(pFrame);

                       avcodec_close(pCodecCtx);
                       //av_free(pCodecCtx);
                       cout &lt;&lt; "\n before free formatctx \n";
                       cout.flush();
                       if(pFormatCtx)
                           avformat_close_input(&amp;pFormatCtx);
                       cout &lt;&lt; "\n after free formatctx \n";
                       cout.flush();

                   }
                   else
                       bRet = false;





               }
               else
                   bRet = false;
           }
           else
               bRet = false;
       }
       else
           bRet = false;





    }


    return bRet;
    }


    bool WriteJPEG (AVCodecContext *pCodecCtx, AVFrame *pFrame, char cFileName[], PixelFormat pix)
       {
    int complete = 0;
    bool bRet = false;
    int out_buf_size;
    uint8_t *out_buf;

    AVCodecContext *pMJPEGCtx = avcodec_alloc_context3(pMJPEGCodec);
    if( pMJPEGCtx )
    {
       pMJPEGCtx->bit_rate = pCodecCtx->bit_rate;
       pMJPEGCtx->width = pCodecCtx->width;
       pMJPEGCtx->height = pCodecCtx->height;
       pMJPEGCtx->pix_fmt = pix;
       pMJPEGCtx->codec_id = CODEC_ID_MJPEG;
       pMJPEGCtx->codec_type = AVMEDIA_TYPE_VIDEO;
       pMJPEGCtx->time_base.num = pCodecCtx->time_base.num;
       pMJPEGCtx->time_base.den = pCodecCtx->time_base.den;
       pMJPEGCtx->time_base= (AVRational){1,29.7};




       if( pMJPEGCodec &amp;&amp; (avcodec_open2( pMJPEGCtx, pMJPEGCodec, NULL) >= 0) )
       {

            AVFrame *oframe;
           oframe = avcodec_alloc_frame();

           if(oframe == NULL)
           {
               printf("\n (oframe == NULL");
               fflush(stdout);
           }


           /* calculate the bytes needed for the output image and create buffer for the output image */
           out_buf_size = avpicture_get_size(pMJPEGCtx->pix_fmt,
                   pMJPEGCtx->width,
                   pMJPEGCtx->height);
           out_buf = (uint8_t *)av_malloc(out_buf_size * sizeof(uint8_t));
           if (out_buf == NULL) {
               fprintf(stderr, "cannot allocate output data buffer!\n");
               //ret = -ENOMEM;

           }

           avpicture_alloc((AVPicture *)oframe, pMJPEGCtx->pix_fmt, pMJPEGCtx->width, pMJPEGCtx->height);

           struct SwsContext *sws;
           sws = sws_getContext(pMJPEGCtx->width, pMJPEGCtx->height, pCodecCtx->pix_fmt,
                   pMJPEGCtx->width, pMJPEGCtx->height, pMJPEGCtx->pix_fmt, SWS_BILINEAR,
                   NULL, NULL, NULL);

           sws_scale(sws, (const uint8_t **)pFrame->data, pFrame->linesize,
                   0, pMJPEGCtx->height, &amp;oframe->data[0], &amp;oframe->linesize[0]);
           sws_freeContext(sws);





           AVPacket pp2;
           av_init_packet(&amp;pp2);
           pp2.data = NULL;
           pp2.size = 0;
           avcodec_encode_video2(pMJPEGCtx, &amp;pp2,  oframe, &amp;complete);
           if(complete)
           {
               printf("\n packet recieved");
               fflush(stdout);
           }
           else
           {
               printf("\n packet NOT recieved");
               fflush(stdout);
           }

           if( SaveFrameJpeg(pp2.size, pp2.data, cFileName ) )
               bRet = true;

               av_free(oframe);



               avcodec_close(pMJPEGCtx);

           av_free_packet(&amp;pp2);
           av_free(out_buf);

               av_free(pMJPEGCtx);


       }
       else
       {
           printf("\n problem!!");
           fflush(stdout);
       }

       return bRet;
    }
    }

    bool SaveFrameJpeg(int nszBuffer, uint8_t *buffer, char cOutFileName[])
    {
    bool bRet = false;
    FILE *pFile;
    if( nszBuffer > 0 )
    {

       if(0 == 0 )
       {
           printf("\n start SaveFrameJpeg=%d",nszBuffer );
           fflush(stdout);
           pFile= fopen(cOutFileName, "wb");
           fwrite(buffer, sizeof(uint8_t), nszBuffer, pFile);
           bRet = true;
           fclose(pFile);
           printf("\n end SaveFrameJpeg=%d",nszBuffer );
           fflush(stdout);
       }
    }
    return bRet;
    }


    bool newPullFrame(const std::string&amp; capturedUrl)
    {

    AVCodec* pMJPEGCodec  = avcodec_find_encoder(CODEC_ID_MJPEG );

    int videoStream   = -1;

    AVDictionary *optionsDict = NULL;
    AVInputFormat   *pFormat = NULL;
    const char      formatName[] = "mp4";

    if (!(pFormat = av_find_input_format(formatName)))
    {
       std::cout &lt;&lt; "can&#39;t find input format " &lt;&lt; formatName &lt;&lt; "\n";
       return false;
    }

    AVFormatContextHandle FormatCtx(avformat_alloc_context());

    if(!FormatCtx.is_valid())
    {
       std::cout &lt;&lt; "\n NULL CONTEXT \n ";
       return false;
    }

    if(avformat_open_input (&amp;FormatCtx, capturedUrl.c_str(), pFormat, NULL))
       return false;

    for(int i=0; i&lt;(int)FormatCtx->nb_streams; i++)
    {
       if(FormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
       {
           videoStream=i;
           break;
       }
    }
    if(videoStream &lt; 0 )
       return false;

    CodecContextHandle CodecCtx(FormatCtx->streams[videoStream]->codec, avcodec_close);
    AVCodec *pCodec = avcodec_find_decoder(CodecCtx->codec_id);

    if(pCodec == NULL)
       return false;

    if( avcodec_open2(CodecCtx, pCodec, &amp;optionsDict) &lt; 0 )
       return false;

    FrameHandle Frame(avcodec_alloc_frame(), av_free);

    if(!Frame.is_valid())
       return false;

    int frameFinished=0;
    AVPacket packet;

    while(av_read_frame(FormatCtx, &amp;packet)>=0)
    {

       if(packet.stream_index==videoStream)
       {
           avcodec_decode_video2(CodecCtx, Frame, &amp;frameFinished, &amp;packet);

           if(frameFinished)
           {

               std::string uu (capturedUrl);
               size_t pos = capturedUrl.rfind(".mp4");
               uu.replace(pos, 4, "thumbnail.jpg");
               // save the frame to file
               int Bytes = avpicture_get_size(PIX_FMT_YUVJ420P, CodecCtx->width, CodecCtx->height);
               BufferHandle buffer((uint8_t*)av_malloc(Bytes*sizeof(uint8_t)), av_free);
               CodecContextHandle OutContext(avcodec_alloc_context3(NULL), free_context);

               OutContext->bit_rate = CodecCtx->bit_rate;

               OutContext->width = CodecCtx->width;
               OutContext->height = CodecCtx->height;
               OutContext->pix_fmt = PIX_FMT_YUVJ420P;
               OutContext->codec_id = CODEC_ID_MJPEG;
               OutContext->codec_type = AVMEDIA_TYPE_VIDEO;
               OutContext->time_base.num = CodecCtx->time_base.num;
               OutContext->time_base.den = CodecCtx->time_base.den;
               OutContext->time_base= (AVRational){1,29.7};
               AVCodec *OutCodec = avcodec_find_encoder(OutContext->codec_id);
               avcodec_open2(OutContext, OutCodec, NULL);
               OutContext->mb_lmin = OutContext->lmin = OutContext->qmin * 118;
               OutContext->mb_lmax = OutContext->lmax = OutContext->qmax * 118;
               OutContext->flags = 2;
               OutContext->global_quality = OutContext->qmin * 118;
               Frame->pts = 1;

               Frame->quality = OutContext->global_quality;

               int ActualSize = avcodec_encode_video(OutContext, buffer, Bytes, Frame);

               std::ofstream file(uu.data(), std::ios_base::binary | std::ios_base::out);
               file.write((const char*)(uint8_t*)buffer, ActualSize);
               file.close();
               av_free_packet(&amp;packet);
               av_free(Frame);
               break;
           }
           else
           {
               std::cout &lt;&lt; " new pullframe frameNOTfinished\n";
                               cout.flush();
           }
           //if(CodecCtx->refcounted_frames == 1)

               av_free(Frame);

       }
       av_free_packet(&amp;packet);
    }

    return true;
    }
  • Transcoding & displaying user-uploaded videos for cross-browser/platform compatibility

    5 avril 2012, par Jonathan Amend

    I want to display user-uploaded videos in high quality on different browsers/platforms. I think I have a pretty good start, but there are a few issues. I have at my disposal ffmpeg 0.10 (called from PHP) and jwPlayer 5.8 (licensed).

    Ideally I would like to support :

    • Browsers with Flash 9+
    • Modern Firefox/Chrome/Safari without Flash
    • iOS 4.1+
    • Android 2.2+

    My current transcoding commands are :

    $commands = array(
       &#39;flv&#39; => "/usr/bin/ffmpeg -y -i {$sourceFile} -b 500k -ar 22050 -ab 64 {$tmpFileName}.flv 2>&amp;1",
       &#39;webm&#39; => "/usr/bin/ffmpeg -i {$sourceFile} -acodec libvorbis -ac 2 -ab 96k -ar 44100 -b 500k {$tmpFileName}.webm 2>&amp;1",
       &#39;mp4&#39; => "/usr/bin/ffmpeg -i {$sourceFile} -acodec libfaac -ab 96k -vcodec libx264 -level 21 -refs 2 -vf &#39;scale=trunc(ih*a/2)*2:trunc(iw/a/2)*2&#39; -b 500k -bt 1000k -threads 0 -f mp4 {$tmpFileName}.pre.mp4 2>&amp;1",
       &#39;jpg&#39; => "/usr/bin/ffmpeg -y -i {$sourceFile} -ss 5 -vcodec mjpeg -vframes 1 -an -f rawvideo {$tmpFileName}.jpg 2>&amp;1"
    );

    $fastStartCommand = "/usr/bin/qt-faststart {$tmpFileName}.pre.mp4 {$tmpFileName}.mp4");

    My current display code is this :

    <video controls="controls" width="{$width}" height="{$height}" poster="{$fileJPG}" style="width: {$width}px; height: {$height}px;">
       <source src="{$fileMP4}" type="video/mp4" data-ext="mp4"></source>
       <source src="{$fileWEBM}" type="video/webm" data-ext="webm"></source>
       <a href="http://stackoverflow.com/feeds/tag/{$fileMP4}" title="Play Video">
           <img border="0" src="http://stackoverflow.com/feeds/tag/{$fileJPG}" width='0' height='0' alt="Play Video" />
       </a>
    </video>
    <code class="echappe-js">&lt;script type=&quot;text/javascript&quot;&gt;<br />
    swfobject.embedSWF(<br />
       &amp;#39;/flash/jwPlayer.swf&amp;#39;,<br />
       &amp;#39;video&amp;#39;,<br />
       {$width},<br />
       {$height},<br />
       &amp;#39;9.0.0&amp;#39;,<br />
       &amp;#39;&amp;#39;,<br />
       {<br />
           file: &amp;#39;{$fileFLV}&amp;#39;,<br />
           width: {$width},<br />
           height: {$height},<br />
           provider: &amp;#39;video&amp;#39;,<br />
           stretching: &amp;#39;uniform&amp;#39;,<br />
           smoothing: &amp;#39;true&amp;#39;,<br />
           dock: &amp;#39;true&amp;#39;<br />
       },<br />
       {<br />
           menu: &amp;#39;false&amp;#39;,<br />
           allowfullscreen: &amp;#39;true&amp;#39;,<br />
           allowscriptaccess: &amp;#39;always&amp;#39;,<br />
           allownetworking: &amp;#39;always&amp;#39;,<br />
           wmode: &amp;#39;transparent&amp;#39;<br />
       }<br />
    );<br />
    &lt;/script&gt;

    The idea is to prefer the Flash player (we have many custom skins that we would like to keep using), then fall back to HTML 5 video, and if that fails, show the JPEG with a link to the mp4 file (that seems to work as a last-ditch effort for iOS 2/3 and old browsers so they can at least play the video by launching QuickTime).

    The main issues that I'm not sure how to solve right now are :

    • How can I show a higher quality video in Flash ? I tried using the mp4 video instead of the flv but it doesn't work and I only get sound, no video. I think Flash is supposed to support h.264 these days, but how ? And do I have to use a different transcoding method for older and newer versions of Flash ?
    • How can I transcode the video with better quality ? Right now I am using the same bitrate for all resolutions. Any chance there is a way for ffmpeg to adjust the bitrate automatically ? Or can I detect and match the resolution of the uploaded video to a list of resolution -> bitrates somehow ?