Recherche avancée

Médias (91)

Autres articles (104)

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

  • Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs

    12 avril 2011, par

    La manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
    Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.

  • Encodage et transformation en formats lisibles sur Internet

    10 avril 2011

    MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
    Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
    Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...)

Sur d’autres sites (9611)

  • Pydub unable to locate ffprobe

    25 décembre 2022, par Recessive

    Here is the link to a similar question to this : Pydub (WindowsError : [Error 2] The system can not find the file specified)
Although in this one the problem is with ffmpeg, which I solved by setting the absolute path.

    


    After setting the absolute path for converter and/or ffmpeg with either :

    


    AudioSegment.converter = r'C:\ffmpeg\bin'

    


    or

    


    AudioSegment.ffmpeg = r'C:\ffmpeg\bin'

    


    I still get this error :

    


    


    C :\Program Files\Python36\lib\site-packages\pydub\utils.py:193 : RuntimeWarning : Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last) :
File "C :/Users/Sean/Desktop/vp/encode_audio/m4a_to_wav.py", line 4, in 
song = AudioSegment.from_file("pines.m4a", "m4a")
File "C :\Program Files\Python36\lib\site-packages\pydub\audio_segment.py", line 660, in from_file
info = mediainfo_json(orig_file)
File "C :\Program Files\Python36\lib\site-packages\pydub\utils.py", line 263, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C :\Program Files\Python36\lib\subprocess.py", line 707, in init
restore_signals, start_new_session)
File "C :\Program Files\Python36\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError : [WinError 2] The system cannot find the file specified`

    


    


    I have ffmpeg in my path envvar. I also have libav in my path envvar, and installed libav and then pydub in the order specified at https://github.com/jiaaro/pydub#dependencies.

    


    Nothing I'm doing appears to be working, so any ideas or solutions would be greatly appreciated !

    


  • Using FFmpeg programmatically with a proxy

    2 mai 2013, par William Seemann

    I'm trying to use FFmpeg with a proxy. The following code works if I comment out :

    setenv("http_proxy", "http://172.0.0.1:3128/", 1);

    The proxy server is an instance of Squid. I know the proxy server is working because I can use the same URL with VLC without any issues. With the proxy specified, the output from my code is always :

    Proxy path: http://172.0.0.1:3128/
    Metadata could not be retrieved -5 // indicates an IO Error
    setDataSource failed, rc is: -1

    I compiled FFmpeg with everything enabled. Can someone explain why this code doesn't work with a proxy ?

    #include
    #include
    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>

    const int SUCCESS = 0;
    const int FAILURE = -1;

    typedef struct State {
       AVFormatContext *pFormatCtx;
       int             audio_stream;
       int             video_stream;
       AVStream        *audio_st;
       AVStream        *video_st;
    } State;

    int setDataSource(State** ps, const char* path) {
       State *state = *ps;

       if (state->pFormatCtx) {
           avformat_close_input(&amp;state->pFormatCtx);
       }

       int ret = 0;

       if ((ret = avformat_open_input(&amp;state->pFormatCtx, path, NULL, NULL)) != 0) {
           printf("Metadata could not be retrieved %d\n", ret);
           *ps = NULL;
           return FAILURE;
       }

       if (avformat_find_stream_info(state->pFormatCtx, NULL) &lt; 0) {
           printf("Metadata could not be retrieved\n");
           avformat_close_input(&amp;state->pFormatCtx);
           *ps = NULL;
           return FAILURE;
       }

       *ps = state;
       return SUCCESS;
    }

    const char* extractMetadata(State** ps, const char* key) {
       char* value = NULL;

       State *state = *ps;

       if (!state->pFormatCtx) {
           goto fail;
       }

       if (key) {
           if (av_dict_get(state->pFormatCtx->metadata, key, NULL, AV_DICT_IGNORE_SUFFIX)) {
               value = av_dict_get(state->pFormatCtx->metadata, key, NULL, AV_DICT_IGNORE_SUFFIX)->value;
           }
       }

       fail:

       return value;
    }

    int main(void) {
       setenv("http_proxy", "http://172.0.0.1:3128/", 1);
       unsetenv("no_proxy");

       const char *proxy_path = getenv("http_proxy");

       if (proxy_path) {
           printf("Proxy path: %s\n", proxy_path);
       } else {
           printf("No proxy specified\n");
       }

       av_register_all();
       avformat_network_init();

       State * state = av_mallocz(sizeof(State));

       int ret = setDataSource(&amp;state, "http://<some host="host">/song.mp3");

       if (ret == 0) {
           printf("setDataSource succedded!\n");
           printf("Artist: %s\n", extractMetadata(&amp;state, "artist"));
       } else {
           printf("setDataSource failed, rc is: %d\n", ret);
       }

       return EXIT_SUCCESS;
    }
    </some>
  • Reading mp3 file using ffmpeg caues memory leaks, even after freeing it in main

    12 août 2020, par leonardltk1

    i am continuously reading mp3 files and processing them, but the memory keeps getting build up even though i freed it.

    &#xA;

    At the bottom read_audio_mp3(), they are already freeing some variable.&#xA;why do i still face a memory build up and how do i deal with it ?

    &#xA;

    following this code : https://rodic.fr/blog/libavcodec-tutorial-decode-audio-file/, i read mp3 using this function

    &#xA;

        int read_audio_mp3(string filePath_str, const int sample_rate, &#xA;      double** output_buffer, int &amp;AUDIO_DURATION){&#xA;      const char* path = filePath_str.c_str();&#xA;&#xA;      /* Reads the file header and stores information about the file format. */&#xA;        AVFormatContext* format = avformat_alloc_context();&#xA;        if (avformat_open_input(&amp;format, path, NULL, NULL) != 0) {&#xA;            fprintf(stderr, "Could not open file &#x27;%s&#x27;\n", path);&#xA;            return -1;&#xA;        }&#xA;&#xA;      /* Check out the stream information in the file. */&#xA;        if (avformat_find_stream_info(format, NULL) &lt; 0) {&#xA;            fprintf(stderr, "Could not retrieve stream info from file &#x27;%s&#x27;\n", path);&#xA;            return -1;&#xA;        }&#xA;&#xA;      /* find an audio stream. */&#xA;        int stream_index =- 1;&#xA;        for (unsigned i=0; inb_streams; i&#x2B;&#x2B;) {&#xA;          if (format->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {&#xA;            stream_index = i;&#xA;            break;&#xA;          }&#xA;        }&#xA;        if (stream_index == -1) {&#xA;            fprintf(stderr, "Could not retrieve audio stream from file &#x27;%s&#x27;\n", path);&#xA;            return -1;&#xA;        }&#xA;        AVStream* stream = format->streams[stream_index];&#xA;&#xA;      // find &amp; open codec&#xA;        AVCodecContext* codec = stream->codec;&#xA;        if (avcodec_open2(codec, avcodec_find_decoder(codec->codec_id), NULL) &lt; 0) {&#xA;            fprintf(stderr, "Failed to open decoder for stream #%u in file &#x27;%s&#x27;\n", stream_index, path);&#xA;            return -1;&#xA;        }&#xA;&#xA;      // prepare resampler&#xA;        struct SwrContext* swr = swr_alloc();&#xA;        av_opt_set_int(swr, "in_channel_count",  codec->channels, 0);&#xA;        av_opt_set_int(swr, "out_channel_count", 1, 0);&#xA;        av_opt_set_int(swr, "in_channel_layout",  codec->channel_layout, 0);&#xA;        av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);&#xA;        av_opt_set_int(swr, "in_sample_rate", codec->sample_rate, 0);&#xA;        av_opt_set_int(swr, "out_sample_rate", sample_rate, 0);&#xA;        av_opt_set_sample_fmt(swr, "in_sample_fmt",  codec->sample_fmt, 0);&#xA;        av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_DBL,  0);&#xA;        swr_init(swr);&#xA;        if (!swr_is_initialized(swr)) {&#xA;            fprintf(stderr, "Resampler has not been properly initialized\n");&#xA;            return -1;&#xA;        }&#xA;&#xA;      /* Allocate an audio frame. */&#xA;        AVPacket packet;&#xA;        av_init_packet(&amp;packet);&#xA;        AVFrame* frame = av_frame_alloc();&#xA;        if (!frame) {&#xA;          fprintf(stderr, "Error allocating the frame\n");&#xA;          return -1;&#xA;        }&#xA;&#xA;      // iterate through frames&#xA;        *output_buffer = NULL;&#xA;        AUDIO_DURATION = 0;&#xA;        while (av_read_frame(format, &amp;packet) >= 0) {&#xA;          // decode one frame&#xA;            int gotFrame;&#xA;            if (avcodec_decode_audio4(codec, frame, &amp;gotFrame, &amp;packet) &lt; 0) {&#xA;              // free packet&#xA;                av_free_packet(&amp;packet);&#xA;                break;&#xA;            }&#xA;            if (!gotFrame) {&#xA;              // free packet&#xA;                av_free_packet(&amp;packet);&#xA;                continue;&#xA;            }&#xA;          // resample frames&#xA;            double* buffer;&#xA;            av_samples_alloc((uint8_t**) &amp;buffer, NULL, 1, frame->nb_samples, AV_SAMPLE_FMT_DBL, 0);&#xA;            int frame_count = swr_convert(swr, (uint8_t**) &amp;buffer, frame->nb_samples, (const uint8_t**) frame->data, frame->nb_samples);&#xA;          // append resampled frames to output_buffer&#xA;            *output_buffer = (double*) realloc(*output_buffer,&#xA;             (AUDIO_DURATION &#x2B; frame->nb_samples) * sizeof(double));&#xA;            memcpy(*output_buffer &#x2B; AUDIO_DURATION, buffer, frame_count * sizeof(double));&#xA;            AUDIO_DURATION &#x2B;= frame_count;&#xA;          // free buffer &amp; packet&#xA;            av_free_packet(&amp;packet);&#xA;            av_free( buffer );&#xA;        }&#xA;&#xA;      // clean up&#xA;        av_frame_free(&amp;frame);&#xA;        swr_free(&amp;swr);&#xA;        avcodec_close(codec);&#xA;        avformat_free_context(format);&#xA;&#xA;      return 0;&#xA;    }&#xA;

    &#xA;

    Main Script : MemoryLeak.cpp

    &#xA;

        // imports&#xA;      #include <fstream>&#xA;      #include &#xA;      #include &#xA;      #include &#xA;      #include &#xA;      #include <iostream>&#xA;      #include <sstream>&#xA;      #include <vector>&#xA;      #include <sys></sys>time.h> &#xA;      extern "C"&#xA;      {&#xA;      #include <libavutil></libavutil>opt.h>&#xA;      #include <libavcodec></libavcodec>avcodec.h>&#xA;      #include <libavformat></libavformat>avformat.h>&#xA;      #include <libswresample></libswresample>swresample.h>&#xA;      }&#xA;      using namespace std;&#xA;&#xA;    int main (int argc, char ** argv) {&#xA;      string wavpath = argv[1];&#xA;      printf("wavpath=%s\n", wavpath.c_str());&#xA;&#xA;      printf("\n==== Params =====\n");&#xA;      // Init&#xA;        int AUDIO_DURATION;&#xA;        int sample_rate = 8000;&#xA;        av_register_all();&#xA;&#xA;      printf("\n==== Reading MP3 =====\n");&#xA;        while (true) {&#xA;            // Read mp3&#xA;              double* buffer;&#xA;              if (read_audio_mp3(wavpath, sample_rate, &amp;buffer, AUDIO_DURATION) != 0) {&#xA;                printf("Cannot read %s\n", wavpath.c_str());&#xA;                continue;&#xA;              }&#xA;&#xA;            /* &#xA;              Process the buffer for down stream tasks.&#xA;            */&#xA;&#xA;            // Freeing the buffer&#xA;            free(buffer);&#xA;        }&#xA;&#xA;      return 0 ;&#xA;    }&#xA;</vector></sstream></iostream></fstream>

    &#xA;

    Compiling

    &#xA;

        g&#x2B;&#x2B; -o ./MemoryLeak.out -Ofast -Wall -Wextra \&#xA;        -std=c&#x2B;&#x2B;11 "./MemoryLeak.cpp" \&#xA;        -lavformat -lavcodec -lavutil -lswresample&#xA;

    &#xA;

    Running, by right my input an argument wav.scp that reads text file of all the mp3s.&#xA;But for easy to replicate purpose, i only read 1 file song.mp3 in and i keep re-reading it

    &#xA;

    ./MemoryLeak.out song.mp3&#xA;

    &#xA;

    Why do i know i have memory leaks ?

    &#xA;

      &#xA;
    1. I was running up 32 jobs in parallel for 14 million files, and when i wake up in the morning, they were abruptly killed.
    2. &#xA;

    3. I run htop and i monitor the progress when i re-run it, and i saw that the VIRT & RES & Mem are continuously increasing.
    4. &#xA;

    &#xA;

    &#xA;

    Edit 1 :&#xA;My setup :

    &#xA;

    &#xA;

    ffmpeg version 2.8.15-0ubuntu0.16.04.1&#xA;built with gcc 5.4.0&#xA;

    &#xA;