Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (25)

  • Encoding and processing into web-friendly formats

    13 avril 2011, par

    MediaSPIP automatically converts uploaded files to internet-compatible formats.
    Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
    Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
    Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
    All uploaded files are stored online in their original format, so you can (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

Sur d’autres sites (6475)

  • C++ FFmpeg distorted sound when converting audio

    21 septembre 2016, par David Andrei Norgren

    I’m using the FFmpeg library to generate MP4 files containing audio from various files, such as MP3, WAV, OGG, but I’m having some troubles (I’m also putting video in there, but for simplicity’s sake I’m omitting that for this question, since I’ve got that working). My current code opens an audio file, decodes the content and converts it into the MP4 container and finally writes it into the destination file as interleaved frames.

    It works perfectly for most MP3 files, but when inputting WAV or OGG, the audio in the resulting MP4 is slightly distorted and often plays at the wrong speed (up to many times faster or slower).

    I’ve looked at countless of examples of using the converting functions (swr_convert), but I can’t seem to get rid of the noise in the exported audio.

    Here’s how I add an audio stream to the MP4 (outContext is the AVFormatContext for the output file) :

    audioCodec = avcodec_find_encoder(outContext->oformat->audio_codec);
    if (!audioCodec)
       die("Could not find audio encoder!");


    // Start stream
    audioStream = avformat_new_stream(outContext, audioCodec);
    if (!audioStream)
       die("Could not allocate audio stream!");

    audioCodecContext = audioStream->codec;
    audioStream->id = 1;


    // Setup
    audioCodecContext->sample_fmt = AV_SAMPLE_FMT_S16;
    audioCodecContext->bit_rate = 128000;
    audioCodecContext->sample_rate = 44100;
    audioCodecContext->channels = 2;
    audioCodecContext->channel_layout = AV_CH_LAYOUT_STEREO;


    // Open the codec
    if (avcodec_open2(audioCodecContext, audioCodec, NULL) < 0)
       die("Could not open audio codec");

    And to open a sound file from MP3/WAV/OGG (from the filename variable)...

    // Create contex
    formatContext = avformat_alloc_context();
    if (avformat_open_input(&formatContext, filename, NULL, NULL)<0)
       die("Could not open file");


    // Find info
    if (avformat_find_stream_info(formatContext, 0)<0)
       die("Could not find file info");

    av_dump_format(formatContext, 0, filename, false);


    // Find audio stream
    streamId = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
    if (streamId < 0)
       die("Could not find Audio Stream");

    codecContext = formatContext->streams[streamId]->codec;


    // Find decoder
    codec = avcodec_find_decoder(codecContext->codec_id);
    if (codec == NULL)
       die("cannot find codec!");


    // Open codec
    if (avcodec_open2(codecContext, codec, 0)<0)
       die("Codec cannot be found");


    // Set up resample context
    swrContext = swr_alloc();
    if (!swrContext)
       die("Failed to alloc swr context");

    av_opt_set_int(swrContext, "in_channel_count", codecContext->channels, 0);
    av_opt_set_int(swrContext, "in_channel_layout", codecContext->channel_layout, 0);
    av_opt_set_int(swrContext, "in_sample_rate", codecContext->sample_rate, 0);
    av_opt_set_sample_fmt(swrContext, "in_sample_fmt", codecContext->sample_fmt, 0);

    av_opt_set_int(swrContext, "out_channel_count", audioCodecContext->channels, 0);
    av_opt_set_int(swrContext, "out_channel_layout", audioCodecContext->channel_layout, 0);
    av_opt_set_int(swrContext, "out_sample_rate", audioCodecContext->sample_rate, 0);
    av_opt_set_sample_fmt(swrContext, "out_sample_fmt", audioCodecContext->sample_fmt, 0);

    if (swr_init(swrContext))
       die("Failed to init swr context");

    Finally, to decode+convert+encode...

    // Allocate and init re-usable frames
    audioFrameDecoded = av_frame_alloc();
    if (!audioFrameDecoded)
           die("Could not allocate audio frame");

    audioFrameDecoded->format = fileCodecContext->sample_fmt;
    audioFrameDecoded->channel_layout = fileCodecContext->channel_layout;
    audioFrameDecoded->channels = fileCodecContext->channels;
    audioFrameDecoded->sample_rate = fileCodecContext->sample_rate;

    audioFrameConverted = av_frame_alloc();
    if (!audioFrameConverted)
           die("Could not allocate audio frame");

    audioFrameConverted->nb_samples = audioCodecContext->frame_size;
    audioFrameConverted->format = audioCodecContext->sample_fmt;
    audioFrameConverted->channel_layout = audioCodecContext->channel_layout;
    audioFrameConverted->channels = audioCodecContext->channels;
    audioFrameConverted->sample_rate = audioCodecContext->sample_rate;

    AVPacket inPacket;
    av_init_packet(&inPacket);
    inPacket.data = NULL;
    inPacket.size = 0;

    int frameFinished = 0;

    while (av_read_frame(formatContext, &inPacket) >= 0) {

           if (inPacket.stream_index == streamId) {

                   int len = avcodec_decode_audio4(fileCodecContext, audioFrameDecoded, &frameFinished, &inPacket);

                   if (frameFinished) {

                           // Convert

                           uint8_t *convertedData=NULL;

                           if (av_samples_alloc(&convertedData,
                                                NULL,
                                                audioCodecContext->channels,
                                                audioFrameConverted->nb_samples,
                                                audioCodecContext->sample_fmt, 0) < 0)
                                   die("Could not allocate samples");

                           int outSamples = swr_convert(swrContext,
                                                        &convertedData,
                                                        audioFrameConverted->nb_samples,
                                                        (const uint8_t **)audioFrameDecoded->data,
                                                        audioFrameDecoded->nb_samples);
                           if (outSamples < 0)
                                   die("Could not convert");

                           size_t buffer_size = av_samples_get_buffer_size(NULL,
                                                                           audioCodecContext->channels,
                                                                           audioFrameConverted->nb_samples,
                                                                           audioCodecContext->sample_fmt,
                                                                           0);
                           if (buffer_size < 0)
                                   die("Invalid buffer size");

                           if (avcodec_fill_audio_frame(audioFrameConverted,
                                                        audioCodecContext->channels,
                                                        audioCodecContext->sample_fmt,
                                                        convertedData,
                                                        buffer_size,
                                                        0) < 0)
                                   die("Could not fill frame");

                           AVPacket outPacket;
                           av_init_packet(&outPacket);
                           outPacket.data = NULL;
                           outPacket.size = 0;

                           if (avcodec_encode_audio2(audioCodecContext, &outPacket, audioFrameConverted, &frameFinished) < 0)
                                   die("Error encoding audio frame");

                           if (frameFinished) {
                                   outPacket.stream_index = audioStream->index;

                                   if (av_interleaved_write_frame(outContext, &outPacket) != 0)
                                           die("Error while writing audio frame");

                                   av_free_packet(&outPacket);
                           }
                   }
           }
    }

    av_frame_free(&audioFrameConverted);
    av_frame_free(&audioFrameDecoded);
    av_free_packet(&inPacket);

    I have also tried setting appropriate pts values for outgoing frames, but that doesn’t seem to affect the sound quality at all.

    I’m also unsure how/if I should be allocating the converted data, can av_samples_alloc be used for this ? What about avcodec_fill_audio_frame ? Am I on the right track ?

    Any input is appreciated (I can also send the exported MP4s if necessary, if you want to hear the distortion).

  • Converting FLAC to AAC outputs no sound using ffmpeg

    29 décembre 2023, par Aleksandar

    I am trying to convert a FLAC audio input file to AAC using ffmpeg, but the output .aac seems to have no sound when opening in VLC. The input container is a .mka containing only the one single audio stream.

    


    I am using this command :

    


    ffmpeg -i en.mka -c:a aac -b:a 512k -map 0:a:0 en4.aac

    


    I tried with map -0 and both 320k and 512k - nothing seems to produce an output file with sound and VLC seemingly can't even determine the length of the file constantly shifting how long it is ?

    


  • How to put a sound in the watermark of a video in Laravel so that it repeats at specific intervals ? [closed]

    27 décembre 2023, par geo fadak

    How to put a sound in the watermark of a video in Laravel so that it repeats at specific intervals ?

    


    I use https://github.com/protonemedia/laravel-ffmpeg package But this feature is not seen in its documentation. What is the way to do this with PHP programming language or Laravel framework ?