Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (64)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (12585)

  • QSharedMemory in Real-Time process

    21 novembre 2016, par Seungsoo Kim

    I’m trying to use QSharedMemory Class to share video data between two processes.

    So I tried like following method, but it has problem in simultaneous access of two processes.

    Two process crashes when they access sequentially to same memory name(key) "SharedMemory".

    I locked them while they’re used, but also it doesn’t work well.

    How can i avoid this crash ??

    1. Writing to SharedMemory - data type is and this function called by callback.

      QBuffer buffer;
      buffer.open(QBuffer::ReadWrite);
      QDataStream out(&buffer);

      QByteArray outArray = QByteArray::fromRawData(reinterpret_cast<const>(data), strlen(reinterpret_cast<const>(data)));
      out &lt;&lt; width &lt;&lt; height &lt;&lt; step &lt;&lt; cameraId &lt;&lt; strlen(reinterpret_cast<const>(data));
      out.writeRawData(outArray.data(), outArray.size());

      int size = buffer.size();

      sharedMemory.setKey("SharedMemory");

      if (!sharedMemory.isAttached()) {
         printf("Cannot attach to shared memory to update!\n");
      }
      if (!sharedMemory.create(size))
      {
         printf("failed to allocate memory\n");
      }
      sharedMemory.lock();
      char *to = (char*)sharedMemory.data();
      const char *from = buffer.data().data();
      memcpy(to, from,qMin(sharedMemory.size(),size));
      sharedMemory.unlock();
      </const></const></const>
    2. Using data in SharedMemory. - this function is called by QThread, interval 100ms

      QSharedMemory sharedMemory("SharedMemory");
      sharedMemory.lock();
      if (!sharedMemory.attach()) {
         printf("failed to attach to memory\n");
         return;
      }

      QBuffer buffer;
      QDataStream in(&amp;buffer);

      sharedMemory.create(1920 * 1080);
      buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
      buffer.open(QBuffer::ReadOnly);
      sharedMemory.unlock();
      sharedMemory.detach();

      int r_width = 0;    
      int r_height = 0;
      int r_cameraId = 0;
      int r_step = 0;
      int r_strlen = 0;
      in >> r_width >> r_height >> r_step >> r_cameraId >> r_strlen;

      char* receive = new char[r_strlen];
      in.readRawData(receive, r_strlen);
      //unsigned char* r_receive = new unsigned char[r_strlen];
      //r_receive = (unsigned char*)receive;

      QPixmap backBuffer = QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step, QImage::Format::Format_RGB888));
      ui.label->setPixmap(backBuffer.scaled(ui.label->size(), Qt::KeepAspectRatio));
      ui.label->show();

    please share your idea ! thank you !

  • How to extract frames at 30 fps using FFMPEG APIs on Android ?

    8 septembre 2016, par Amber Beriwal

    We are working on a project that consumes FFMPEG library for video frame extraction on Android platform.

    On Windows, we have observed :

    • Using CLI, ffmpeg is capable of extracting frames at 30 fps using command ffmpeg -i input.flv -vf fps=1 out%d.png.
    • Using Xuggler, we are able to extract frames at 30 fps.
    • Using FFMPEG APIs directly in code, we are getting frames at 30 fps.

    But when we use FFMPEG APIs directly on Android (See Hardware Details), we are getting following results :

    • 720p video (1280 x 720) - 16 fps (approx. 60 ms/frame)
    • 1080p video (1920 x 1080) - 7 fps (approx. 140 ms/frame)

    We haven’t tested Xuggler/CLI on Android yet.

    Ideally, we should be able to get the data in constant time (approx. 30 ms/frame).

    How can we get 30 fps on Android ?

    Code being used on Android :

    if (avformat_open_input(&amp;pFormatCtx, pcVideoFile, NULL, NULL)) {
       iError = -1;  //Couldn't open file
    }

    if (!iError) {
       //Retrieve stream information
       if (avformat_find_stream_info(pFormatCtx, NULL) &lt; 0)
           iError = -2; //Couldn't find stream information
    }

    //Find the first video stream
    if (!iError) {

       for (i = 0; i &lt; pFormatCtx->nb_streams; i++) {
           if (AVMEDIA_TYPE_VIDEO
                   == pFormatCtx->streams[i]->codec->codec_type) {
               iFramesInVideo = pFormatCtx->streams[i]->nb_index_entries;
               duration = pFormatCtx->streams[i]->duration;
               begin = pFormatCtx->streams[i]->start_time;
               time_base = (pFormatCtx->streams[i]->time_base.num * 1.0f)
                       / pFormatCtx->streams[i]->time_base.den;

               pCodecCtx = avcodec_alloc_context3(NULL);
               if (!pCodecCtx) {
                   iError = -6;
                   break;
               }

               AVCodecParameters params = { 0 };
               iReturn = avcodec_parameters_from_context(&amp;params,
                       pFormatCtx->streams[i]->codec);
               if (iReturn &lt; 0) {
                   iError = -7;
                   break;
               }

               iReturn = avcodec_parameters_to_context(pCodecCtx, &amp;params);
               if (iReturn &lt; 0) {
                   iError = -7;
                   break;
               }

               //pCodecCtx = pFormatCtx->streams[i]->codec;

               iVideoStreamIndex = i;
               break;
           }
       }
    }

    if (!iError) {
       if (iVideoStreamIndex == -1) {
           iError = -3; // Didn't find a video stream
       }
    }

    if (!iError) {
       // Find the decoder for the video stream
       pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
       if (pCodec == NULL) {
           iError = -4;
       }
    }

    if (!iError) {
       // Open codec
       if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)
           iError = -5;
    }

    if (!iError) {
       iNumBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width,
               pCodecCtx->height, 1);

       // initialize SWS context for software scaling
       sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
               pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
               AV_PIX_FMT_RGB24,
               SWS_BILINEAR,
               NULL,
               NULL,
               NULL);
       if (!sws_ctx) {
           iError = -7;
       }
    }
    clock_gettime(CLOCK_MONOTONIC_RAW, &amp;end);
    delta_us = (end.tv_sec - start.tv_sec) * 1000000
           + (end.tv_nsec - start.tv_nsec) / 1000;
    start = end;
    //LOGI("Starting_Frame_Extraction: %lld", delta_us);
    if (!iError) {
       while (av_read_frame(pFormatCtx, &amp;packet) == 0) {
           // Is this a packet from the video stream?
           if (packet.stream_index == iVideoStreamIndex) {
               pFrame = av_frame_alloc();
               if (NULL == pFrame) {
                   iError = -8;
                   break;
               }

               // Decode video frame
               avcodec_decode_video2(pCodecCtx, pFrame, &amp;iFrameFinished,
                       &amp;packet);
               if (iFrameFinished) {
                   //OUR CODE
               }
               av_frame_free(&amp;pFrame);
               pFrame = NULL;
           }
           av_packet_unref(&amp;packet);
       }
    }
  • Facebook Reels Upload always failing

    21 juin, par Evrard A.

    I'm trying to upload Reels through Facebook Graph API. The video is created with the following ffmpeg command.

    &#xA;

    cmd = [&#xA;            &#x27;ffmpeg&#x27;,&#xA;            &#x27;-i&#x27;, video_path,&#xA;            &#x27;-i&#x27;, voice_path,&#xA;            &#x27;-i&#x27;, music_path,&#xA;&#xA;            &#x27;-filter_complex&#x27;,&#xA;            &#x27;[1:a]loudnorm=I=-16:LRA=11:TP=-1.5,adelay=0|0[a1];&#x27; &#x2B;&#xA;            &#x27;[2:a]volume=0.2,afade=t=in:ss=0:d=0.02,afade=t=out:st=28:d=0.03[a2];&#x27; &#x2B;&#xA;            &#x27;[a1][a2]amix=inputs=2:duration=first:dropout_transition=0[aout]&#x27;,&#xA;&#xA;            &#x27;-map&#x27;, &#x27;0:v:0&#x27;,&#xA;            &#x27;-map&#x27;, &#x27;[aout]&#x27;,&#xA;&#xA;            &#x27;-vf&#x27;,&#xA;             f"subtitles=&#x27;{str(ass_path)}&#x27;,format=yuv420p,scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1",  # Incrustation des sous-titres&#xA;&#xA;            &#x27;-r&#x27;, &#x27;30&#x27;,&#xA;            &#x27;-g&#x27;, &#x27;60&#x27;,&#xA;            &#x27;-keyint_min&#x27;, &#x27;60&#x27;,&#xA;            &#x27;-sc_threshold&#x27;, &#x27;0&#x27;,&#xA;            &#x27;-x264opts&#x27;, &#x27;no-scenecut&#x27;,&#xA;&#xA;            &#x27;-c:v&#x27;, &#x27;libx264&#x27;,&#xA;            &#x27;-profile:v&#x27;, &#x27;baseline&#x27;,&#xA;            &#x27;-level&#x27;, &#x27;4.1&#x27;,&#xA;            &#x27;-pix_fmt&#x27;, &#x27;yuv420p&#x27;,&#xA;            &#x27;-color_range&#x27;, &#x27;tv&#x27;,&#xA;            &#x27;-colorspace&#x27;, &#x27;bt709&#x27;,&#xA;&#xA;            &#x27;-b:v&#x27;, &#x27;9500k&#x27;,&#xA;            &#x27;-maxrate&#x27;, &#x27;9500k&#x27;,&#xA;            &#x27;-bufsize&#x27;, &#x27;19000k&#x27;,&#xA;&#xA;            &#x27;-c:a&#x27;, &#x27;aac&#x27;,&#xA;            &#x27;-b:a&#x27;, &#x27;192k&#x27;,&#xA;            &#x27;-ac&#x27;, &#x27;2&#x27;,&#xA;            &#x27;-ar&#x27;, &#x27;48000&#x27;,&#xA;&#xA;            &#x27;-movflags&#x27;, &#x27;&#x2B;faststart&#x27;,&#xA;            &#x27;-video_track_timescale&#x27;, &#x27;15360&#x27;,&#xA;            &#x27;-max_muxing_queue_size&#x27;, &#x27;9999&#x27;,&#xA;&#xA;            &#x27;-y&#x27;, self.output_video_path if self.output_video_path else f&#x27;{parts[0]}.subtitled.{parts[1]}&#x27;&#xA;        ]&#xA;&#xA;        subprocess.run(cmd, check=True)&#xA;

    &#xA;

    Here is the class method I use to publish :

    &#xA;

      import requests, os,  time&#xA;  from datetime import datetime, timedelta&#xA;  from moviepy.editor import VideoFileClip&#xA;   &#xA;  def post_reel(&#xA;      self,&#xA;      page_id: str,&#xA;      page_access_token: str,&#xA;      video_file_path: str,&#xA;      video_description: str,&#xA;      tags: list = None, # type: ignore&#xA;      publish_now: bool = True&#xA;  ):&#xA;      def extract_first_frame(video_path: str, output_image_path: str, time_in_seconds: float = 1):&#xA;          """&#xA;          Extrait une frame &#xE0; time_in_seconds et la sauvegarde comme miniature.&#xA;          """&#xA;          try:&#xA;              clip = VideoFileClip(video_path)&#xA;              clip.save_frame(output_image_path, t=time_in_seconds)&#xA;              print(f"[THUMBNAIL] Frame at {time_in_seconds}s saved to {output_image_path}")&#xA;              return output_image_path&#xA;          except Exception as e:&#xA;              print(f"[ERROR] Could not extract thumbnail: {str(e)}")&#xA;              return None&#xA;&#xA;      def wait_for_video_ready(video_id, page_access_token, timeout=300, poll_interval=10):&#xA;          """&#xA;          Attends que la vid&#xE9;o soit compl&#xE8;tement trait&#xE9;e et publi&#xE9;e.&#xA;          """&#xA;          status_url = f"{self.BASE_API_URL}/{video_id}"&#xA;          params = {&#xA;              "access_token": page_access_token,&#xA;              "fields": "status"&#xA;          }&#xA;&#xA;          start = time.time()&#xA;          while time.time() - start &lt; timeout:&#xA;              try:&#xA;                  r = requests.get(url=status_url, params=params)&#xA;                  r.raise_for_status()&#xA;                  status = r.json().get("status", {})&#xA;                  processing = status.get("processing_phase", {}).get("status")&#xA;                  publishing = status.get("publishing_phase", {}).get("status")&#xA;                  video_status = status.get("video_status")&#xA;&#xA;                  print(f"[WAIT] video_status={video_status}, processing={processing}, publishing={publishing}")&#xA;&#xA;                  if processing == "complete" and publishing == "complete":&#xA;                      print("[READY] Reel processed and published")&#xA;                      return True&#xA;                  elif processing == "error":&#xA;                     print(r.json())&#xA;&#xA;              except Exception as e:&#xA;                  print(f"[ERROR] during polling: {e}")&#xA;&#xA;              time.sleep(poll_interval)&#xA;&#xA;          print("[TIMEOUT] Video did not finish processing in time.")&#xA;          return False&#xA;&#xA;      try:&#xA;          # Step 1: Initialize upload&#xA;          init_url = f"{self.BASE_API_URL}/{page_id}/video_reels"&#xA;          init_params = {"upload_phase": "start"}&#xA;          init_payload = {&#x27;access_token&#x27;: page_access_token}&#xA;&#xA;          r = requests.post(url=init_url, data=init_payload, params=init_params)&#xA;          r.raise_for_status()&#xA;          response = r.json()&#xA;          video_id = response["video_id"]&#xA;          upload_url = response["upload_url"]&#xA;          print(f"[INIT OK] Video ID: {video_id}")&#xA;&#xA;          # Step 2: Upload video&#xA;          file_size = os.path.getsize(video_file_path)&#xA;          headers = {&#xA;              &#x27;Authorization&#x27;: f"OAuth {page_access_token}",&#xA;              &#x27;offset&#x27;: "0",&#xA;              &#x27;file_size&#x27;: str(file_size),&#xA;          }&#xA;&#xA;          with open(video_file_path, &#x27;rb&#x27;) as f:&#xA;              files = {&#x27;source&#x27;: f}&#xA;              r = requests.post(url=upload_url, data=files, headers=headers)&#xA;              r.raise_for_status()&#xA;              upload_response = r.json()&#xA;&#xA;          if not upload_response.get("success"):&#xA;              print("[ERROR] Upload failed.")&#xA;              return None&#xA;          print(f"[UPLOAD OK]")&#xA;&#xA;          # Step 3: Check video status&#xA;          status_check_url = f&#x27;{self.BASE_API_URL}/{video_id}&#x27;&#xA;          check_params = {&#xA;              "access_token": page_access_token,&#xA;              "fields": "status"&#xA;          }&#xA;          r = requests.get(url=status_check_url, params=check_params)&#xA;          r.raise_for_status()&#xA;          print(f"[STATUS CHECK] {r.json()}")&#xA;&#xA;          # Step 4: Finalize video&#xA;          finalize_params = {&#xA;              "video_id": video_id,&#xA;              "upload_phase": "finish",&#xA;              "published": "true",&#xA;              "access_token": page_access_token,&#xA;              "video_state": "PUBLISHED" if publish_now else "SCHEDULED",&#xA;              "title": video_description,&#xA;              "description": video_description&#xA;          }&#xA;&#xA;          if not publish_now:&#xA;              finalize_params["scheduled_publish_time"] = int((datetime.now() &#x2B; timedelta(days=1)).timestamp())&#xA;&#xA;          if tags:&#xA;              finalize_params["tags"] = ",".join(tags)&#xA;&#xA;          r = requests.post(url=init_url, params=finalize_params, headers=headers)&#xA;          r.raise_for_status()&#xA;          finalize_response = r.json()&#xA;          post_id = finalize_response.get("post_id")&#xA;          print(f"[FINALIZE OK] Post ID: {post_id}")&#xA;          &#xA;          # WAIT UNTIL PUBLISHED&#xA;          if not wait_for_video_ready(video_id, page_access_token):&#xA;              print("[ERROR] Reel processing timeout or failure")&#xA;              return None&#xA;          &#xA;          # Step 5: Extract and upload thumbnail&#xA;          thumbnail_path = f"temp_thumb_{video_id}.jpg"&#xA;          if extract_first_frame(video_file_path, thumbnail_path):&#xA;              thumb_url = f"{self.BASE_API_URL}/{video_id}/thumbnails"&#xA;              with open(thumbnail_path, &#x27;rb&#x27;) as img:&#xA;                  files = {&#x27;source&#x27;: img}&#xA;                  thumb_payload = {&#x27;access_token&#x27;: page_access_token}&#xA;                  r = requests.post(url=thumb_url, files=files, data=thumb_payload)&#xA;                  r.raise_for_status()&#xA;                  print("[THUMBNAIL UPLOADED]")&#xA;              # Clean up temp file&#xA;              os.remove(thumbnail_path)&#xA;              print("[THUMBNAIL CLEANED UP]")&#xA;&#xA;          return post_id&#xA;&#xA;      except Exception as e:&#xA;          print(f"[ERROR] {str(e)}")&#xA;          return None&#xA;

    &#xA;

    Here are the logs I get :

    &#xA;

      &#xA;
    • [INIT OK] Video ID: 1020853163558419
    • &#xA;

    • [UPLOAD OK]
    • &#xA;

    • [STATUS CHECK]
    • &#xA;

    &#xA;

    {&#xA;  "status": {&#xA;    "video_status": "upload_complete",&#xA;    "uploading_phase": {&#xA;      "status": "complete",&#xA;      "bytes_transferred": 37780189&#xA;    },&#xA;    "processing_phase": {&#xA;      "status": "not_started"&#xA;    },&#xA;    "publishing_phase": {&#xA;      "status": "not_started"&#xA;    },&#xA;    "copyright_check_status": {&#xA;      "status": "in_progress"&#xA;    }&#xA;  },&#xA;  "id": "1020853163558419"&#xA;}&#xA;

    &#xA;

      &#xA;
    • [FINALIZE OK] Post ID: 122162302376476425
    • &#xA;

    • [WAIT] video_status=upload_complete, processing=not_started, publishing=not_started
    • &#xA;

    • [WAIT] video_status=error, processing=error, publishing=not_started
    • &#xA;

    &#xA;

    {&#xA;  "status": {&#xA;    "video_status": "error",&#xA;    "uploading_phase": {&#xA;      "status": "complete",&#xA;      "bytes_transferred": 37780189&#xA;    },&#xA;    "processing_phase": {&#xA;      "status": "error",&#xA;      "errors": [&#xA;        {&#xA;          "code": 1363008,&#xA;          "message": "Video Creation failed, please try again."&#xA;        }&#xA;      ]&#xA;    },&#xA;    "publishing_phase": {&#xA;      "status": "not_started"&#xA;    },&#xA;    "copyright_check_status": {&#xA;      "status": "in_progress"&#xA;    }&#xA;  },&#xA;  "id": "1020853163558419"&#xA;}&#xA;

    &#xA;

    It seems the error code 1363008 is related to the video properties format but even after following Facebook Reels video format recommandations, I can't make it work.

    &#xA;

    Can you help me with this please ?

    &#xA;

    I failed getting usefull help with ChatGPT 😅, and thanks in advance for anyone who answers or comments my question.

    &#xA;