Recherche avancée

Médias (1)

Mot : - Tags -/école

Autres articles (111)

  • Script d’installation automatique de MediaSPIP

    25 avril 2011, par

    Afin de palier aux difficultés d’installation dues principalement aux dépendances logicielles coté serveur, un script d’installation "tout en un" en bash a été créé afin de faciliter cette étape sur un serveur doté d’une distribution Linux compatible.
    Vous devez bénéficier d’un accès SSH à votre serveur et d’un compte "root" afin de l’utiliser, ce qui permettra d’installer les dépendances. Contactez votre hébergeur si vous ne disposez pas de cela.
    La documentation de l’utilisation du script d’installation (...)

  • Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs

    12 avril 2011, par

    La manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
    Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.

  • Que fait exactement ce script ?

    18 janvier 2011, par

    Ce script est écrit en bash. Il est donc facilement utilisable sur n’importe quel serveur.
    Il n’est compatible qu’avec une liste de distributions précises (voir Liste des distributions compatibles).
    Installation de dépendances de MediaSPIP
    Son rôle principal est d’installer l’ensemble des dépendances logicielles nécessaires coté serveur à savoir :
    Les outils de base pour pouvoir installer le reste des dépendances Les outils de développements : build-essential (via APT depuis les dépôts officiels) ; (...)

