
Recherche avancée
Autres articles (59)
-
Les vidéos
21 avril 2011, parComme 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 2011Vous 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, parMediaspip 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 saulspatzI’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 runmake
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&, cv::String const&, 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&) 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
"_hb_buffer_create", 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
"_hb_buffer_destroy", 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
"_hb_buffer_get_glyph_infos", 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
"_hb_buffer_guess_segment_properties", 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
"_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&) 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
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 leonardltk1i am continuously reading mp3 files and processing them, but the memory keeps getting build up even though i freed it.


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

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


int read_audio_mp3(string filePath_str, const int sample_rate, 
 double** output_buffer, int &AUDIO_DURATION){
 const char* path = filePath_str.c_str();

 /* Reads the file header and stores information about the file format. */
 AVFormatContext* format = avformat_alloc_context();
 if (avformat_open_input(&format, path, NULL, NULL) != 0) {
 fprintf(stderr, "Could not open file '%s'\n", path);
 return -1;
 }

 /* Check out the stream information in the file. */
 if (avformat_find_stream_info(format, NULL) < 0) {
 fprintf(stderr, "Could not retrieve stream info from file '%s'\n", path);
 return -1;
 }

 /* find an audio stream. */
 int stream_index =- 1;
 for (unsigned i=0; inb_streams; i++) {
 if (format->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
 stream_index = i;
 break;
 }
 }
 if (stream_index == -1) {
 fprintf(stderr, "Could not retrieve audio stream from file '%s'\n", path);
 return -1;
 }
 AVStream* stream = format->streams[stream_index];

 // find & open codec
 AVCodecContext* codec = stream->codec;
 if (avcodec_open2(codec, avcodec_find_decoder(codec->codec_id), NULL) < 0) {
 fprintf(stderr, "Failed to open decoder for stream #%u in file '%s'\n", stream_index, path);
 return -1;
 }

 // prepare resampler
 struct SwrContext* swr = swr_alloc();
 av_opt_set_int(swr, "in_channel_count", codec->channels, 0);
 av_opt_set_int(swr, "out_channel_count", 1, 0);
 av_opt_set_int(swr, "in_channel_layout", codec->channel_layout, 0);
 av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_MONO, 0);
 av_opt_set_int(swr, "in_sample_rate", codec->sample_rate, 0);
 av_opt_set_int(swr, "out_sample_rate", sample_rate, 0);
 av_opt_set_sample_fmt(swr, "in_sample_fmt", codec->sample_fmt, 0);
 av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_DBL, 0);
 swr_init(swr);
 if (!swr_is_initialized(swr)) {
 fprintf(stderr, "Resampler has not been properly initialized\n");
 return -1;
 }

 /* Allocate an audio frame. */
 AVPacket packet;
 av_init_packet(&packet);
 AVFrame* frame = av_frame_alloc();
 if (!frame) {
 fprintf(stderr, "Error allocating the frame\n");
 return -1;
 }

 // iterate through frames
 *output_buffer = NULL;
 AUDIO_DURATION = 0;
 while (av_read_frame(format, &packet) >= 0) {
 // decode one frame
 int gotFrame;
 if (avcodec_decode_audio4(codec, frame, &gotFrame, &packet) < 0) {
 // free packet
 av_free_packet(&packet);
 break;
 }
 if (!gotFrame) {
 // free packet
 av_free_packet(&packet);
 continue;
 }
 // resample frames
 double* buffer;
 av_samples_alloc((uint8_t**) &buffer, NULL, 1, frame->nb_samples, AV_SAMPLE_FMT_DBL, 0);
 int frame_count = swr_convert(swr, (uint8_t**) &buffer, frame->nb_samples, (const uint8_t**) frame->data, frame->nb_samples);
 // append resampled frames to output_buffer
 *output_buffer = (double*) realloc(*output_buffer,
 (AUDIO_DURATION + frame->nb_samples) * sizeof(double));
 memcpy(*output_buffer + AUDIO_DURATION, buffer, frame_count * sizeof(double));
 AUDIO_DURATION += frame_count;
 // free buffer & packet
 av_free_packet(&packet);
 av_free( buffer );
 }

 // clean up
 av_frame_free(&frame);
 swr_free(&swr);
 avcodec_close(codec);
 avformat_free_context(format);

 return 0;
 }



Main Script :
MemoryLeak.cpp


// imports
 #include <fstream>
 #include 
 #include 
 #include 
 #include 
 #include <iostream>
 #include <sstream>
 #include <vector>
 #include <sys></sys>time.h> 
 extern "C"
 {
 #include <libavutil></libavutil>opt.h>
 #include <libavcodec></libavcodec>avcodec.h>
 #include <libavformat></libavformat>avformat.h>
 #include <libswresample></libswresample>swresample.h>
 }
 using namespace std;

 int main (int argc, char ** argv) {
 string wavpath = argv[1];
 printf("wavpath=%s\n", wavpath.c_str());

 printf("\n==== Params =====\n");
 // Init
 int AUDIO_DURATION;
 int sample_rate = 8000;
 av_register_all();

 printf("\n==== Reading MP3 =====\n");
 while (true) {
 // Read mp3
 double* buffer;
 if (read_audio_mp3(wavpath, sample_rate, &buffer, AUDIO_DURATION) != 0) {
 printf("Cannot read %s\n", wavpath.c_str());
 continue;
 }

 /* 
 Process the buffer for down stream tasks.
 */

 // Freeing the buffer
 free(buffer);
 }

 return 0 ;
 }
</vector></sstream></iostream></fstream>


Compiling


g++ -o ./MemoryLeak.out -Ofast -Wall -Wextra \
 -std=c++11 "./MemoryLeak.cpp" \
 -lavformat -lavcodec -lavutil -lswresample



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

./MemoryLeak.out song.mp3



Why do i know i have memory leaks ?


- 

- I was running up 32 jobs in parallel for 14 million files, and when i wake up in the morning, they were abruptly killed.
- I run
htop
and i monitor the progress when i re-run it, and i saw that theVIRT
&RES
&Mem
are continuously increasing.








Edit 1 :
My setup :




ffmpeg version 2.8.15-0ubuntu0.16.04.1
built with gcc 5.4.0



-
FFMpeg process created from Java on CentOS doesn't exit
21 juin 2017, par DonzI 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 < 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.