Recherche avancée

Médias (1)

Mot : - Tags -/artwork

Autres articles (90)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

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

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

Sur d’autres sites (7939)

  • Extracting the h264 part of a video file (demuxing)

    3 mars 2016, par MOHW

    I am trying to demux a video file into the video part (h264, mpeg4, h265, vp8, etc) and the audio part (mp3, aac, ac3, etc) and the subtitle part (srt) using ffmpeg in c++.

    The audio part came out alright and played on all the media players I have, so also did the subtitle part. The video part however came out WITHOUT error and saved into a .h264 file but when I use ffprobe to check it or ffplay to play it, it always give the error "Invalid data found when processing input".

    The code below

    /* Separate a media file into audio, video and subtitle files (demuxing, complex) */
    //TODO: mute error when subtitle is not present
    #define __STDC_CONSTANT_MACROS

    extern "C"
    {
       #include "libavformat/avformat.h"
    }


    int main()
    {
       //Input AVFormatContext and Output AVFormatContext
       AVOutputFormat *ofmt_a = NULL, *ofmt_v = NULL, *ofmt_s = NULL;
       AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx_a = NULL, *ofmt_ctx_v = NULL, *ofmt_ctx_s = NULL;
       AVPacket pkt;

       int ret, i;
       int videoindex=-1, audioindex=-1, srtindex=-1;
       int frame_index=0;

       //Input file URL
       const char *in_filename  = "sample.mp4";

       //Output file URL
       const char *out_filename_v = "sample.h264";
       const char *out_filename_a = "sample.mp3";
       const char *out_filename_s = "sample.srt";

       av_register_all();

       //Input
       if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
           printf( "Could not open input file.");
           goto end;
       }
       if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
           printf( "Failed to retrieve input stream information");
           goto end;
       }

       //Output
       avformat_alloc_output_context2(&ofmt_ctx_v, NULL, NULL, out_filename_v);
       if (!ofmt_ctx_v) {
           printf( "Could not create output context\n");
           ret = AVERROR_UNKNOWN;
           goto end;
       }
       ofmt_v = ofmt_ctx_v->oformat;

       avformat_alloc_output_context2(&ofmt_ctx_a, NULL, NULL, out_filename_a);
       if (!ofmt_ctx_a) {
           printf( "Could not create output context\n");
           ret = AVERROR_UNKNOWN;
           goto end;
       }
       ofmt_a = ofmt_ctx_a->oformat;

       avformat_alloc_output_context2(&ofmt_ctx_s, NULL, NULL, out_filename_s);
       if (!ofmt_ctx_a) {
           printf( "Could not create output context\n");
           ret = AVERROR_UNKNOWN;
           goto end;
       }
       ofmt_s = ofmt_ctx_s->oformat;

       for (i = 0; i < ifmt_ctx->nb_streams; i++) {
               //Create output AVStream according to input AVStream
               AVFormatContext *ofmt_ctx;
               AVStream *in_stream = ifmt_ctx->streams[i];
               AVStream *out_stream = NULL;

               if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
                   videoindex=i;
                   out_stream=avformat_new_stream(ofmt_ctx_v, in_stream->codec->codec);
                   ofmt_ctx=ofmt_ctx_v;
               }
               else if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){
                   audioindex=i;
                   out_stream=avformat_new_stream(ofmt_ctx_a, in_stream->codec->codec);
                   ofmt_ctx=ofmt_ctx_a;
               }
               else if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){
                   srtindex=i;
                   out_stream=avformat_new_stream(ofmt_ctx_s, in_stream->codec->codec);
                   ofmt_ctx=ofmt_ctx_s;
               }
               else{
                   break;
               }

               if (!out_stream) {
                   printf( "Failed allocating output stream\n");
                   ret = AVERROR_UNKNOWN;
                   goto end;
               }
               //Copy the settings of AVCodecContext
               if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {
                   printf( "Failed to copy context from input to output stream codec context\n");
                   goto end;
               }
               out_stream->codec->codec_tag = 0;

               if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
                   out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
       }

       //Dump Format------------------
       printf("\n==============Input Video=============\n");
       av_dump_format(ifmt_ctx, 0, in_filename, 0);

       printf("\n==============Output Video============\n");
       av_dump_format(ofmt_ctx_v, 0, out_filename_v, 1);
       printf("\n==============Output Audio============\n");
       av_dump_format(ofmt_ctx_a, 0, out_filename_a, 1);
       /*printf("\n==============Output Subtitle============\n");
       av_dump_format(ofmt_ctx_s, 0, out_filename_s, 1);*/
       printf("\n======================================\n");

       //Open output file
       if (!(ofmt_v->flags & AVFMT_NOFILE)) {
           if (avio_open(&ofmt_ctx_v->pb, out_filename_v, AVIO_FLAG_WRITE) < 0) {
               printf( "Could not open output file '%s'", out_filename_v);
               goto end;
           }
       }
       if (!(ofmt_a->flags & AVFMT_NOFILE)) {
           if (avio_open(&ofmt_ctx_a->pb, out_filename_a, AVIO_FLAG_WRITE) < 0) {
               printf( "Could not open output file '%s'", out_filename_a);
               goto end;
           }
       }
       if (!(ofmt_a->flags & AVFMT_NOFILE)) {
           if (avio_open(&ofmt_ctx_s->pb, out_filename_s, AVIO_FLAG_WRITE) < 0) {
               printf( "Could not open output file '%s'", out_filename_s);
               goto end;
           }
       }

       //Write file header
       if (avformat_write_header(ofmt_ctx_v, NULL) < 0) {
           printf( "Error occurred when opening video output file\n");
           goto end;
       }
       system("pause");


       if (avformat_write_header(ofmt_ctx_a, NULL) < 0) {
           printf( "Error occurred when opening audio output file\n");
           goto end;
       }
       if (avformat_write_header(ofmt_ctx_s, NULL) < 0) {
           printf( "Error occurred when opening audio output file\n");
           goto end;
       }

       AVBitStreamFilterContext* h264bsfc =  av_bitstream_filter_init("h264_mp4toannexb");

       while (1) {
           AVFormatContext *ofmt_ctx;
           AVStream *in_stream, *out_stream;
           //Get an AVPacket
           if (av_read_frame(ifmt_ctx, &pkt) < 0)
               break;
           in_stream  = ifmt_ctx->streams[pkt.stream_index];


           if(pkt.stream_index==videoindex){
               out_stream = ofmt_ctx_v->streams[0];
               ofmt_ctx=ofmt_ctx_v;
               printf("Write Video Packet. size:%d\tpts:%lld\n",pkt.size,pkt.pts);
               av_bitstream_filter_filter(h264bsfc, in_stream->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);
           }else if(pkt.stream_index==audioindex){
               out_stream = ofmt_ctx_a->streams[0];
               ofmt_ctx=ofmt_ctx_a;
               printf("Write Audio Packet. size:%d\tpts:%lld\n",pkt.size,pkt.pts);
           }
           else if(pkt.stream_index==srtindex){
               out_stream = ofmt_ctx_s->streams[0];
               ofmt_ctx=ofmt_ctx_s;
               printf("Write Subtitle Packet. size:%d\tpts:%lld\n",pkt.size,pkt.pts);
           }
           else{
               continue;
           }


           //Convert PTS/DTS
           pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
           pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
           pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);
           pkt.pos = -1;
           pkt.stream_index=0;
           //Write
           if (av_interleaved_write_frame(ofmt_ctx, &pkt) < 0) {
               printf( "Error muxing packet\n");
               break;
           }
           //printf("Write %8d frames to output file\n",frame_index);
           av_free_packet(&pkt);
           frame_index++;
       }

       av_bitstream_filter_close(h264bsfc);  

       //Write file trailer
       av_write_trailer(ofmt_ctx_a);
       av_write_trailer(ofmt_ctx_v);
       av_write_trailer(ofmt_ctx_s);
    end:
       avformat_close_input(&ifmt_ctx);
       /* close output */
       if (ofmt_ctx_a && !(ofmt_a->flags & AVFMT_NOFILE))
           avio_close(ofmt_ctx_a->pb);

       if (ofmt_ctx_v && !(ofmt_v->flags & AVFMT_NOFILE))
           avio_close(ofmt_ctx_v->pb);

       if (ofmt_ctx_s && !(ofmt_s->flags & AVFMT_NOFILE))
           avio_close(ofmt_ctx_s->pb);

       avformat_free_context(ofmt_ctx_a);
       avformat_free_context(ofmt_ctx_v);
       avformat_free_context(ofmt_ctx_s);

       system("pause");
       if (ret < 0 && ret != AVERROR_EOF) {
           printf( "Error occurred.\n");
           return -1;
       }

       return 0;
    }

    EDIT 1
    Screen shot of resultant h264 file
    enter image description here

    EDIT 2
    I think the "error" has to do with FFMPEG’s "Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead" error.
    I revert to an older version of FFMPEG and with the same code, the resultant h264 file was ok !

  • 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.

  • ismindex : Allow adding a path prefix to the generated .ism file

    2 juillet 2014, par Martin Storsjö
    ismindex : Allow adding a path prefix to the generated .ism file
    

    This allows storing the .ismv/.isma/.ismc files separately from
    the .ism file on a server, without having to manually edit the
    .ism file after generating it with the ismindex tool.

    Signed-off-by : Martin Storsjö <martin@martin.st>

    • [DH] tools/ismindex.c