Recherche avancée

Médias (39)

Mot : - Tags -/audio

Autres articles (88)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

Sur d’autres sites (10810)

  • How AVCodecContext bitrate, framerate and timebase is used when encoding single frame

    28 mars 2023, par Cyrus

    I am trying to learn FFmpeg from examples as there is a tight schedule. The task is to encode a raw YUV image into JPEG format of the given width and height. I have found examples from ffmpeg official website, which turns out to be quite straight-forward. However there are some fields in AVCodecContext that I thought only makes sense when encoding videos(e.g. bitrate, framerate, timebase, gopsize, max_b_frames etc).

    


    I understand on a high level what those values are when it comes to videos, but do I need to care about those when I just want a single image ? Currently for testing, I am just setting them as dummy values and it seems to work. But I want to make sure that I am not making terrible assumptions that will break in the long run.

    


    EDIT :

    


    Here is the code I got. Most of them are copy and paste from examples, with some changes to replace old APIs with newer ones.

    


    #include "thumbnail.h"
#include "libavcodec/avcodec.h"
#include "libavutil/imgutils.h"
#include 
#include 
#include 

void print_averror(int error_code) {
    char err_msg[100] = {0};
    av_strerror(error_code, err_msg, 100);
    printf("Reason: %s\n", err_msg);
}

