Recherche avancée

Médias (0)

Mot : - Tags -/albums

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

Autres articles (5)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Configuration spécifique pour PHP5

    4 février 2011, par

    PHP5 est obligatoire, vous pouvez l’installer en suivant ce tutoriel spécifique.
    Il est recommandé dans un premier temps de désactiver le safe_mode, cependant, s’il est correctement configuré et que les binaires nécessaires sont accessibles, MediaSPIP devrait fonctionner correctement avec le safe_mode activé.
    Modules spécifiques
    Il est nécessaire d’installer certains modules PHP spécifiques, via le gestionnaire de paquet de votre distribution ou manuellement : php5-mysql pour la connectivité avec la (...)

Sur d’autres sites (2131)

  • Socket.io client in js and server in Socket.io go doesn't send connected messege and data

    24 mars 2023, par OmriHalifa

    I am using ffmpeg and socket.io and I have some issues. I'm trying to send a connection request to a server written in Go through React, but I'm unable to connect to it. I tried adding the events in useEffect and it's still not working, what should I do ? i attaching my code in js and in go :
main.go

    


    package main

import (
    "log"

    "github.com/gin-gonic/gin"

    socketio "github.com/googollee/go-socket.io"
)

func main() {
    router := gin.New()

    server := socketio.NewServer(nil)

    server.OnConnect("/", func(s socketio.Conn) error {
        s.SetContext("")
        log.Println("connected:", s.ID())
        return nil
    })

    server.OnEvent("/", "notice", func(s socketio.Conn, msg string) {
        log.Println("notice:", msg)
        s.Emit("reply", "have "+msg)
    })

    server.OnEvent("/", "transcoded-video", func(s socketio.Conn, data string) {
        log.Println("transcoded-video:", data)
    })

    server.OnEvent("/", "bye", func(s socketio.Conn) string {
        last := s.Context().(string)
        s.Emit("bye", last)
        s.Close()
        return last
    })

    server.OnError("/", func(s socketio.Conn, e error) {
        log.Println("meet error:", e)
    })

    server.OnDisconnect("/", func(s socketio.Conn, reason string) {
        log.Println("closed", reason)
    })

    go func() {
        if err := server.Serve(); err != nil {
            log.Fatalf("socketio listen error: %s\n", err)
        }
    }()
    defer server.Close()

    if err := router.Run(":8000"); err != nil {
        log.Fatal("failed run app: ", err)
    }
}



    


    App.js

    


    import &#x27;./App.css&#x27;;&#xA;import { useEffect } from &#x27;react&#x27;;&#xA;import { createFFmpeg, fetchFile } from &#x27;@ffmpeg/ffmpeg&#x27;;&#xA;import { io } from &#x27;socket.io-client&#x27;; &#xA;&#xA;function App() {&#xA;  const socket = io("http://localhost:8000",function() {&#xA;    // Send a message to the server when the client is connected&#xA;    socket.emit(&#x27;clientConnected&#x27;, &#x27;Client has connected to the server!&#x27;);&#xA;  })&#xA;&#xA;  const ffmpegWorker = createFFmpeg({&#xA;    log: true&#xA;  })&#xA;&#xA;  // Initialize FFmpeg when the component is mounted&#xA;  async function initFFmpeg() {&#xA;    await ffmpegWorker.load();&#xA;  }&#xA;&#xA;  async function transcode(webcamData) {&#xA;    const name = &#x27;record.webm&#x27;;&#xA;    await ffmpegWorker.FS(&#x27;writeFile&#x27;, name, await fetchFile(webcamData));&#xA;    await ffmpegWorker.run(&#x27;-i&#x27;, name, &#x27;-preset&#x27;, &#x27;ultrafast&#x27;, &#x27;-threads&#x27;, &#x27;4&#x27;, &#x27;output.mp4&#x27;);&#xA;    const data = ffmpegWorker.FS(&#x27;readFile&#x27;, &#x27;output.mp4&#x27;);&#xA;    &#xA;    // Set the source of the output video element to the transcoded video data&#xA;    const video = document.getElementById(&#x27;output-video&#x27;);&#xA;    video.src = URL.createObjectURL(new Blob([data.buffer], { type: &#x27;video/mp4&#x27; }));&#xA;    &#xA;    // Remove the output.mp4 file from the FFmpeg virtual file system&#xA;    ffmpegWorker.FS(&#x27;unlink&#x27;, &#x27;output.mp4&#x27;);&#xA;    &#xA;    // Emit a "transcoded-video" event to the server with the transcoded video data&#xA;    socket.emit("transcoded-video", data.buffer)&#xA;  }&#xA;  &#xA;  &#xA;&#xA;  let mediaRecorder;&#xA;  let chunks = [];&#xA;  &#xA;  // Request access to the user&#x27;s camera and microphone and start recording&#xA;  function requestMedia() {&#xA;    const webcam = document.getElementById(&#x27;webcam&#x27;);&#xA;    navigator.mediaDevices.getUserMedia({ video: true, audio: true })&#xA;    .then(async (stream) => {&#xA;      webcam.srcObject = stream;&#xA;      await webcam.play();&#xA;&#xA;      // Set up a MediaRecorder instance to record the video and audio&#xA;      mediaRecorder = new MediaRecorder(stream);&#xA;&#xA;      // Add the recorded data to the chunks array&#xA;      mediaRecorder.ondataavailable = async (e) => {&#xA;        chunks.push(e.data);&#xA;      }&#xA;&#xA;      // Transcode the recorded video data after the MediaRecorder stops&#xA;      mediaRecorder.onstop = async () => {&#xA;        await transcode(new Uint8Array(await (new Blob(chunks)).arrayBuffer()));&#xA;&#xA;        // Clear the chunks array after transcoding&#xA;        chunks = [];&#xA;&#xA;        // Start the MediaRecorder again after a 0 millisecond delay&#xA;        setTimeout(() => {&#xA;          mediaRecorder.start();&#xA;          &#xA;          // Stop the MediaRecorder after 3 seconds&#xA;          setTimeout(() => {&#xA;            mediaRecorder.stop();&#xA;          }, 500);&#xA;        }, 0);&#xA;      }&#xA;&#xA;      // Start the MediaRecorder&#xA;      mediaRecorder.start();&#xA;&#xA;      // Stop the MediaRecorder after 3 seconds&#xA;      setTimeout(() => {&#xA;        mediaRecorder.stop();&#xA;      }, 700);&#xA;    })&#xA;  }&#xA;  &#xA;  useEffect(() => {&#xA;    // Set up event listeners for the socket connection&#xA;    socket.on(&#x27;/&#x27;, function(){&#xA;      // Log a message when the client is connected to the server&#xA;      console.log("Connected to server!"); &#xA;    });&#xA;&#xA;    socket.on(&#x27;transcoded-video&#x27;, function(data){&#xA;      // Log the received data for debugging purposes&#xA;      console.log("Received transcoded video data:", data); &#xA;    });&#xA;&#xA;    socket.on(&#x27;notice&#x27;, function(data){&#xA;      // Emit a "notice" event back to the server to acknowledge the received data&#xA;      socket.emit("notice", "ping server!");&#xA;    });&#xA;&#xA;    socket.on(&#x27;bye&#x27;, function(data){&#xA;      // Log the received data and disconnect from the server&#xA;      console.log("Server sent:", data); &#xA;      socket.disconnect();&#xA;    });&#xA;&#xA;    socket.on(&#x27;disconnect&#x27;, function(){&#xA;      // Log a message when the client is disconnected from the server&#xA;      console.log("Disconnected from server!"); &#xA;    });&#xA;  }, [])&#xA;&#xA;  return (&#xA;    <div classname="App">&#xA;      <div>&#xA;          <video muted="{true}"></video>&#xA;          <video autoplay="autoplay"></video>&#xA;      </div>&#xA;      <button>start streaming</button>&#xA;    </div>&#xA;  );&#xA;}&#xA;&#xA;export default App;&#xA;

    &#xA;

    What can i do to fix it ? thank you !!

    &#xA;

  • I have use the ffmpeg in my react konva project but it not import correclty ?

    5 septembre 2024, par Humayoun Saeed

    I use ffmpeg in my react konva project to record video and download it, but when i import it give me error, when i give to to gpt or google it giveme another way of export when i do this one it same give me error of import from ffpmg

    &#xA;

    Error :

    &#xA;

    ERROR in ./src/components/Preview.jsx 29:25-37&#xA;export 'createFFmpeg' (imported as 'createFFmpeg') was not found in '@ffmpeg/ffmpeg' (possible exports : FFmpeg)&#xA;ERROR in ./src/components/Preview.jsx 123:34-43&#xA;export 'fetchFile' (imported as 'fetchFile') was not found in '@ffmpeg/ffmpeg' (possible exports : FFmpeg)

    &#xA;

    Preview.jsx :

    &#xA;

    import React, { useEffect, useState, useRef } from "react";&#xA;// import { createFFmpeg } from "@ffmpeg/ffmpeg";&#xA;// import { createFFmpeg, fetchFile } from "@ffmpeg/ffmpeg/dist/ffmpeg.min.js";&#xA;// import { FFmpeg } from "@ffmpeg/ffmpeg";&#xA;// import { fetchFile } from "@ffmpeg/util";&#xA;import { createFFmpeg, fetchFile } from "@ffmpeg/ffmpeg";&#xA;&#xA;&#xA;&#xA;const Preview = ({ layout, onClose }) => {&#xA;  const [currentContent, setCurrentContent] = useState([]);&#xA;  const [progress, setProgress] = useState(0);&#xA;  const totalDuration = useRef(0);&#xA;  const elapsedDuration = useRef(0); // Track total elapsed duration&#xA;  const progressInterval = useRef(null);&#xA;  const ffmpeg = useRef(null); // Use useRef to store ffmpeg instance&#xA;  const [ffmpegReady, setFfmpegReady] = useState(false);&#xA;&#xA;  // Initialize FFmpeg instance&#xA;  useEffect(() => {&#xA;    const loadFFmpeg = async () => {&#xA;      if (!ffmpeg.current) {&#xA;        ffmpeg.current = createFFmpeg({ log: true });&#xA;        await ffmpeg.current.load();&#xA;        setFfmpegReady(true);&#xA;      }&#xA;    };&#xA;    loadFFmpeg();&#xA;  }, []);&#xA;&#xA;&#xA;&#xA;&#xA;const handleDownload = async () => {&#xA;    try {&#xA;      if (!ffmpegReady) {&#xA;        alert("FFmpeg is still loading, please wait...");&#xA;        return;&#xA;      }&#xA;&#xA;      // Fetch all media files from the layout&#xA;      const inputFiles = [];&#xA;&#xA;      // Process each division of the layout&#xA;      for (const division of layout.divisions) {&#xA;        for (let i = 0; i &lt; division.imageSrcs.length; i&#x2B;&#x2B;) {&#xA;          const src = division.imageSrcs[i];&#xA;&#xA;          // Fetch and store media data&#xA;          const mediaData = await fetchFile(src);&#xA;          const fileName = `input${inputFiles.length &#x2B; 1}${&#xA;            src.endsWith(".mp4") ? ".mp4" : ".png"&#xA;          }`;&#xA;&#xA;          // Write file to ffmpeg virtual filesystem&#xA;          ffmpeg.current.FS("writeFile", fileName, mediaData);&#xA;          inputFiles.push(fileName);&#xA;        }&#xA;      }&#xA;&#xA;      // Create a list of inputs for ffmpeg&#xA;      let concatList = "";&#xA;      inputFiles.forEach((fileName) => {&#xA;        concatList &#x2B;= `file &#x27;${fileName}&#x27;\n`;&#xA;      });&#xA;&#xA;      // Write the concat list file to FFmpeg FS&#xA;      ffmpeg.current.FS(&#xA;        "writeFile",&#xA;        "concatList.txt",&#xA;        new TextEncoder().encode(concatList)&#xA;      );&#xA;&#xA;      // Run the ffmpeg command to concatenate all files into one video&#xA;      await ffmpeg.current.run(&#xA;        "-f",&#xA;        "concat",&#xA;        "-safe",&#xA;        "0",&#xA;        "-i",&#xA;        "concatList.txt",&#xA;        "-c",&#xA;        "copy",&#xA;        "output.mp4"&#xA;      );&#xA;&#xA;      // Read the result video&#xA;      const data = ffmpeg.current.FS("readFile", "output.mp4");&#xA;&#xA;      // Create a Blob from the data and download it&#xA;      const videoBlob = new Blob([data.buffer], { type: "video/mp4" });&#xA;      const url = URL.createObjectURL(videoBlob);&#xA;      const link = document.createElement("a");&#xA;      link.href = url;&#xA;      link.download = `${layout.name || "layout_video"}.mp4`;&#xA;      document.body.appendChild(link);&#xA;      link.click();&#xA;      document.body.removeChild(link);&#xA;&#xA;      alert("Video download completed.");&#xA;    } catch (error) {&#xA;      console.error("Error during video creation:", error);&#xA;    }&#xA;  };&#xA;&#xA;&#xA; &#xA;&#xA;&#xA;&#xA;return (&#xA;    &#xA;      &#xA;        &#xA;          Close&#xA;        &#xA; &#xA;  {/* Download button */}&#xA;        > (e.target.style.backgroundColor = "#218838")}&#xA;          onMouseOut={(e) => (e.target.style.backgroundColor = "#28a745")}&#xA;        >&#xA;          Download Video&#xA;        &#xA;      &#xA;    &#xA;  );&#xA;};&#xA;&#xA;export default Preview;&#xA;&#xA;

    &#xA;

    Ignore all other main issue in just ffmpeg , import, declaration and in it usage in download function, if anyone solution or ability to resolve it, then check it.

    &#xA;

    I try to use ffmpeg in my project for video downloading but it not importing and not use , i want to download video i made using ffmpeg.

    &#xA;

  • ffmpeg RTSP stream decoding memory leak

    6 février 2019, par Haris

    I need to decode rtsp stream from Ip camera using ffmpeg, below is the code for decoder

    ffmpeg_decoder.h

    class ffmpeg_decoder
    {
    public:
       ffmpeg_decoder();
       int initial(QString &amp; url);
       int h264Decodec();
       void close_stream();
       virtual ~ffmpeg_decoder();
       AVPicture  picture;
       int width;
       int height;
       QMutex mutex;
       QImage imageDecoded;

    private:
       AVFormatContext *pFormatCtx;
       AVCodecContext *pCodecCtx;
       AVFrame *pFrame;
       AVPacket packet;


       SwsContext * pSwsCtx;
       int videoStream;

       QString rtspURL;

    };

    ffmpeg_decoder.cpp

    ffmpeg_decoder::ffmpeg_decoder()
    {
       pCodecCtx = NULL;
       videoStream=-1;

    }

    ffmpeg_decoder::~ffmpeg_decoder()
    {
       sws_freeContext(pSwsCtx);
    }

    int ffmpeg_decoder::initial(QString &amp; url)
    {
       int err;
       rtspURL=url;
       AVCodec *pCodec;
       av_register_all();
       avformat_network_init();
       pFormatCtx = avformat_alloc_context();
       pFrame = av_frame_alloc();
       err = avformat_open_input(&amp;pFormatCtx, rtspURL.toStdString().c_str(), NULL,
                                 NULL);
       if (err &lt; 0)
       {
           printf("Can not open this file");
           return -1;
       }
       if (avformat_find_stream_info(pFormatCtx,NULL) &lt; 0)
       {
           printf("Unable to get stream info");
           return -1;
       }
       int i = 0;
       videoStream = -1;
       for (i = 0; i &lt; pFormatCtx->nb_streams; i++)
       {
           if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
           {
               videoStream = i;
               break;
           }
       }
       if (videoStream == -1)
       {
           printf("Unable to find video stream");
           return -1;
       }
       pCodecCtx = pFormatCtx->streams[videoStream]->codec;

       width=pCodecCtx->width;
       height=pCodecCtx->height;
       avpicture_alloc(&amp;picture,PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
       pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
       pSwsCtx = sws_getContext(width, height, PIX_FMT_YUV420P, width,
               height, PIX_FMT_RGB24,
               SWS_BICUBIC, 0, 0, 0);

       if (pCodec == NULL)
       {
           printf("Unsupported codec");
           return -1;
       }
       printf("video size : width=%d height=%d \n", pCodecCtx->width,
              pCodecCtx->height);
       if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)
       {
           printf("Unable to open codec");
           return -1;
       }
       printf("initial successfully");
       return 0;
    }

    int ffmpeg_decoder::h264Decodec()
    {
       int frameFinished=0;
      // while (av_read_frame(pFormatCtx, &amp;packet) >= 0)

       if(av_read_frame(pFormatCtx, &amp;packet) >= 0)
       {
           if(packet.stream_index==videoStream)
           {
               avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);
               if (frameFinished)
               {
                   printf("***************ffmpeg decodec*******************\n");
                   mutex.lock();
                   int rs = sws_scale(pSwsCtx, (const uint8_t* const *) pFrame->data,
                                      pFrame->linesize, 0,
                                      height, picture.data, picture.linesize);

                  imageDecoded = QImage();
                  imageDecoded= QImage(this->picture.data[0],this->width,this->height,QImage::Format_RGB888);
                  //imageDecoded = imageDecoded.copy();
                   mutex.unlock();

                   if (rs == -1)
                   {
                       printf("__________Can open to change to des imag_____________e\n");
                       return -1;
                   }
               }
           }
       }
       av_free_packet(&amp;packet);
       av_frame_unref(pFrame);
       av_packet_unref(&amp;packet);
       avpicture_free(&amp;picture);


       return 1;

    }

    void ffmpeg_decoder::close_stream(){

       /*if (pFrame)
           av_free(&amp;pFrame);*/

       if (pCodecCtx)
           avcodec_close(pCodecCtx);

       if (pSwsCtx)
           sws_freeContext(pSwsCtx);

       avpicture_free(&amp;picture);

       if (pFormatCtx)
           avformat_close_input(&amp;pFormatCtx);



    }

    Below is the main thread which do the decoding.

    I am using Qt for creating thread and do decoding

    ffmpeg_decoder * ffmpeg =  new ffmpeg_decoder();;

    if(ffmpeg->initial(rtspURL)==0){
       while (1) {

           ffmpeg->h264Decodec();
           //get frame and do processing right now it disabled, and still see the memory leak.
              .......

           if(stopFlg.load()==1)
               break;

       }
       //close stream if break
       ffmpeg->close_stream();

      }
      else {

          ffmpeg->close_stream();
      }

    When I run 36 thread with different URL I can see the memory usage of the program increase over time.

    I have used valgrind to detect the leak, and here is the relevant part of the log

    This is the first memory leak location

    =14402==    by 0x692017F: av_malloc (in /usr/lib/x86_64-linux-gnu/libavutil-ffmpeg.so.54.31.100)
    ==14402==    by 0x692048D: av_mallocz (in /usr/lib/x86_64-linux-gnu/libavutil-ffmpeg.so.54.31.100)
    ==14402==    by 0x691915E: av_frame_alloc (in /usr/lib/x86_64-linux-gnu/libavutil-ffmpeg.so.54.31.100)
    ==14402==    by 0x419663: ffmpeg_decoder::initial(QString&amp;) (ffmpeg_decoder.cpp:24)
    ==14402==    by 0x41ABEC: RTSP_Player_Object::run() (rtsp_player_object.cpp:15)

    Another

    ==14402== 2,176 bytes in 16 blocks are indirectly lost in loss record 23,113 of 23,379
    ==14402==    at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==14402==    by 0x7780A4E: QImageData::create(unsigned char*, int, int, int, QImage::Format, bool, void (*)(void*), void*) (in /home/vapplica/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Gui.so.5.11.1)
    ==14402==    by 0x7780C30: QImage::QImage(unsigned char*, int, int, QImage::Format, void (*)(void*), void*) (in /home/vapplica/Qt5.11.1/5.11.1/gcc_64/lib/libQt5Gui.so.5.11.1)
    ==14402==    by 0x419B21: ffmpeg_decoder::h264Decodec() (ffmpeg_decoder.cpp:96)

    I have check the documentation and sample on ffmpeg site, and I think I am releasing the allocated memory, but still I can see the memory leak when I run the program.