Recherche avancée

Médias (91)

Autres articles (100)

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

  • XMP PHP

    13 mai 2011, par

    Dixit Wikipedia, XMP signifie :
    Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
    Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
    XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)

  • Sélection de projets utilisant MediaSPIP

    29 avril 2011, par

    Les exemples cités ci-dessous sont des éléments représentatifs d’usages spécifiques de MediaSPIP pour certains projets.
    Vous pensez avoir un site "remarquable" réalisé avec MediaSPIP ? Faites le nous savoir ici.
    Ferme MediaSPIP @ Infini
    L’Association Infini développe des activités d’accueil, de point d’accès internet, de formation, de conduite de projets innovants dans le domaine des Technologies de l’Information et de la Communication, et l’hébergement de sites. Elle joue en la matière un rôle unique (...)

Sur d’autres sites (10912)

  • Why does my lambda doesn't end with an expected request end event ? [on hold]

    16 avril 2019, par Nachum Freedman
    const now = (...a) =>
     console.log(...a, Math.floor(new Date().getTime() / 1000) % 3600);

    exports.handler = (event, context, callback) => {
     console.log("PROCESS START");

     const FROM_BUCKET = event.Records[0].s3.bucket.name;
     const Key = decodeURIComponent(
       event.Records[0].s3.object.key.replace(/\+/g, " ")
     );
     const uploadKey = Key.replace(/.webm/, ".mp4");

     console.log("FROM BUCKET", FROM_BUCKET);
     console.log("Recived key", Key);

     const slicedFilename = Key.slice(-4) !== "webm" ? Key.slice(-4) : ".webm";
     const extension =
       slicedFilename === ".mp4"
         ? ".mp4"
         : slicedFilename === ".pcm"
         ? ".pcm"
         : slicedFilename === ".webm"
         ? ".webm"
         : console.log("THE FILE NAME IS INCORRECT PLEASE CHECK @:", Key);

     console.log("Extension detected is", extension);

     const downloadKey =
       Key.slice(-4) !== "webm"
         ? Key.slice(0, -4) + extension
         : Key.slice(0, -5) + extension;

     const downloadParams = { Bucket: FROM_BUCKET, Key: downloadKey };

     console.log("Downloading file from S3", downloadParams);

     const mobileDownloadExtension =
       extension === ".mp4" ? ".pcm" : extension === ".pcm" ? ".mp4" : null;

     const mobileDownloadParams = {
       Bucket: FROM_BUCKET,
       Key: Key.slice(0, -4) + mobileDownloadExtension
     };

     console.log("Downloading file from S3", mobileDownloadParams);

     const tmpNamespace = Math.random();

     const isMobile = extension === ".mp4" || extension === ".pcm";
     let firstDigit = 0;
     let restOfTheOffset = 0;
     if (isMobile) {
       console.log(
         "If apply, second key to download is a file type",
         mobileDownloadExtension
       );
       const offsetTime = Key.slice(
         Key.lastIndexOf("_") + 1,
         Key.indexOf(".")
       ).replace("-", "");
       if (offsetTime > 999) {
         firstDigit = 1;
         restOfTheOffset = offsetTime.slice(1, offsetTime.length);
       } else {
         firstDigit = 0;
         restOfTheOffset = offsetTime;
       }
     }
     console.log("FIle recieved from Mobile?", isMobile);

     Promise.all([
       // download file from s3
       new Promise((resolve, reject) =>
         s3.getObject(downloadParams, (err, response) => {
           if (err) {
             console.error(
               "Error while downloading file from S3",
               downloadParams,
               err.code,
               "-",
               err.message
             );
             return reject(err);
           }
           console.log("Successfully downloaed file from S3", downloadParams);
           fs.writeFile(
             tmp + "/input" + tmpNamespace + extension,
             response.Body,
             err =>
               err
                 ? console.log(err.code, "-", err.message) || reject(err)
                 : console.log(tmp + "/input" + tmpNamespace + extension) ||
                   resolve()
           );
         })
       ),
       new Promise((resolve, reject) => {
         extension !== ".mp4" && extension !== ".pcm"
           ? resolve()
           : s3.getObject(mobileDownloadParams, (err, response) => {
               if (err) {
                 console.error(
                   "Error while downloading file from S3",
                   mobileDownloadParams,
                   err.code,
                   "-",
                   err.message
                 );
                 return reject(err);
               }
               console.log(
                 "Successfully downloaed file from S3",
                 mobileDownloadParams
               );
               fs.writeFile(
                 tmp + "/input" + tmpNamespace + mobileDownloadExtension,
                 response.Body,
                 err =>
                   err
                     ? console.log(err.code, "-", err.message) || reject(err)
                     : console.log(
                         tmp + "/input" + tmpNamespace + mobileDownloadExtension
                       ) || resolve()
               );
             });
       })
     ])
       .then(() =>
         Promise.all([
           // call the answerVideoReady -> PROCESSING mobileDownloadExtnesion is actually the second file we seek (if mp4 then pcm)
           // ,

           isMobile
             ? Promise.resolve()
                 .then(() => {
                   new Promise((resolve, reject) => {
                     console.log("CALLING VIDEO PROCESSING", Key);
                     videoProcessing(Key);
                     resolve();
                   });
                 })
                 .then(
                   () =>
                     // run ffmpeg
                     // ffmpeg -i tmp/input.mp4 -movflags faststart -acodec copy -vcodec copy output.mp4
                     now("FFMPEG CONVERT PCM TO WAV START") ||
                     new Promise((resolve, reject) =>
                       spawn("./ffmpeg/ffmpeg", [
                         "-f",
                         "s16le",
                         "-ar",
                         "16000",
                         "-ac",
                         "1",
                         "-i",
                         tmp + "/input" + tmpNamespace + ".pcm",
                         "-ar",
                         "44100",
                         "-ac",
                         "2",
                         tmp + "/input" + tmpNamespace + ".wav"
                       ]).on("close", code =>
                         console.log("FFMPEG CONVERT PCM TO WAV SUCCESS", code) ||
                         !code
                           ? resolve()
                           : reject()
                       )
                     )
                 )
                 .then(
                   () =>
                     // run ffmpeg
                     // ffmpeg -i tmp/input.mp4 -movflags faststart -acodec copy -vcodec copy output.mp4
    //more stuff
                     now("FFMPEG COMBINE MP4 AND WAV START") ||
                     new Promise(
                       (resolve, reject) =>
                         console.log(
                           [
                             "-i",
                             tmp + "/input" + tmpNamespace + ".mp4",
                             "-itsoffset",
                             "-" + firstDigit + "." + restOfTheOffset,
                             "-i",
                             tmp + "/input" + tmpNamespace + ".wav",
                             "-movflags",
                             "faststart",
                             "-filter_complex",
                             " [1:0] apad ",
                             "-shortest",
                             tmp + "/output" + tmpNamespace + ".mp4"
                           ].join(" ")
                         ) ||
                         spawn("./ffmpeg/ffmpeg", [
                           "-i",
                           tmp + "/input" + tmpNamespace + ".mp4",
                           "-itsoffset",
                           "-" + firstDigit + "." + restOfTheOffset,
                           "-i",
                           tmp + "/input" + tmpNamespace + ".wav",
                           "-movflags",
                           "faststart",
                           "-filter_complex",
                           " [1:0] apad ",
                           "-shortest",
                           tmp + "/output" + tmpNamespace + ".mp4"
                         ]).on("close", code =>
                           console.log(
                             "FFMPEG COMBINE MP4 AND WAV SUCCESS",
                             code
                           ) || !code
                             ? resolve()
                             : reject()
                         )
                     )
                 )
             : Promise.resolve()
                 .then(() => {
                   new Promise((resolve, reject) => {
                     console.log("CALLING VIDEO PROCESSING", Key);
                     videoProcessing(Key);
                     resolve();
                   });
                 })
                 .then(
                   () =>
                     now("FFMPEG SEND WEBM START") ||
                     new Promise((resolve, reject) => {
                       exec(
                         "./sed -i '1,4d;$d' " +
                           tmp +
                           "/input" +
                           tmpNamespace +
                           ".webm"
                       ).on(
                         "close",
                         code =>
                           console.log("FFMPEG SEND WEBM SUCCESS", code) ||
                           (!code ? resolve() : reject())
                       );
                     })
                 )
                 .then(
                   () =>
                     // run ffmpeg
                     // ffmpeg -i tmp/input.mp4 -movflags faststart -acodec copy -vcodec copy output.mp4
                     now("FFMPEG WEBM WEB READY START") ||
                     new Promise((resolve, reject) =>
                       (a => {
                         a.stdout.on("data", data => {
                           //console.log(`child stdout:\n${data}`);
                         });
                         a.stderr.on("data", data => {
                           //console.log(`child stdout:\n${data}`);
                         });
                         return a;
                       })(
                         spawn("./ffmpeg/ffmpeg", [
                           "-i",
                           tmp + "/input" + tmpNamespace + extension,
                           "-movflags",
                           "faststart",
                           "-acodec",
                           "aac",
                           "-vcodec",
                           "h264",
                           "-preset",
                           "slow",
                           "-crf",
                           "26",
                           "-r",
                           "25",
                           tmp + "/output" + tmpNamespace + ".mp4"
                         ])
                       ).on("close", code =>
                         console.log(
                           "FFMPEG WEBM WEB READY FINISHED WITH:",
                           code
                         ) || !code
                           ? resolve()
                           : reject()
                       )
                     )
                 )
         ])
       )
       .then(
         () =>
           new Promise((resolve, reject) =>
             // upload the output.mp4 to s3
             fs.readFile(
               tmp + "/output" + tmpNamespace + ".mp4",
               (err, filedata) => {
                 if (err) {
                   console.log("ERROR WHILE TRYING TO READ FILE", err);
                   throw err;
                 }
                 console.log("KEEEEYYY", uploadKey),
                   s3.putObject(
                     {
                       Bucket: TO_BUCKET,
                       Key: uploadKey,
                       Body: filedata
                     },
                     (err, response) => {
                       console.log(response);
                       if (err) {
                         console.log(
                           "ERROR WHILE UPLOADING FILE TO S3",
                           err,
                           response
                         );
                         return reject(err);
                       }
    //uploading file
                       console.log(
                         "Successfully uploaded file to " + TO_BUCKET,
                         Key
                       );
                       resolve();
                     }
                   );
               }
             )
           )

         // call the answerVideoReady -> COMPLETED, context.success  or ERROR, context.fail or error on set status to ERROR -> fail
       )
       .then(p =>
         videoCompleted(Key)
           .then(c => context.succeed())
           .catch(es => context.fail(es))
       )
       .catch(
         e =>
           console.log("catch for upload error with:", e) ||
           videoError(Key)
             .then(p => context.fail(e))
             .catch(ee => context.fail(ee))
       );
    };
  • How to run bash script from NodeJS application correctly ?

    13 mars 2019, par z Eyeland

    I am running a node application that uses spawn child-process to start this script

    #!/bin/bash
    FILEPATH="$1"
    COMPRESSIONPATH="$2"
    ffmpeg -i $FILEPATH -vcodec h264 -acodec mp2 $COMPRESSIONPATH
    sudo rm $FILEPATH
    curl -H "Content-Type:application/json" -X GET
    http://localhost:3000/clovis/api/led

    The script never finishes. If the ffmpeg compression command takes long then x amount of time then the process just stops and holds the process. I cant tell so by using the command ps-ef. Is there another way to start bash scripts from NodeJS other then spawn ? Does the NodeJS child-process have a time limit ?

  • audio file conversion using ffmpeg

    15 juillet 2014, par user3789242

    I’m building a voice recording project.so far I have succeeded in recording the voice as .wav audio file, and I’m using the ffmpeg for the user to be able to convert the audio file into a selected format (mp3, pcm, wma). What I want to do is to allow the user to select the format before recording the voice so that when stop recording the file will be saved in the selected format maybe by using ffmpeg conversion.

    I have been searching the net for weeks for any demo using JavaScript and html5 but can’t find any. What I have tried so far is to save the audio file in a folder using Ajax/php and I’m trying to call that file in order to convert it but this method is very complicated and is not working. Any suggestions please. If you can also help me with a demo it would be most appreciated. This is my code so far :

    function handleWAV(blob) {

    if (currentEditedSoundIndex !== -1) {
    $('#inFile2 tr:nth-child(' + (currentEditedSoundIndex + 1) + ')').remove();

    }

    var url = URL.createObjectURL(blob);

    var li = document.createElement('li');
    var au = document.createElement('audio');
    var hf = document.createElement('a');

    au.controls = true;
    au.src = url;
    hf.href = url;
    hf.download = 'audio_recording_' + new Date().getTime() + '.wav';
    hf.innerHTML = hf.download;
    li.appendChild(au);
    li.appendChild(hf);
    inFile2.appendChild(li);


    fileName=hf.download;

    var reader = new FileReader();
    reader.onload = function(event){
       var fd = new FormData();
       var Name = encodeURIComponent('audio_recording_' + new Date().getTime() + '.wav');
       console.log("name = " + Name);
       fd.append('fname', Name);
       fd.append('data', event.target.result);
       $.ajax({
           type: 'POST',
           url: 'upload.php',
           data: fd,
           processData: false,
           contentType: false,
           success: function(data){
               //console.log(data);
           }
       });
    };      
    reader.readAsDataURL(blob);



    var fileBuffer;



    // create ffmpeg worker
    function getFFMPEGWorker() {


        var ffmpegWorker = new Worker('worker.js');

        ffmpegWorker.addEventListener('message', function(event) {
            var message = event.data;
            console.log(message.type);
            if (message.type === "ready" && window.File && window.FileList && window.FileReader) {
                // script loaded, hide loader

            } else if (message.type == "stdout") {
                console.log(message.data);
            } else if (message.type == "stderr") {
                console.log(message.data);
            } else if (message.type == "done") {
                var code = message.data.code;
                console.log(code);
                console.log(message.data);
                var outFileNames = Object.keys(message.data.outputFiles);

                console.log(outFileNames);
                if (code == 0 && outFileNames.length) {
                    var outFileName = outFileNames[0];
                    console.log(outFileName);
                    var outFileBuffer = message.data.outputFiles[outFileName];
                    console.log(outFileBuffer);
                    var src = url;
                    console.log(url);
                    $("#downloadLink2").attr('href', src);
                    $("#download2").show();
                } else {
                    $("#error").show();
                }

            }
        }, false);
        return ffmpegWorker;
    }

    // create ffmpeg worker
    var ffmpegWorker = getFFMPEGWorker();
    var ffmpegRunning = false;
    if (ffmpegRunning) {
        ffmpegWorker.terminate();
        ffmpegWorker = getFFMPEGWorker();
    }
    ffmpegRunning = true;



    // hide download div
    $("#download2").hide();

    // change download file name
    var fileNameExt = fileName.substr(fileName.lastIndexOf('.') + 1);

    var outFileName = fileName.substr(0, fileName.lastIndexOf('.')) + "." + getOutFormat();

    $("#downloadLink2").attr("download2", outFileName);
    $("#downloadLink2").text(outFileName);

    var arguments = [];
    arguments.push("-i");
    arguments.push(fileName);

    arguments.push("-b:a");
    arguments.push(getBitrate());

    switch (getOutFormat()) {
        case "mp3":
            arguments.push("-acodec");
            arguments.push("libmp3lame");
            arguments.push("out.mp3");
            break;

        case "wma":
            arguments.push("-acodec");
            arguments.push("wmav1");
            arguments.push("out.asf");
            break;

        case "pcm":
            arguments.push("-f");
            arguments.push("s16le");
            arguments.push("-acodec");
            arguments.push("pcm_s16le");
            arguments.push("out.pcm");
    }

    ffmpegWorker.postMessage({
        type: "command",
        arguments: arguments,
        files: [
            {
                "name": fileName,
                "buffer": fileBuffer
            }
        ]
    });


    function getOutFormat() {
    return $('input[name=format]:checked').val();
    }

    function getBitrate() {
    return $('input[name=bitrate]:checked').val();
    }

    function readInputFile(file) {


    // load file content
    var reader = new FileReader();
    reader.onload = function(e) {

        fileName = file.name;
        console.log(fileName);
        fileBuffer = e.target.result;
    }
    reader.readAsArrayBuffer(file);

    }



    function handleFileSelect(event) {
    var files = event.target.files; // FileList object

    console.log(files);
    // files is a FileList of File objects. display first file name
    file = files[0];

    console.log(file);
    if (file) {

        readInputFile(file);
        console.log(file);

    }
    }

    // setup input file listeners
    el=document.getElementById('inFile2');

    el.addEventListener('change',handleFileSelect, true);

    }

    This code is for the download link where the user will be able to download the audio file also the conversion function happening in it.

    As I said earlier the audio files are uploaded in a folder upload using Ajax.