ffmpeg_status_t save_yuv_as_jpeg(uint8_t* source_buffer, char* output_thumbnail_filename, int thumbnail_width, int thumbnail_height) {
    const AVCodec* mjpeg_codec = avcodec_find_encoder(AV_CODEC_ID_MJPEG);
    if (!mjpeg_codec) {
        printf("Codec for mjpeg cannot be found.\n");
        return FFMPEG_THUMBNAIL_CODEC_NOT_FOUND;
    }

    AVCodecContext* codec_ctx = avcodec_alloc_context3(mjpeg_codec);
    if (!codec_ctx) {
        printf("Codec context cannot be allocated for the given mjpeg codec.\n");
        return FFMPEG_THUMBNAIL_ALLOC_CONTEXT_FAILED;
    }

    AVPacket* pkt = av_packet_alloc();
    if (!pkt) {
        printf("Thumbnail packet cannot be allocated.\n");
        return FFMPEG_THUMBNAIL_ALLOC_PACKET_FAILED;
    }

    AVFrame* frame = av_frame_alloc();
    if (!frame) {
        printf("Thumbnail frame cannot be allocated.\n");
        return FFMPEG_THUMBNAIL_ALLOC_FRAME_FAILED;
    }

    // The part that I don't understand
    codec_ctx->bit_rate = 400000;
    codec_ctx->width = thumbnail_width;
    codec_ctx->height = thumbnail_height;
    codec_ctx->time_base = (AVRational){1, 25};
    codec_ctx->framerate = (AVRational){1, 25};

    codec_ctx->gop_size = 10;
    codec_ctx->max_b_frames = 1;
    codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;
    int ret = av_image_fill_arrays(frame->data, frame->linesize, source_buffer, AV_PIX_FMT_YUV420P, thumbnail_width, thumbnail_height, 32);
    if (ret < 0) {
        print_averror(ret);
        printf("Pixel format: yuv420p, width: %d, height: %d\n", thumbnail_width, thumbnail_height);
        return FFMPEG_THUMBNAIL_FILL_FRAME_DATA_FAILED;
    }

    ret = avcodec_send_frame(codec_ctx, frame);
    if (ret < 0) {
        print_averror(ret);
        printf("Failed to send frame to encoder.\n");
        return FFMPEG_THUMBNAIL_FILL_SEND_FRAME_FAILED;
    }

    ret = avcodec_receive_packet(codec_ctx, pkt);
    if (ret < 0) {
        print_averror(ret);
        printf("Failed to receive packet from encoder.\n");
        return FFMPEG_THUMBNAIL_FILL_SEND_FRAME_FAILED;
    }

    // store the thumbnail in output
    int fd = open(output_thumbnail_filename, O_CREAT | O_RDWR);
    write(fd, pkt->data, pkt->size);
    close(fd);

    // freeing allocated structs
    avcodec_free_context(&codec_ctx);
    av_frame_free(&frame);
    av_packet_free(&pkt);
    return FFMPEG_SUCCESS;
}


    


  • PHP : Convert file with FFMPEG and upload to S3 using shell_exec() and aws cli tools

    18 septembre 2017, par andreaem

    I need a script that handle the upload of a video file from dropzone.js, convert to m4v then generate 5 thumbnails using the name of file appending -(number) to each jpg file (eg : file-1.jpg, file-2.jpg, file-3.jpgetc) and finally upload to s3 using shell_script (or maybe if there is a better way to do this).

    Recap

    1. Upload file in a temp dir
    2. Convert file to .m4v
    3. Generate 5 thumbnails from video
    4. Upload the converted video to Amazon S3
    5. Delete local video file

    Here is my code, at the moment I don’t know where the file goes and nothing seems to be uploaded to Amazon S3 (doing the upload in command-line works, so the credentials are ok).

    Dropzone.js

    $("#dZUpload").dropzone({
        url: "/ajax/admin/admin.acceptVideo.php",
        maxFilesize: 200,
        renameFile: new Date,
        acceptedFiles: "video/*",
        addRemoveLinks: true,
        success: function (file, response) {
             var imgName = response;                              file.previewElement.classList.add("dz-success");
             console.log("Successfully uploaded :" + imgName);
             $('#form_video').val(file);
        },
        error: function (file, response) {file.previewElement.classList.add("dz-error");
        }
    }).autoDiscover = false;
       Dropzone.prototype.defaultOptions.dictRemoveFile = "Rimuovi file";
       Dropzone.on("addedfile", function(file) {
           var cancelLink = Dropzone.createElement('<a>Cancel upload</a>');
        file.previewElement.appendChild(cancelLink);
        cancelLink.addEventListener("click", function(e) {
        e.preventDefault();
        myDropzone.cancelUpload(file);
    });
    });

    PHP

    $target_dir = "/var/www/html/example.com/web/temp/";
    $target_file = $target_dir . basename($_FILES["file"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    // Check if image file is a actual image or fake image
    if(isset($_POST["submit"])) {
       $check = getimagesize($_FILES["file"]["tmp_name"]);
       if($check !== false) {
           echo "File is a video - " . $check["mime"] . ".";
           $uploadOk = 1;
       } else {
           echo "File is not an image.";
           $uploadOk = 0;
       }
    }
    // Check if file already exists
    if (file_exists($target_file)) {
       echo "Sorry, file already exists.";
       $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 200000000) {
       echo "Sorry, your file is too large.";
       $uploadOk = 0;
    }
    // Allow certain file formats
    if($imageFileType != "mp4" &amp;&amp; $imageFileType != "mov" &amp;&amp; $imageFileType != "avi" &amp;&amp; $imageFileType != "m4v" ) {
       echo "Sorry, only MP4 MOV AVI M4V files are allowed.";
       $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
       echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
       if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
           S3Up(VideoConvert(basename( $_FILES["file"]["name"]),random_int('1','9999')));
           echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
       } else {
           echo "Sorry, there was an error uploading your file.";
       }
    }

    function VideoConvert($video, $id) {
       shell_exec('ffmpeg -i ' . $video . ' /var/www/html/example.com/web/temp/' . $id . '.m4v');
       for ($i=0;$i &lt;= 5;$i++) {
           shell_exec('ffmpeg -i ' . $video .' -vf "select=gte(n\,' . $i .'00)" -vframes 1 ' .$id . '-' . $i. '.jpg');
       }

       return '/var/www/html/example.com/web/temp/' . $id . '.m4v';
    }

    function S3Up($video) {
       shell_exec('aws s3 cp ' . $video .' s3://example-video/ --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers');
       sleep(1);
       //shell_exec('rm '. $video);
    }

    Here is my error.log line relating to s3 upload :

    error.log

    example.mp4: No such file or directory
    Traceback (most recent call last):
     File "/usr/local/bin/aws", line 19, in <module>
       import awscli.clidriver
     File "/usr/local/lib/python2.7/dist-packages/awscli/clidriver.py", line 17, in <module>
       import botocore.session
     File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 26, in <module>
       import botocore.credentials
     File "/usr/local/lib/python2.7/dist-packages/botocore/credentials.py", line 22, in <module>
       from dateutil.parser import parse
    ImportError: No module named dateutil.parser
    </module></module></module></module>

    How can I improve this ? I’ve tried using aws php api but got some problems with credentials, cli tools don’t have.

    Behavior

    At the moment dropzone.js stop uploading at 50% if I put a file of 8 MB, php maxUploadSize directive is set to 201M, php upload temp folder is inside the site root directory and permissions set to 7777. File where uploaded if I put a smallest file of 200Kb but don’t convert and make a 0 byte file.

  • wav file from fluent-ffmpeg not working for asterisk if returned as stream nodejs

    7 mars 2023, par Sunil Garg

    I am using aws polly for text to speech and generating mp3 out of it, to get the certain wav as asterisk needs wav with specific paramters, I am using fluent-ffmpeg npm package.

    &#xA;

    I generated the file by providing the destination path, and returned from the api using sendFile method on response. Here is the code

    &#xA;

    _convertMp3ToWav(mp3Buffer, destPath) {&#xA;        const { options } = this;&#xA;        return new Promise((resolve, reject) => {&#xA;            ffmpeg(mp3Buffer)&#xA;                .audioFilter(`highpass=f=300, lowpass=f=3400`)&#xA;                .outputOptions([`-ar 8000`, `-ac 1`]&#xA;                .output(destPath)&#xA;                .on(&#x27;error&#x27;, (err) => {&#xA;                    log.error(`An error occured: ${err?.message || err?.stack}`);&#xA;                    reject({ err: &#x27;Failed to convert from mp3 to wav&#x27; });&#xA;                })&#xA;                .on(&#x27;end&#x27;, async () => {&#xA;                    log.info(`successfully converted mp3 to wav at ${destPath}`);&#xA;                    resolve({ msg: "voice file generated" });&#xA;                }).run();&#xA;        });&#xA;    }&#xA;&#xA;res.status(200).sendFile(wavFilePath)&#xA;

    &#xA;

    file is playable on local machine as well as working on asterisk server.

    &#xA;

    But i tried to avoid intermediate file generation, generated the stream and returned that stream using res.send(buffer)

    &#xA;

    Here is the code

    &#xA;

    _convertMp3ToWav(mp3Buffer) {&#xA;        return new Promise((resolve, reject) => {&#xA;            // create a writable output stream to store wav stream&#xA;            const outputStream = new Stream.Writable();&#xA;            const buffer = [];&#xA;            // redefining _write function to write wav stream&#xA;            outputStream._write = function (chunk, encoding, done) {&#xA;                buffer.push(chunk);&#xA;                done();&#xA;            };&#xA;            // convert mp3 buffer to wav buffer &#xA;            ffmpeg(mp3Buffer)&#xA;                .audioFilter(`highpass=f=300, lowpass=f=3400`)&#xA;                .outputOptions([`-ar 8000`, `-ac 1`])&#xA;                .output(outputStream)&#xA;                .format(&#x27;wav&#x27;)&#xA;                .on(&#x27;error&#x27;, (err) => {&#xA;                    log.error(`An error occured: ${err?.message || err?.stack}`);&#xA;                    reject({ err: &#x27;Failed to convert from mp3 to wav&#x27; });&#xA;                })&#xA;                .on(&#x27;end&#x27;, async () => {&#xA;                    try {&#xA;                        // create wav buffer &#xA;                        const wavBuffer = Buffer.concat(buffer);&#xA;                        log.info(`successfully converted mp3 to wav buffer`);&#xA;                        &#xA;                        resolve({ wavBuffer });&#xA;                    }&#xA;                    catch (err) {&#xA;                        log.error(`failed to create wav buffer : ${err?.message || err?.stack}`);&#xA;                        reject({ err: &#x27;Failed to create wav buffer&#x27; });&#xA;                    }&#xA;                }).run();&#xA;        });&#xA;    }&#xA;&#xA;const buffer = await this._convertMp3ToWav(bufferStream);&#xA;res.send(buffer.wavBuffer);&#xA;

    &#xA;

    I tried using as well

    &#xA;

    // set content type to audio/wav&#xA;res.set(&#x27;Content-Type&#x27;, &#x27;audio/wav&#x27;);&#xA;

    &#xA;

    the file is playable on local but not working on asterisk.

    &#xA;

    Is there any problem with sending or encoding issues ?

    &#xA;

    Update1

    &#xA;

    tried writing directly to the res like this

    &#xA;

    _convertMp3ToWav(mp3Buffer, res) {&#xA;    return new Promise((resolve, reject) => {&#xA;        // create a writable output stream to send wav stream in response&#xA;        const outputStream = new Stream.Writable();&#xA;        outputStream._write = function (chunk, encoding, done) {&#xA;            res.write(chunk, encoding);&#xA;            done();&#xA;        };&#xA;        // convert mp3 buffer to wav buffer&#xA;        ffmpeg(mp3Buffer)&#xA;            .audioFilter(`highpass=f=300, lowpass=f=3400`)&#xA;            .outputOptions([`-ar 8000`, `-ac 1`])&#xA;            .output(outputStream)&#xA;            .format(&#x27;wav&#x27;)&#xA;            .on(&#x27;error&#x27;, (err) => {&#xA;              reject({ err: &#x27;Failed to convert from mp3 to wav&#x27; });&#xA;            })&#xA;            .on(&#x27;end&#x27;, async () => {&#xA;                try {&#xA;         // end the response stream&#xA;                    res.end();&#xA;                    resolve();&#xA;                }&#xA;                catch (err) {&#xA;                    reject({ err: &#x27;Failed to send wav buffer in response&#x27; });&#xA;                }&#xA;            }).run();&#xA;    });&#xA;}&#xA;

    &#xA;

    files generated from both functions mentioned in questions are not playable on asterisk, I checked the properties of these files using this website

    &#xA;

    and both files are showing

    &#xA;

    at least one of the list chunks has an incorrect length&#xA;

    &#xA;

    other properties that asterisk understands are the same

    &#xA;

    enter image description here

    &#xA;

    and this file i can play on windows machine. Any help ?

    &#xA;