Recherche avancée

Médias (0)

Mot : - Tags -/configuration

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (26)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

  • Les statuts des instances de mutualisation

    13 mars 2010, par

    Pour des raisons de compatibilité générale du plugin de gestion de mutualisations avec les fonctions originales de SPIP, les statuts des instances sont les mêmes que pour tout autre objets (articles...), seuls leurs noms dans l’interface change quelque peu.
    Les différents statuts possibles sont : prepa (demandé) qui correspond à une instance demandée par un utilisateur. Si le site a déjà été créé par le passé, il est passé en mode désactivé. publie (validé) qui correspond à une instance validée par un (...)

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

Sur d’autres sites (6879)

  • libavcodec/ffmpeg reports two channels when decoding, but segfaults when trying to access the second

    1er décembre 2017, par Astrognome

    I am attempting to decode an audio file into raw pcm data using FFMpeg’s libavcodec. I have the following code so far, but it segfaults when trying to access the second audio channel for some reason.

    #include
    #include
    #include <ao></ao>ao.h>
    #include

    #include <libavutil></libavutil>opt.h>
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>

    #define BUF_SIZE 4096


    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096

    int decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, uint8_t* out_data, int* index) {

       int i, ch;
       int ret, data_size;

       ret = avcodec_send_packet(dec_ctx, pkt);
       if (ret &lt; 0) {
           fprintf(stderr, "Error submitting packet to decoder\n");
           exit(1);
       }

       while (ret >= 0) {
           ret = avcodec_receive_frame(dec_ctx, frame);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
               return 0;
           }
           else if (ret &lt; 0) {
               fprintf(stderr, "Error during decoding\n");
               exit(1);
           }

           data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
           if (data_size &lt; 0) {
               fprintf(stderr, "Failed to calculate data size\n");
               exit(1);
           }
           for (i = 0; i &lt; frame->nb_samples; ++i)
               for (ch = 0; ch &lt; dec_ctx->channels; ++ch) {

                   //Things go wrong here...
                   memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);
                   *index += data_size;
               }
       }

       return 0;
    }

    int decode_audio_file(const char* path, uint8_t* out_data, int size) {
       const AVCodec *codec;
       AVCodecContext *c = NULL;
       AVCodecParserContext *parser = NULL;
       int len, ret;
       FILE *f;
       uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       uint8_t *data;
       size_t data_size;
       AVPacket *pkt;
       AVFrame *decoded_frame = NULL;


       avcodec_register_all();
       pkt = av_packet_alloc();
       codec = avcodec_find_decoder(AV_CODEC_ID_FLAC);
       if (!codec) {
           fprintf(stderr, "Codec not found!\n");
           return -1;
       }

       parser = av_parser_init(codec->id);
       if (!parser) {
           fprintf(stderr, "Parser not found!\n");
           return -1;
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate audio context!\n");
           return -1;
       }

       if(avcodec_open2(c, codec, NULL) &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           exit(1);
       }

       f = fopen(path, "rb");
       if(!f) {
           fprintf(stderr, "Could not open %s\n", path);
           exit(1);
       }

       data = inbuf;
       data_size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);

       int index = 0;  
       while (data_size > 0) {
           if (!decoded_frame) {
               if (!(decoded_frame = av_frame_alloc())) {
                   fprintf(stderr, "Could not allocate audio frame\n");
                   exit(1);
               }
           }

           ret = av_parser_parse2(parser, c, &amp;pkt->data, &amp;pkt->size, data, data_size, AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0);
           if (ret &lt; 0) {
               fprintf(stderr, "Error while parsing\n");
               exit(1);
           }
           data += ret;
           data_size -= ret;

           if (pkt->size)
               decode(c, pkt, decoded_frame, out_data, &amp;index);
           if (data_size &lt; AUDIO_REFILL_THRESH) {
               memmove(inbuf, data, data_size);
               data = inbuf;
               len = fread(data + data_size, 1, AUDIO_INBUF_SIZE - data_size, f);
               if (len > 0)
                   data_size += len;
           }
       }
       avcodec_free_context(&amp;c);
       av_parser_close(parser);
       av_frame_free(&amp;decoded_frame);
       av_packet_free(&amp;pkt);

       return 0;
    }


    int main(int argc, char **argv)
    {
       int bsize = 1024*1024*60;
       uint8_t* audio_buffer = calloc(bsize, sizeof(uint8_t));
       decode_audio_file("testsong.flac", audio_buffer, bsize);
    }

    Here is the offending line :

    memcpy(out_data + *index, frame->data[ch] + (data_size*i), data_size);

    If you access frame->data[0] it’s fine, but if you attempt to access frame->data[1] it segfaults. The context reports two channels and the file contains two channels (tried with several different tracks).
    But it gets even weirder. If I switch the offending line to

    memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch), data_size);

    it will have the left channel with correct data and the right channel is white noise. This tells me (and I could be wrong) that the first channel actually contains 2 channels of audio interleaved, the actual left channel, plus a junk channel of white noise.
    I was wrong, I forgot to multiple ch by data_size. If the line is memcpy(out_data + *index, frame->data[0] + (data_size*i*2 + ch*data_size), data_size); things seem to work as expected. This all still seems very sketchy though so if anyone can thoroughly explain what’s happening here, that would be nice.

    I have been working off the decode_audio example available in the ffmpeg documentation here although modified slightly.

    This ALSO happens if I use the vanilla example with the only change being setting the codec to FLAC, so I assume it’s a bug in the library. In that case, how can I work around it.

  • Anomalie #4589 (Fermé) : PHP8 : Warning Trying to access array offset on value of type bool in inc...

    4 novembre 2020
  • Access to folders on Ubuntu-based Rails server (keep getting "No such file..")

    13 avril 2012, par Stpn

    I am setting up Rails+ffmpeg on Ubuntu and I keep getting

    Errno::ENOENT
    No such file or directory..

    The setup is as follows :

    /home/username/RailsApp
    /home/username/videos/

    I am trying to run ffmpeg to write to /home/username/videos and I used "/home/username/videos/" and " /videos/" but no luck..

    What am I missing ?

    "www-data" user is included in "username" group..

    Rails app works fine otherwise..

    Any input greatly appreciated !

    Thanks !