Recherche avancée

Médias (3)

Mot : - Tags -/pdf

Autres articles (77)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • 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" ;

  • Installation en mode ferme

    4 février 2011, par

    Le mode ferme permet d’héberger plusieurs sites de type MediaSPIP en n’installant qu’une seule fois son noyau fonctionnel.
    C’est la méthode que nous utilisons sur cette même plateforme.
    L’utilisation en mode ferme nécessite de connaïtre un peu le mécanisme de SPIP contrairement à la version standalone qui ne nécessite pas réellement de connaissances spécifique puisque l’espace privé habituel de SPIP n’est plus utilisé.
    Dans un premier temps, vous devez avoir installé les mêmes fichiers que l’installation (...)

Sur d’autres sites (5333)

  • FFMPEG Muxing from Audio and Video files.(C++)

    27 mai 2013, par Michael IV

    I am learning how to create MP4 video from this example.The problem is that the example demonstrates audio encoding from some dummy source data generated on the fly.I need to encode audio from a file.I have checked many examples and most of them show the same or just a separate audio encoding.
    In my trial and error process I am using the same AVFormatContext for both audio and video frames.I am not sure if it's right thing to do, or should I rather have 2 separate contexts ?So far I got Video encoding ok but audio stream fails as AVPacket can't locate correct audio stream index.
    Here is how I setup audio stream :

     void open_audio(AVFormatContext *oc, AVCodec **codec, AVStream **st ,enum AVCodecID codec_id){

       //    AVCodecContext *c;
       int ret;
       //    c = st->codec;

       *codec = avcodec_find_encoder(codec_id);
       if (!(*codec)) {
           fprintf(stderr, "Could not find encoder for '%s'\n",avcodec_get_name(codec_id));

       }
       /* open it */



       if(avformat_open_input(&oc,_audioInName.c_str(),NULL,NULL) !=0){

           Msg::PrintErrorMsg("Error opening audio file");

       }


       AVStream* audioStream = NULL;

       // Find the audio stream (some container files can have multiple streams in them)

       for (uint32_t i = 0; i < oc->nb_streams; ++i)

       {

           if (oc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)

           {

               audioStream = oc->streams[i];

               break;

           }

       }

       if (audioStream == NULL)
       {
           Msg::PrintErrorMsg("Could not find any audio stream in the file");

       }
       *st =audioStream;

       AVCodecContext *c  = audioStream->codec;
       c->codec = *codec;//avcodec_find_decoder(c->codec_id);
       audioStream->id = 1;
       c->sample_fmt  = AV_SAMPLE_FMT_S16;
       c->bit_rate    = 64000;
       c->sample_rate = 44100;
       c->channels    = 1;

       if (oc->oformat->flags & AVFMT_GLOBALHEADER){
           c->flags |= CODEC_FLAG_GLOBAL_HEADER;

       }

       if (c->codec == NULL)
       {
           Msg::PrintErrorMsg("Couldn't find a proper decoder");

       }

       ret = avcodec_open2(c, *codec, NULL);
       if (ret < 0) {

           Msg::PrintErrorMsg("Could not open audio codec\n");

       }

    }

    Here "oc" is the same context used to initialize video stream as well.

    Then I am trying to write audio frame like this :

     void write_audio_frame(AVFormatContext *oc, AVStream *st){
       AVCodecContext *c;
       AVPacket pkt = { 0 }; // data and size must be 0;
       AVFrame *frame = avcodec_alloc_frame();
       int got_packet, ret;
       av_init_packet(&pkt);
       c = st->codec;
       /////
       //  get_audio_frame(samples, audio_input_frame_size, c->channels);

       ////Read the packet:
       while(av_read_frame(oc,&pkt) == 0 ){

           if(pkt.stream_index ==st->index){

           // Try to decode the packet into a frame
           int frameFinished = 0;
           avcodec_decode_audio4(c, frame, &frameFinished, &pkt);

           // Some frames rely on multiple packets, so we have to make sure the frame is finished before
           // we can use it
           if (frameFinished){
               assert(frameFinished);
               ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
               if (ret < 0) {
                   Msg::PrintErrorMsg("Error encoding audio frame\n");

               }
               if (!got_packet){
                   printf("failed to aquire packet");
               }
               pkt.stream_index = st->index;
               /* Write the compressed frame to the media file. */
               ret = av_interleaved_write_frame(oc, &pkt);
               if (ret != 0) {

                   Msg::PrintErrorMsg("Error while writing audio frame.");
               }

             }
           }

          }
       }
       av_free_packet(&pkt);
       avcodec_free_frame(&frame);
    }

    The thing is I never pass this statement : "if(pkt.stream_index ==st->index)".Packet stream index is never equal to the audio stream index.Anyone can point out where I am wrong ?

  • Merge audio (m4s) segments into one

    20 avril 2022, par akinuri

    I recently started learning Laravel, and currently watching an online course. Online courses are fine, but I like to have local copies, so I'm trying to download/merge segmented audio from Laracasts : Laravel 8 From Scratch series.

    


    I've written some scripts (in Python) that does the following :

    


      

    1. Download the master.json
    2. 


    3. Read master.json and download audio segments
    4. 


    5. Merge the segments into a single file (the file is not playable yet)
    6. 


    7. Process the audio file via ffmpeg (now it's playable, but has issues)
    8. 


    


    I think there's a problem with the step 3 and/or 4.

    


    In step/script 3, I create a new file, and add the contents of the segments to the file in binary.

    


    Then (step/script 4), run a ffmpeg command in python : ffmpeg -i merged-file.mp4 -c copy processed-file.mp4

    


    However, the final file doesn't work/play as expected. There's a delay in the beginning, and some parts seem to be cut off/skipped.

    


    There are three possibilities :

    


      

    • Segment files are problematic (not likely ?)
    • 


    • I'm doing the merging wrong
    • 


    • I'm doing the ffmpeg processing wrong
    • 


    


    Can someone guide me here ?

    



    


    The issues/colored parts in the ffmpeg output are :

    


    ...
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001cfbc0de780] could not find corresponding track id 2
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001cfbc0de780] could not find corresponding trex (id 2)
...
[aac @ 000001cfbc0f0380] Number of bands (31) exceeds limit (6).
...
[mp4 @ 000001cfbc20ecc0] track 0: codec frame size is not set
...
[mp4 @ 000001cfbc20ecc0] Non-monotonous DTS in output stream 0:0; previous: 318318, current: 286286; changing to 318319. This may result in incorrect timestamps in the output file.
...


    


    Everything required for a test case is located in GitHub (akinuri/dump/m4s-segments/). Screenshot of the contents :

    


    repo folder contents

    



    


    Note : there are two types/formats of audio in the master.json : mp42 and dash. dash works as expected, and seem to be used in limited videos/courses. On the other hand, mp42 appears more. So I need a way to make mp42 work.

    


  • How to silent the MP3 decoding process

    3 août 2019, par Golu

    I am learning ffmpeg and I made a MP3 decoder but when I am executing it , some kind of information is printing on my terminal but I don’t want it. So how to silent it ?

    Here is code (full code)

    /* FFmpeg Usage Example
    * Date : 28 July 2019
    */
    #include
    #include <libavformat></libavformat>avformat.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>avutil.h>
    #include

    int decode_packet(AVCodecContext*, AVPacket*, AVFrame*);

    int main(void) {
           AVFormatContext *pFormatContext = avformat_alloc_context();
           AVCodecParameters *pCodecParameters = NULL;
           if(avformat_open_input(&amp;pFormatContext,"song.mp3",NULL,NULL)!=0) {
                   fprintf(stderr,"Could not open file\n");
                   return -1;
           }
           if(avformat_find_stream_info(pFormatContext,NULL)&lt;0) {
                   fprintf(stderr,"Could not find stream\n");
                   return -1;
           }

           size_t stream_index = 0;
           for(;stream_indexnb_streams;stream_index++) {
                   if(pFormatContext->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
                           pCodecParameters = pFormatContext->streams[stream_index]->codecpar;
                   }
                           break;
           }

           if(stream_index == -1) {
                   fprintf(stderr,"could not retrive stream info from file\n");
                   return -1;
           }
           AVStream *stream = pFormatContext->streams[stream_index];
           pCodecParameters = stream->codecpar;
           AVCodec *cdc = avcodec_find_decoder(pCodecParameters->codec_id);
           AVCodecContext *cdc_ctx = avcodec_alloc_context3(cdc);
           assert(pCodecParameters);

           if(avcodec_parameters_to_context(cdc_ctx,pCodecParameters) &lt; 0) {
                   fprintf(stderr,"Can't copy params to codec context\n");
                   return -1;
           }

           if(avcodec_open2(cdc_ctx,cdc,NULL) &lt; 0) {
                   fprintf(stderr,"Failed to open decoder for stream\n");
                   return -1;
           }

           AVFrame *frame = av_frame_alloc();
           if(!frame) {
                   fprintf(stderr,"could not allocate memory for frame\n");
                   return -1;
           }

           AVPacket *packet = av_packet_alloc();
    //      av_init_packet(&amp;packet);
           if(!packet) {
                   fprintf(stderr,"could not allocate memory for packet");
                   return -1;
           }

           packet->data=NULL;
           packet->size=0;
           // lets read the packets
           while(av_read_frame(pFormatContext,packet) >= 0) {
                   if(packet->stream_index==stream_index) {
                           int response = 0 ;
               response = decode_packet(cdc_ctx,packet,frame);

                           if(response &lt; 0)
                                   continue;
                   }
           av_packet_unref(packet);
           }

           return 0;
    }

    int decode_packet(AVCodecContext *cdc_ctx , AVPacket *pkt, AVFrame *frm) {
       int response = avcodec_send_packet(cdc_ctx,pkt);
       if(response &lt; 0)
           return response;
       while(response >= 0) {
           response = avcodec_receive_frame(cdc_ctx,frm);
           if(response == AVERROR(EAGAIN) || response == AVERROR_EOF)
               return -1;
           else if(response &lt; 0)
               return response;
       }
       return 0;
    }

    Expected behaviour : nothing should be printed on screen

    Actual behaviour : some kind of logs are printing automatically

    Here is output logs ( some of them )

    [mp3float @ 0x75172e7400] overread, skip -6 enddists: -5 -5        
    [mp3float @ 0x75172e7400] overread, skip -7 enddists: -6 -6
    [mp3float @ 0x75172e7400] overread, skip -6 enddists: -5 -5
    [mp3float @ 0x75172e7400] overread, skip -6 enddists: -4 -4