[Libav-user] ffmpeg threading
Ierum Shanaya
ierumshanaya85 at gmail.com
Thu Oct 30 08:12:49 CET 2014
hi,
I am setting the thread_count as below:
code snippet: In example file -
https://www.ffmpeg.org/doxygen/trunk/demuxing_decoding_8c-example.html
--------------------------------------------------------
int main (int argc, char **argv)
{
int ret = 0, got_frame;
//unsigned long start, end;
int frame_count=0;
char frameStart[50], frameEnd[50];
//FILE *fp;
SimRoiStart();
//srand((unsigned int)time(NULL));
if (argc != 4 && argc != 5) {
fprintf(stderr, "usage: %s [-refcount=<old|new_norefcount|new_refcount>] "
"input_file video_output_file audio_output_file\n"
"API example program to show how to read frames from an input file.\n"
"This program reads frames from a file, decodes them, and writes decoded\n"
"video frames to a rawvideo file named video_output_file, and decoded\n"
"audio frames to a rawaudio file named audio_output_file.\n\n"
"If the -refcount option is specified, the program use the\n"
"reference counting frame system which allows keeping a copy of\n"
"the data for longer than one decode call. If unset, it's using\n"
"the classic old method.\n"
"\n", argv[0]);
exit(1);
}
if (argc == 5) {
const char *mode = argv[1] + strlen("-refcount=");
if (!strcmp(mode, "old")) api_mode = API_MODE_OLD;
else if (!strcmp(mode, "new_norefcount")) api_mode =
API_MODE_NEW_API_NO_REF_COUNT;
else if (!strcmp(mode, "new_refcount")) api_mode =
API_MODE_NEW_API_REF_COUNT;
else {
fprintf(stderr, "unknow mode '%s'\n", mode);
exit(1);
}
argv++;
}
src_filename = argv[1];
video_dst_filename = argv[2];
audio_dst_filename = argv[3];
/* register all formats and codecs */
av_register_all();
/* open input file, and allocate format context */
if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) {
fprintf(stderr, "Could not open source file %s\n", src_filename);
exit(1);
}
/* retrieve stream information */
if (avformat_find_stream_info(fmt_ctx, NULL) < 0) {
fprintf(stderr, "Could not find stream information\n");
exit(1);
}
if (open_codec_context(&video_stream_idx, fmt_ctx, AVMEDIA_TYPE_VIDEO) >=
0) {
video_stream = fmt_ctx->streams[video_stream_idx];
video_dec_ctx = video_stream->codec;
*//set number of threads to be utilized for video decoding*
* video_dec_ctx->thread_count = 7;*
* video_dec_ctx->thread_type = FF_THREAD_SLICE; //multithreading method set
to slice-based*
video_dst_file = fopen(video_dst_filename, "wb");
if (!video_dst_file) {
fprintf(stderr, "Could not open destination file %s\n", video_dst_filename);
ret = 1;
goto end;
}
.....................
---------------------------------------------------------------
and for compilation the command used is -
gcc -o demuxing_decoding demuxing_decoding.c -lavutil -lavformat -lavcodec
-lz -lavutil -lm -lpthread -lbz2
The threads are not getting created, I have set the thread_count to 7 to
create 8 threads.
I have also tried by setting the thread_count to 0 for automatic thread
creation based on the no of cores.
Any pointers will be helpful.
Thanks,
Ierum
On Mon, Oct 27, 2014 at 9:48 PM, wm4 <nfxjfg at googlemail.com> wrote:
> On Mon, 27 Oct 2014 16:08:33 +0530
> Ierum Shanaya <ierumshanaya85 at gmail.com> wrote:
>
> > Hi,
> >
> > I am trying to run ffmpeg video decoding by creating multiple threads.
> The
> > problem i am facing is that only one thread is created, irrespective of
> > setting the thread_count to 0 or any no like say 2 , 4 etc.
> >
> > I did check the config as below:
> >
> > *it doesnt have --enable pthreads things.. Is this the issue??. *
> > If so, how to set the --enable pthread again in ffmpeg?? Can someone
> please
> > help me understand.
> >
> > I have Ubuntu 12.4 on my system(64 bit)
> >
> > *Output:*
> > -----------------------------------------------------------------
> >
> > ierumshanaya at ubuntu:~/ffmpeg_sources/ffmpeg$ ffmpeg
> > ffmpeg version git-2014-01-05-f5f6e59 Copyright (c) 2000-2014 the FFmpeg
> > developers
> > built on Jan 22 2014 19:00:25 with gcc 4.6 (Ubuntu/Linaro
> 4.6.3-1ubuntu5)
> > *configuration*: --prefix=/home/ierumshanaya/ffmpeg_build/lib/pkgconfig
> > --extra-cflags=-I/home/ierumshanaya/ffmpeg_build/include
> > --extra-ldflags=-L/home/ierumshanaya/ffmpeg_build/lib
> > --bindir=/home/ierumshanaya/bin --extra-libs=-ldl --enable-gpl
> > --enable-libass --enable-libfdk-aac --enable-libmp3lame
> --enable-libtheora
> > --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
> > --enable-x11grab
> > libavutil 52. 60.100 / 52. 60.100
> > libavcodec 55. 47.100 / 55. 47.100
> > libavformat 55. 22.102 / 55. 22.102
> > libavdevice 55. 5.102 / 55. 5.102
> > libavfilter 4. 0.103 / 4. 0.103
> > libswscale 2. 5.101 / 2. 5.101
> > libswresample 0. 17.104 / 0. 17.104
> > libpostproc 52. 3.100 / 52. 3.100
> > Hyper fast Audio and Video encoder
> > usage: ffmpeg [options] [[infile options] -i infile]... {[outfile
> options]
> > outfile}...
> > Thanks,
> > Ierum
>
> Are you setting the thread_count before "opening" the decoder?
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20141030/23e2bee2/attachment.html>
More information about the Libav-user
mailing list