Recherche avancée

Médias (91)

Autres articles (38)

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (4884)

  • using ffmpeg as multiple downloads

    26 avril 2013, par user2321982

    well guys, I'm having problems with my application.
    well I'll explain more, I'm using the plugin uploader uploads multiple videos and I'm using the ffmpeg extension to my php version.

    <code class="echappe-js">&lt;script type=&quot;text/javascript&quot;&gt;<br />
    // Convert divs to queue widgets when the DOM is ready<br />
    $(function() {<br />
       $(&quot;#uploader&quot;).pluploadQueue({<br />
           // General settings<br />
           runtimes : &amp;#39;gears,flash,silverlight,browserplus,html5&amp;#39;,<br />
           url : &amp;#39;upload.php?id=&amp;lt;?= $login_usuario; ?&gt;&amp;amp;name=&amp;lt;?= $name_user; ?&gt;&amp;#39;,<br />
           flash_swf_url : &amp;#39;plugins/plupload/plupload.flash.swf&amp;#39;,<br />
           containers: &amp;#39;plupload&amp;#39;,<br />
           multipart: true,<br />
           urlstream_upload: true,<br />
           multipart_params:{directory:&amp;#39;uploads&amp;#39;},<br />
           multi_selection: true,<br />
    <br />
           max_file_size : &amp;#39;500mb&amp;#39;,<br />
           chunk_size : &amp;#39;1mb&amp;#39;,<br />
           unique_names : true,<br />
    <br />
           // Specify what files to browse for<br />
           filters : [<br />
               {title : &quot;Video Files&quot;, extensions : &quot;avi,mpg,wmv,flv,3gp,mpeg,mpeg4,mpg4,mp4&quot;}<br />
           ],<br />
           // Silverlight settings<br />
           silverlight_xap_url : &amp;#39;plugins/plupload/plupload.silverlight.xap&amp;#39;<br />
       });<br />
    <br />
       uploader.ini();<br />
    <br />
    // Client side form validation<br />
           $(&amp;#39;form&amp;#39;).submit(function(e) {<br />
               var uploader = $(&amp;#39;#uploader&amp;#39;).plupload(&amp;#39;getUploader&amp;#39;);<br />
    <br />
               // Files in queue upload them first<br />
               if (uploader.files.length &gt; 0) {<br />
                   // When all files are uploaded submit form<br />
                   uploader.bind(&amp;#39;StateChanged&amp;#39;, function() {<br />
                       if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {<br />
                           $(&amp;#39;form&amp;#39;)[0].submit();<br />
                       }<br />
                   });<br />
    <br />
                   uploader.start();<br />
               } else<br />
                   alert(&amp;#39;You must at least upload one file.&amp;#39;);<br />
    <br />
               return false;<br />
           });<br />
       });<br />
    &lt;/script&gt;

    You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.

    well he calls javascript in a php file, in case it will upload the videos.

    what I want is to get the length, resolution, file size and take a screenshot of the video randomly, so far so good, the problem is that it only works with only one upload at a time.
    When sending more than one he does the procedure with ffmpeg, besides the most is not taking a screenshot of the video.
    below is my code

    &lt;?php
    ini_set(&#39;max_execution_time&#39;, 300); //300 seconds = 5 minutes
    if (!extension_loaded (&#39;ffmpeg&#39;) ) exit ( &#39;ffmpeg não foi carregado!&#39; );
    // HTTP headers for no cache etc
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");

    include("includes/seguranca.php");
    include("includes/classes/class.mysql.php");
    include("includes/funcoes/sql_inject.php");

    $id_user = anti_injection($_GET[&#39;id&#39;]);
    session_start();

    // Settings
    //$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
    $targetDir = &#39;uploads/&#39;;

    //$cleanupTargetDir = false; // Remove old files
    //$maxFileAge = 60 * 60; // Temp file age in seconds

    // 5 minutes execution time
    @set_time_limit(5 * 60);

    // Uncomment this one to fake upload time
    // usleep(5000);

    // Get parameters
    $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
    $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
    $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : &#39;&#39;;

    // Clean the fileName for security reasons
    $fileName = preg_replace(&#39;/[^\w\._]+/&#39;, &#39;&#39;, $fileName);

    // Make sure the fileName is unique but only if chunking is disabled
    if ($chunks &lt; 2 &amp;&amp; file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) {
       $ext = strrpos($fileName, &#39;.&#39;);
       $fileName_a = substr($fileName, 0, $ext);
       $fileName_b = substr($fileName, $ext);

       $count = 1;
       while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . &#39;_&#39; . $count . $fileName_b))
           $count++;

       $fileName = $fileName_a . &#39;_&#39; . $count . $fileName_b;


    }

    // Create target dir
    if (!file_exists($targetDir))
       @mkdir($targetDir);

    // Look for the content type header
    if (isset($_SERVER["HTTP_CONTENT_TYPE"]))
       $contentType = $_SERVER["HTTP_CONTENT_TYPE"];

    if (isset($_SERVER["CONTENT_TYPE"]))
       $contentType = $_SERVER["CONTENT_TYPE"];

    // Handle non multipart uploads older WebKit versions didn&#39;t support multipart in HTML5
    if (strpos($contentType, "multipart") !== false) {
       if (isset($_FILES[&#39;file&#39;][&#39;tmp_name&#39;]) &amp;&amp; is_uploaded_file($_FILES[&#39;file&#39;][&#39;tmp_name&#39;])) {


           // Open temp file
           $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
           if ($out) {
               // Read binary input stream and append it to temp file
               $in = fopen($_FILES[&#39;file&#39;][&#39;tmp_name&#39;], "rb");

               if ($in) {
                   while ($buff = fread($in, 4096))
                       fwrite($out, $buff);
               } else
                   die(&#39;{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}&#39;);
               fclose($in);
               fclose($out);
               @unlink($_FILES[&#39;file&#39;][&#39;tmp_name&#39;]);



           } else
               die(&#39;{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}&#39;);
       } else
           die(&#39;{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}&#39;);
    } else {
       // Open temp file
       $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
       if ($out) {
           // Read binary input stream and append it to temp file
           $in = fopen("php://input", "rb");

           if ($in) {
               while ($buff = fread($in, 4096))
                   fwrite($out, $buff);
           } else
               die(&#39;{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}&#39;);

           fclose($in);
           fclose($out);
       } else
           die(&#39;{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}&#39;);
    }
    $photoName = $_FILES[&#39;file&#39;][&#39;name&#39;];

    $exploded_photoName = explode(&#39;.&#39;, $photoName);

    $user_id = $_SESSION[&#39;SESS_MEMBER_ID&#39;];

    if(!isset($_SESSION[$photoName])) {

       $_SESSION[$photoName] = &#39;1&#39;;
    }

    if($chunk==1){

    $movie_file = realpath("/uploads/".$fileName);

    // instancia a classe ffmpeg_movie para pegarmos as informações que queremos o vídeo
    $movie = new ffmpeg_movie($movie_file);
    // pegamos a duranção do video em segundos
    $duration = round ( $movie->getDuration() , 0 );
    // recebemos o número de frames do vídeo
    $totalFrames = $movie->getFrameCount();
    // recebemos a altura do vídeo em pixels
    $height = $movie->getFrameHeight ();
    // recebemos a largura do vídeo em pixels
    $width = $movie->getFrameWidth ();

    $thumbnailOf = $movie->getFrameRate() * 5;

    $thumbnailOf = round ( $movie->getFrameCount() / 2 );

    // precisamos criar uma imagem GD para o ffmpeg-php trabalhar nela
    $image = imagecreatetruecolor ($width,$height ) ;
    // criamos a instancia do frame com a classe ffmpeg_frame
    $frame = new ffmpeg_frame ($image);
    // escolhemos o frame que queremos salvar como jpeg
    $thumbnailOf = rand (1,$movie->getFrameCount());
    // recebe o frame
    $frame = $movie->getFrame ( $thumbnailOf );
    // converte para uma imagem GD
    $image = $frame->toGDImage ();

    $size = filesize("uploads/".$fileName);

    $valuea = rand(0,100);
    $valueb = rand(0,100);
    $valuec = rand(0,10);

    $nome = @md5(date(&#39;now&#39;) * $valuea - $valueb / $valuec);

    $dir = realpath("uploads/snapshots/$nome.jpg");
    //salva no HD.
    imagejpeg($image, $dir, 100);


    $resolu = $width."x".$height;

       mysql_query("INSERT INTO video
    (poster_id,duration,video,titulo,resolucao,tamanho)
       VALUES
    (&#39;$id_user&#39;,&#39;$duration&#39;,&#39;$fileName&#39;,&#39;$exploded_photoName[0]&#39;,&#39;$resolu&#39;,&#39;$size&#39;)") or die(mysql_error());

    }
    // Return JSON-RPC response
    die(&#39;{"jsonrpc" : "2.0", "result" : null, "id" : "id"}&#39;);

    ?>

    I did another method not so effective to do what I want but it only works if I open the page individually.

    I removed the code from ffmpeg extension and put an include to that page.

    &lt;?
    ini_set(&#39;max_execution_time&#39;, 300); //300 seconds = 5 minutes
    if (!extension_loaded (&#39;ffmpeg&#39;) ) exit ( &#39;ffmpeg não foi carregado!&#39; );

    include("includes/seguranca.php");
    include("includes/classes/class.mysql.php");
    include("includes/funcoes/sql_inject.php");

    $id_user = @anti_injection($_GET[&#39;id&#39;]);

    class process{
       public $videos;
       public $target;
       public $id_vid;

    public function screen(){

    $videos = $this->videos;
    $target = $this->target;

    $movie_file = realpath($videos);
    // instancia a classe ffmpeg_movie para pegarmos as informações que queremos o vídeo
    $movie = new ffmpeg_movie($movie_file);
    $totalFrames = $movie->getFrameCount();
    $thumbnailOf = $movie->getFrameRate() * 5;
    $thumbnailOf = round ( $movie->getFrameCount() / 2 );

    // criamos a instancia do frame com a classe ffmpeg_frame
    $frame = new ffmpeg_frame ( $image );
    // escolhemos o frame que queremos salvar como jpeg

    $thumbnailOf = rand (1,$movie->getFrameCount());
    // recebe o frame
    $frame = $movie->getFrame ( $thumbnailOf );
    // converte para uma imagem GD
    $image = $frame->toGDImage ();
    $valuea = rand(0,100);
    $valueb = rand(0,100);
    $valuec = rand(0,10);

    $nome = @md5(date(&#39;now&#39;) * $valuea - $valueb / $valuec);

    $dir = $target."snapshots/".$nome.".jpeg";
    //salva no HD.
    imagejpeg($image,$dir, 100);

    $q = new Query;
    $q  ->update(&#39;video&#39;)
       ->set(
           array(
              &#39;screen&#39;=>$nome.".jpeg"
           )
       )
           ->where_equal_to(
                   array(
                           &#39;id_video&#39;=>$this->id_vid
                   )
           )
           ->limit(1)

       ->run();

    }


    public function duration(){

    $videos = $this->videos;    
    $movie_file = realpath($videos);
    // instancia a classe ffmpeg_movie para pegarmos as informações que queremos o vídeo
    $movie = new ffmpeg_movie($movie_file);
    // pegamos a duranção do video em segundos
    $duration = round ( $movie->getDuration() , 0 );

    $q = new Query;
    $q  ->update(&#39;video&#39;)
       ->set(
           array(
              &#39;duration&#39;=>$duration
           )
       )
           ->where_equal_to(
                   array(
                           &#39;id_video&#39;=>$this->id_vid
                   )
           )
           ->limit(1)

       ->run();
    }


    public function resolution(){

    $videos = $this->videos;    
    $movie_file = realpath($videos);
    // instancia a classe ffmpeg_movie para pegarmos as informações que queremos o vídeo
    $movie = new ffmpeg_movie($movie_file);
    // recebemos a altura do vídeo em pixels
    $height = $movie->getFrameHeight ();
    // recebemos a largura do vídeo em pixels
    $width = $movie->getFrameWidth ();
    $resolucao =  $width."x".$height;


    $q = new Query;
    $q  ->update(&#39;video&#39;)
       ->set(
           array(
              &#39;resolucao&#39;=>$resolucao
           )
       )
       ->where_equal_to(
                   array(
                           &#39;id_video&#39;=>$this->id_vid
                   )
           )
           ->limit(1)

       ->run();
    }

    final public function checar($a){

    $q = new Query;
    $q  ->update(&#39;video&#39;)
       ->set(
           array(
              &#39;process&#39;=>$a
           )
       )
       ->where_equal_to(
                   array(
                           &#39;id_video&#39;=>$this->id_vid
                   )
           )
           ->limit(1)

       ->run();

    }

    }

    $q=new Query;
    $q->select(
                   array(
                           &#39;id_video&#39;,
                           &#39;video&#39;,
                           &#39;dir&#39;,
                           &#39;screen&#39;,
                           &#39;poster_id&#39;,
                           &#39;resolucao&#39;,
                           &#39;duration&#39;
                   )
           )
           ->from(&#39;video&#39;)



           ->run();
    if($q){
           $users=$q->get_selected();
           foreach($users as $user){
            $c = new process;

            $c->videos = $user[&#39;video&#39;];
            $c->target = $user[&#39;dir&#39;];
            $c->id_vid = $user[&#39;id_video&#39;];

           if(($user[&#39;screen&#39;] == &#39;NULL&#39;) or ($user[&#39;duration&#39;] == &#39;NULL&#39;) or ($user[&#39;resolucao&#39;] == &#39;NULL&#39;)){
                   $c->checar(0);

                   if($user[&#39;screen&#39;] == &#39;NULL&#39;){      
                   $c->screen();
                   }

                   if($user[&#39;duration&#39;] == &#39;NULL&#39;){
                   $c->duration();
                   }

                   if($user[&#39;resolucao&#39;] == &#39;NULL&#39;){
                   $c->resolution();  
                   }

           }else{

           $c->checar(1);

           }

           }
    }
    else{
           echo &#39;Sorry, no users found.&#39;;
    }



    ?>
  • 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;
    }
  • Créer des auteurs par lot

    9 mai 2013

    Il peut être intéressant de pouvoir insérer dans SPIP une liste d’auteurs soit via une liste d’emails rentrée dans un champ textarea ou via un import CSV (était possible avec Inscription2 et donc à réadapter).

    Doit être un plugin indépendant. Ce serait trop lourd de gérer cela en plus dans Inscription3 alors que ce plugin est déjà bien compliqué.

    Note du 26/05/13 :

    Tâches à réaliser

    Statut Titre #
    Intégrer le plugin importateur contacts dans la configuration qui permet de récupérer les contacts à partir d’une liste ou d’un site externe (Gmail etc...) ; #1
    Intégrer le plugin parrainages qui permet de sélectionner les contacts et de les inviter à créer un compte (configuration + formulaire de parrainage) ; #2
    Intégrer OpenInviter pour ajouter des méthodes à importateur de contacts #3
    Pouvoir configurer le lien dans le mail de parrainage #4
    Le mail de parrainage devrait être en html (notifications) #5
    Lors du click sur le lien dans le mail => préremplir les champs du formulaire d’inscription (nom + email) ; #6
    Faire en sorte que les personnes avec un code d’invitation puisse s’inscrire dans un intranet : cf zone.spip.org/trac/spip-zone/changeset/73071 #7
    Permettre aux utilisateurs d’inviter leurs propres amis depuis leur page cf : http://zone.spip.org/trac/spip-zone/changeset/73066 ; #8
    Ne pas pouvoir parrainer si la conf du site ne permet pas l’inscription, l’indiquer dans la configuration du plugin parrainage ; #9
    Passer par une action editer_filleul dans le plugin parrainage ; #10
    Si le code d’invitation est obligatoire, le signaler dans le formulaire d’inscription et dans le formulaire de configuration de l’ouverture d’inscription du site ; #11
    Pouvoir ajouter comme contact un email simple, une liste d’email ; #12
    Pouvoir ajouter les auteurs via un csv ; #13
    intégrer les plugins dans le script de la version 0.3 #14
    documenter l’usage dans MediaSPIP + screencasts #15