Sur d’autres sites (9933)

  • ffmpeg avformat_open_input() function causes memory leak when receiving live stream

    12 septembre 2023, par george_d

    I have live streams (can be UDP or HLS, video codec is H264), from which I grab frames for further processing.

    


    For this purpose, I use ffmpeg + nvjpeg + cuda libraries.

    


    However I noticed memory leak - memory usage periodically (every 10-20 seconds) is increased by 100-400 KB, the amount and period may vary.

    


    After disabling pieces of code one by one, I realized that it is avformat_open_input() which causes memory leak.

    


    No matter which buffer settings (https://ffmpeg.org/ffmpeg-protocols.html#udp) I choose for UDP, the leak still persists. Same goes for HLS streams.

    


    I tried to find anything related to this problem, but all the sources I found claimed that this problem took place in the past and has been fixed.

    


    Is there some mysterious setting I am missing, so that memory could be freed properly ?

    


    Or is this memory supposed to be freed when processing frames (i.e. using av_read_frame() and av_packet_unref(), etc) ?

    


    Minimal example of code to reproduce the problem :

    


    avformat_example.cpp

    


    #include &#xA;extern "C" {&#xA;    #include <libavformat></libavformat>avformat.h>&#xA;    #include <libavcodec></libavcodec>avcodec.h>&#xA;}&#xA;&#xA;int main(int argc, char *argv[]){&#xA;    if (argc &lt; 2) {&#xA;      return 1;&#xA;    }&#xA;&#xA;    char* inputSource = argv[1];&#xA;    AVFormatContext *ctx = NULL;&#xA;&#xA;    if (avformat_open_input(&amp;ctx, inputSource, NULL, NULL) != 0) {&#xA;        av_log(NULL,&#xA;               AV_LOG_ERROR,&#xA;               "Cannot open &#x27;%s&#x27;",&#xA;               inputSource);&#xA;        return 1;&#xA;    }&#xA;&#xA;    /*&#xA;    This loop is placed here to demonstrate&#xA;    avformat_open_input() causing leak.&#xA;    Actually, instead of noop loop there is logic of getting and processing frames,&#xA;    but it doesn&#x27;t matter now.&#xA;    As loop goes on, the amount of leaked memory increases.&#xA;    */&#xA;    while(true) {&#xA;      sleep(1);&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    Compile with :

    &#xA;

    g&#x2B;&#x2B; avformat_example.cpp -lavcodec -lavutil -lavformat -I/usr/include/ffmpeg-cuda -o avformat_open_input_example&#xA;

    &#xA;

    Run :

    &#xA;

    ./avformat_open_input_example "udp://127.0.0.1:5000?reuse=1&amp;pkt_size=1316&amp;buffer_size=1310720&amp;fifo_size=40000"&#xA;

    &#xA;

    Version of ffmpeg underlying libraries :

    &#xA;

    libavutil      58.  7.100 / 58.  7.100&#xA;libavcodec     60. 11.100 / 60. 11.100&#xA;libavformat    60.  5.100 / 60.  5.100&#xA;libavdevice    60.  2.100 / 60.  2.100&#xA;libavfilter     9.  8.100 /  9.  8.100&#xA;libswscale      7.  2.100 /  7.  2.100&#xA;libswresample   4. 11.100 /  4. 11.100&#xA;

    &#xA;

  • Dynamically record parts of a video stream using ffmpeg based on incoming events

    12 septembre 2023, par ganjim

    Say I have a RTSP stream running on some server.

    &#xA;

    I want to record parts of this video stream based on some events that will come up on my machine.&#xA;My goal is to record 10 seconds before up to 10 seconds after the PTS in any received event. Consider that I have a way to synchronize the PTS between the sender and the receiver, but by the time I receive the events, its already streamed and is in the past.&#xA;So I either need to have the ffmpeg command running already, or to have buffered streaming video in my memory.

    &#xA;

    I just added some code with comments as a way to simulate the situation, it is not complete as I still don't have a working solution. But I'm looking to understand if ffmpeg has capabilities for dealing with rtsp streams suitable for this situation.

    &#xA;

    const { spawn } = require(&#x27;child_process&#x27;);&#xA;&#xA;function processEvent(event){&#xA;  &#xA;  let startTime = event.pts - 10&#xA;  let endTime = event.pts &#x2B; 10&#xA;&#xA;  const ffmpegArgs = [&#xA;    &#x27;-i&#x27;, "rtspUrl",&#xA;    &#x27;-ss&#x27;, startTime.toString(),&#xA;    &#x27;-to&#x27;, endTime.toString(),&#xA;    &#x27;-c&#x27;, &#x27;copy&#x27;,&#xA;    &#x27;-f&#x27;, &#x27;mp4&#x27;,&#xA;    `output_${startTime}_${endTime}.mp4` // Output filename&#xA;  ];&#xA;  // Here it is obviously not possible to give ffmpeg a negative startTime.&#xA;  // We either have to have spawned the ffmpeg command and somehow give it a starting time for recording on demand or have a buffering system in place.&#xA;  // Having a buffer to store every raw frame and then attach them after endTime is also considerably CPU and memory intensive.&#xA;  // Looking for alternative ways to achieve the same output.&#xA;&#xA;  const ffmpegProcess = spawn(&#x27;ffmpeg&#x27;, ffmpegArgs, {&#xA;    stdio: &#x27;inherit&#x27;&#xA;  });&#xA;}&#xA;&#xA;// Code to simulate the events:&#xA;// imagine these pts to be relative to Date.now(), so using negative PTS to show the events are going to be in the past by the time we receive them.&#xA;setTimeout(() => {&#xA;  const event1= { pts: -30 };&#xA;  processEvent(event1);&#xA;}, 1000);&#xA;&#xA;setTimeout(() => {&#xA;  const event2 = { pts: -20 };&#xA;  processEvent(event2);&#xA;}, 5000);&#xA;

    &#xA;

  • Detect volume via mic, start recording, end on silence, transcribe and sent to endpoint

    15 juin 2023, par alphadmon

    I have been attempting to get this to work in many ways but I can't seem to get it right. Most of the time I get a part of it to work and then when I try to make other parts work, I generally break other things.

    &#xA;

    I am intercepting the volume coming from the mic and if it is louder than 50, I start a recording. I then keep recording until there is a silence, if the silence is equal to 5 seconds I then stop the recording.

    &#xA;

    I then send the recording to be transcribed by whisper using OpenAI API.

    &#xA;

    Once that is returned, I then want to send it to the open ai chat end point and get the response.

    &#xA;

    After that, I would like to start listening again.

    &#xA;

    Here is what I have that is sort of working so far, but the recording is an empty file always :

    &#xA;

    // DETECT SPEECH&#xA;const recorder = require(&#x27;node-record-lpcm16&#x27;);&#xA;&#xA;// TRANSCRIBE&#xA;const fs = require("fs");&#xA;const ffmpeg = require("fluent-ffmpeg");&#xA;const mic = require("mic");&#xA;const { Readable } = require("stream");&#xA;const ffmpegPath = require("@ffmpeg-installer/ffmpeg").path;&#xA;require(&#x27;dotenv&#x27;).config();&#xA;&#xA;// CHAT&#xA;const { Configuration, OpenAIApi } = require("openai");&#xA;&#xA;// OPEN AI&#xA;const configuration = new Configuration({&#xA;    organization: process.env.OPENAI_ORG,&#xA;    apiKey: process.env.OPENAI_API_KEY,&#xA;});&#xA;const openai = new OpenAIApi(configuration);&#xA;&#xA;// SETUP&#xA;ffmpeg.setFfmpegPath(ffmpegPath);&#xA;&#xA;// VARS&#xA;let isRecording = false;&#xA;const audioFilename = &#x27;recorded_audio.wav&#x27;;&#xA;const micInstance = mic({&#xA;    rate: &#x27;16000&#x27;,&#xA;    channels: &#x27;1&#x27;,&#xA;    fileType: &#x27;wav&#x27;,&#xA;});&#xA;&#xA;// DETECT SPEECH&#xA;const file = fs.createWriteStream(&#x27;determine_speech.wav&#x27;, { encoding: &#x27;binary&#x27; });&#xA;const recording = recorder.record();&#xA;recording.stream().pipe(file);&#xA;&#xA;&#xA;recording.stream().on(&#x27;data&#x27;, async (data) => {&#xA;    let volume = parseInt(calculateVolume(data));&#xA;    if (volume > 50 &amp;&amp; !isRecording) {&#xA;        console.log(&#x27;You are talking.&#x27;);&#xA;        await recordAudio(audioFilename);&#xA;    } else {&#xA;        setTimeout(async () => {&#xA;            console.log(&#x27;You are quiet.&#x27;);&#xA;            micInstance.stop();&#xA;            console.log(&#x27;Finished recording&#x27;);&#xA;            const transcription = await transcribeAudio(audioFilename);&#xA;            console.log(&#x27;Transcription:&#x27;, transcription);&#xA;            setTimeout(async () => {&#xA;                await askAI(transcription);&#xA;            }, 5000);&#xA;        }, 5000);&#xA;    }&#xA;});&#xA;&#xA;function calculateVolume(data) {&#xA;    let sum = 0;&#xA;&#xA;    for (let i = 0; i &lt; data.length; i &#x2B;= 2) {&#xA;        const sample = data.readInt16LE(i);&#xA;        sum &#x2B;= sample * sample;&#xA;    }&#xA;&#xA;    const rms = Math.sqrt(sum / (data.length / 2));&#xA;&#xA;    return rms;&#xA;}&#xA;&#xA;// TRANSCRIBE&#xA;function recordAudio(filename) {&#xA;    const micInputStream = micInstance.getAudioStream();&#xA;    const output = fs.createWriteStream(filename);&#xA;    const writable = new Readable().wrap(micInputStream);&#xA;&#xA;    console.log(&#x27;Listening...&#x27;);&#xA;&#xA;    writable.pipe(output);&#xA;&#xA;    micInstance.start();&#xA;&#xA;    micInputStream.on(&#x27;error&#x27;, (err) => {&#xA;        console.error(err);&#xA;    });&#xA;}&#xA;&#xA;// Transcribe audio&#xA;async function transcribeAudio(filename) {&#xA;    const transcript = await openai.createTranscription(&#xA;        fs.createReadStream(filename),&#xA;        "whisper-1",&#xA;    );&#xA;    return transcript.data.text;&#xA;}&#xA;&#xA;// CHAT&#xA;async function askAI(text) {&#xA;    let completion = await openai.createChatCompletion({&#xA;        model: "gpt-4",&#xA;        temperature: 0.2,&#xA;        stream: false,&#xA;        messages: [&#xA;            { role: "user", content: text },&#xA;            { role: "system", content: "Act like you are a rude person." }&#xA;        ],&#xA;    });&#xA;&#xA;    completion = JSON.stringify(completion.data, null, 2);&#xA;    console.log(completion);&#xA;}&#xA;

    &#xA;