Recherche avancée

Médias (1)

Mot : - Tags -/Christian Nold

Autres articles (66)

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

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

Sur d’autres sites (8899)

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