Recherche avancée

Médias (0)

Mot : - Tags -/formulaire

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

Autres articles (59)

  • Les vidéos

    21 avril 2011, par

    Comme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
    Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
    Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (5891)

  • Install openCV with ffmpeg support on OS X

    4 janvier 2017, par saulspatz

    I’m trying to install openCV with ffmpeg support on Yosemite. I had just successfully installed openCV, but video didn’t work properly, and I was advised to rebuild it with ffmpeg support. So, I installed ffmpeg with

    brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --   with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265

    Then I used the following script to run cmake :

    PYTHON3_DIR=`python3-config --prefix` # Get python 3 path
    VIRTUAL_ENV=`python3-config --prefix`
    FFMPEG_INCLUDE_DIR=/usr/local/Cellar/ffmpeg/3.2.2/include/
    FFMPEG_LIB_DIR=/usr/local/Cellar/ffmpeg/3.2.2/lib/
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV \
    -D PYTHON_EXECUTABLE=$VIRTUAL_ENV/bin/python3 \
    -D PYTHON3_PACKAGES_PATH=$VIRTUAL_ENV/lib/python3.5/site-packages \
    -D PYTHON3_INCLUDE_DIR=$VIRTUAL_ENV/include/python3.5m \
    -D PYTHON3_LIBRARY=$PYTHON3_DIR/lib/libpython3.5m.dylib \
    -D PYTHON3_NUMPY_INCLUDE_DIRS=$VIRTUAL_ENV/lib/python3.5/site-packages/numpy/core/include/ \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D WITH_FFMPEG=ON \
    -D BUILD_opencv_python3=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

    This was the same script that I’d used before, with the addition of the two FFMPEG_ directories and the -D WITH_FFMPEG=ON flag. Now when I run make it fails with a bunch of errors relating to freeType.

    Scanning dependencies of target opencv_video
    [ 24%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/bgfg_KNN.cpp.o
    [ 24%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mappergradshift.cpp.o
    [ 24%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/bgfg_gaussmix2.cpp.o
    [ 25%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mappergradsimilar.cpp.o
    [ 25%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapperpyramid.cpp.o
    [ 25%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/camshift.cpp.o
    [ 25%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapprojec.cpp.o
    [ 25%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/compat_video.cpp.o
    [ 25%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/mapshift.cpp.o
    [ 25%] Building CXX object modules/reg/CMakeFiles/opencv_reg.dir/src/precomp.cpp.o
    [ 25%] Linking CXX shared library ../../lib/libopencv_reg.dylib
    [ 25%] Built target opencv_reg
    [ 25%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/ecc.cpp.o
    [ 25%] Generating opencl_kernels_dnn.cpp, opencl_kernels_dnn.hpp
    Scanning dependencies of target opencv_dnn
    [ 25%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/attr_value.pb.cc.o
    [ 25%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/function.pb.cc.o
    [ 25%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/kalman.cpp.o
    [ 25%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/lkpyramid.cpp.o
    [ 25%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/graph.pb.cc.o
    [ 26%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/optflowgf.cpp.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/op_def.pb.cc.o
    [ 26%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/src/tvl1flow.cpp.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/tensor.pb.cc.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/tensor_shape.pb.cc.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/types.pb.cc.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/tensorflow/versions.pb.cc.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/misc/caffe/caffe.pb.cc.o
    [ 26%] Building CXX object modules/video/CMakeFiles/opencv_video.dir/opencl_kernels_video.cpp.o
    [ 26%] Linking CXX shared library ../../lib/libopencv_video.dylib
    [ 26%] Built target opencv_video
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/blob.cpp.o
    [ 26%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/caffe_importer.cpp.o
    [ 27%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/caffe_io.cpp.o
    [ 27%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/caffe/layer_loaders.cpp.o
    [ 28%] Building CXX object modules/freetype/CMakeFiles/opencv_freetype.dir/src/freetype.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/dnn.cpp.o
    [ 28%] Linking CXX shared library ../../lib/libopencv_freetype.dylib
    Undefined symbols for architecture x86_64:
     "_FT_Done_Face", referenced from:
         cv::freetype::FreeType2Impl::~FreeType2Impl() in freetype.cpp.o
         cv::freetype::FreeType2Impl::loadFontData(cv::String, int) in freetype.cpp.o
     "_FT_Done_FreeType", referenced from:
         cv::freetype::FreeType2Impl::~FreeType2Impl() in freetype.cpp.o
     "_FT_Init_FreeType", referenced from:
         cv::freetype::FreeType2Impl::FreeType2Impl() in freetype.cpp.o
         cv::freetype::FreeType2Impl::FreeType2Impl() in freetype.cpp.o
         cv::freetype::createFreeType2() in freetype.cpp.o
     "_FT_Load_Glyph", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&) in freetype.cpp.o
     "_FT_New_Face", referenced from:
         cv::freetype::FreeType2Impl::loadFontData(cv::String, int) in freetype.cpp.o
     "_FT_Outline_Decompose", referenced from:
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&) in freetype.cpp.o
     "_FT_Outline_Transform", referenced from:
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&) in freetype.cpp.o
     "_FT_Outline_Translate", referenced from:
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&) in freetype.cpp.o
     "_FT_Render_Glyph", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&) in freetype.cpp.o
     "_FT_Set_Pixel_Sizes", referenced from:
         cv::freetype::FreeType2Impl::putText(cv::_InputOutputArray const&amp;, cv::String const&amp;, cv::Point_<int>, int, cv::Scalar_<double>, int, int, bool) in freetype.cpp.o
     "_hb_buffer_add_utf8", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
     "_hb_buffer_create", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
     "_hb_buffer_destroy", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
     "_hb_buffer_get_glyph_infos", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
     "_hb_buffer_guess_segment_properties", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
     "_hb_font_destroy", referenced from:
         cv::freetype::FreeType2Impl::~FreeType2Impl() in freetype.cpp.o
         cv::freetype::FreeType2Impl::loadFontData(cv::String, int) in freetype.cpp.o
     "_hb_ft_font_create", referenced from:
         cv::freetype::FreeType2Impl::loadFontData(cv::String, int) in freetype.cpp.o
     "_hb_shape", referenced from:
         cv::freetype::FreeType2Impl::putTextBitmapBlend(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextBitmapMono(cv::_InputOutputArray const&amp;) in freetype.cpp.o
         cv::freetype::FreeType2Impl::putTextOutline(cv::_InputOutputArray const&amp;) in freetype.cpp.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[2]: *** [lib/libopencv_freetype.3.2.0.dylib] Error 1
    make[1]: *** [modules/freetype/CMakeFiles/opencv_freetype.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs....
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/init.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/concat_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/convolution_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/crop_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/detection_output_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/elementwise_layers.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/eltwise_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/flatten_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/fully_connected_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/layers_common.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/lrn_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/mvn_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/normalize_bbox_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/op_blas.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/op_im2col.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/permute_layer.cpp.o
    [ 28%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/pooling_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/prior_box_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/recurrent_layers.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/reshape_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/shift_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/slice_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/softmax_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/split_layer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/tensorflow/tf_importer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/tensorflow/tf_io.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THDiskFile.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THFile.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THGeneral.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/torch_importer.cpp.o
    [ 29%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/opencl_kernels_dnn.cpp.o
    [ 29%] Linking CXX shared library ../../lib/libopencv_dnn.dylib
    [ 29%] Built target opencv_dnn
    make: *** [all] Error 2
    </double></int>

    I don’t have a clue what’s wrong. Any suggestions ?

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

  • FFMpeg process created from Java on CentOS doesn't exit

    21 juin 2017, par Donz

    I need to convert a lot of wave files simultaneously. About 300 files in parallel. And new files come constantly. I use ffmpeg process call from my Java 1.8 app, which is running on CentOS. I know that I have to read error and input streams for making created process from Java possible to exit.

    My code after several expirements :

       private void ffmpegconverter(String fileIn, String fileOut){
       String[] comand = new String[]{"ffmpeg", "-v", "-8", "-i", fileIn, "-acodec", "pcm_s16le", fileOut};

       Process process = null;
       BufferedReader reader = null;
       try {
           ProcessBuilder pb = new ProcessBuilder(comand);
           pb.redirectErrorStream(true);
           process = pb.start();

           //Reading from error and standard output console buffer of process. Or it could halts because of nobody
           //reads its buffer
           reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
           String s;
           //noinspection StatementWithEmptyBody
           while ((s = reader.readLine()) != null) {
               log.info(Thread.currentThread().getName() + " with fileIn " + fileIn + " and fileOut " + fileOut + " writes " + s);
               //Ignored as we just need to empty the output buffer from process
           }
           log.info(Thread.currentThread().getName() + " ffmpeg process will be waited for");
           if (process.waitFor( 10, TimeUnit.SECONDS )) {
               log.info(Thread.currentThread().getName() + " ffmpeg process exited normally");
           } else {
               log.info(Thread.currentThread().getName() + " ffmpeg process timed out and will be killed");
           }

       } catch (IOException | InterruptedException e) {
           log.error(Thread.currentThread().getName() + "Error during ffmpeg process executing", e);
       } finally {
           if (process != null) {
               if (reader != null) {
                   try {
                       reader.close();
                   } catch (IOException e) {
                       log.error("Error during closing the process streams reader", e);
                   }
               }
               try {
                   process.getOutputStream().close();
               } catch (IOException e) {
                   log.error("Error during closing the process output stream", e);
               }
               process.destroyForcibly();
               log.info(Thread.currentThread().getName() + " ffmpeg process " + process + " must be dead now");
           }
       }
    }

    If I run separate test with this code it goes normally. But in my app I have hundreds of RUNNING deamon threads "process reaper" which are waiting for ffmpeg process finish. In my real app ffpmeg is started from timer thread. Also I have another activity in separate threads, but I don’t think that this is the problem. Max CPU consume is about 10%.

    Here is that I usual see in thread dump :

    "process reaper" #454 daemon prio=10 os_prio=0 tid=0x00007f641c007000 nid=0x5247 runnable [0x00007f63ec063000]
      java.lang.Thread.State: RUNNABLE
       at java.lang.UNIXProcess.waitForProcessExit(Native Method)
       at java.lang.UNIXProcess.lambda$initStreams$3(UNIXProcess.java:289)
       at java.lang.UNIXProcess$$Lambda$32/2113551491.run(Unknown Source)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at java.lang.Thread.run(Thread.java:745)

    What am I doing wrong ?

    UPD :
    My app accepts a lot of connects with voice traffic. So I have about 300-500 another "good" threads in every moment. Could it be the reason ? Deamon threads have low priority. But I don’t beleive that they really can’t do their jobs in one hour. Ususally it takes some tens of millis.

    UPD2 :
    My synthetic test that runs fine. I tried with new threads option and without it just with straigt calling of run method.

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;

    public class FFmpegConvert {

       public static void main(String[] args) throws Exception {

           FFmpegConvert f = new FFmpegConvert();
           f.processDir(args[0], args[1], args.length > 2);
       }

       private void processDir(String dirPath, String dirOutPath, boolean isNewThread) {
           File dir = new File(dirPath);
           File dirOut = new File(dirOutPath);
           if(!dirOut.exists()){
               dirOut.mkdir();
           }
           for (int i = 0; i &lt; 1000; i++) {
               for (File f : dir.listFiles()) {
                   try {
                       System.out.println(f.getName());
                       FFmpegRunner fFmpegRunner = new FFmpegRunner(f.getAbsolutePath(), dirOut.getAbsolutePath() + "/" + System.currentTimeMillis() + f.getName());
                       if (isNewThread) {
                           new Thread(fFmpegRunner).start();
                       } else {
                           fFmpegRunner.run();
                       }
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
               }
           }
       }

       class FFmpegRunner implements Runnable {
           private String fileIn;
           private String fileOut;

           FFmpegRunner(String fileIn, String fileOut) {
               this.fileIn = fileIn;
               this.fileOut = fileOut;
           }

           @Override
           public void run() {
               try {
                   ffmpegconverter(fileIn, fileOut);
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }

           private void ffmpegconverter(String fileIn, String fileOut) throws Exception{
               String[] comand = new String[]{"ffmpeg", "-i", fileIn, "-acodec", "pcm_s16le", fileOut};

               Process process = null;
               try {
                   ProcessBuilder pb = new ProcessBuilder(comand);
                   pb.redirectErrorStream(true);
                   process = pb.start();

                   //Reading from error and standard output console buffer of process. Or it could halts because of nobody
                   //reads its buffer
                   BufferedReader reader =
                           new BufferedReader(new InputStreamReader(process.getInputStream()));
                   String line;
                   //noinspection StatementWithEmptyBody
                   while ((line = reader.readLine()) != null) {
                       System.out.println(line);
                       //Ignored as we just need to empty the output buffer from process
                   }

                   process.waitFor();
               } catch (IOException | InterruptedException e) {
                   throw e;
               } finally {
                   if (process != null)
                       process.destroy();
               }
           }

       }

    }

    UPD3 :
    Sorry, I forgot to notice that I see the work of all these process - they created new converted files but anyway don’t exit.