Note that there are some explanatory texts on larger screens.

plurals
  1. POapplication using ffmpeg segfaults because of for loop?
    text
    copied!<p>I am writing my first ffmpeg application using the tutorial linked to from the ffmpeg.org documentation page [<a href="http://dranger.com/ffmpeg/" rel="nofollow">tutorial</a>] [<a href="https://github.com/mpenkov/ffmpeg-tutorial" rel="nofollow">sample</a>]. Here is my initial code:</p> <pre><code>const char * fnmVideoIn = argv [1]; const char * fnmImageOut = argv [2]; av_register_all (); // [] Open the file AVFormatContext * pcxFormat; if (avformat_open_input (&amp;pcxFormat, fnmVideoIn, NULL, NULL)) { fprintf (stderr, "Could not open file %s for reading\n", fnmVideoIn); return -1; } // [] Get stream information if (avformat_find_stream_info (pcxFormat, NULL) &lt; 0) { fprintf (stderr, "Could not find stream info\n"); return -1; } // [log] print stream info av_dump_format (pcxFormat, 0, fnmVideoIn, 0); </code></pre> <p>and all is well. The program runs without errors and dumps the video info properly. but then I got to the next step...</p> <pre><code>... // [log] print stream info av_dump_format (pcxFormat, 0, fnmVideoIn, 0); int ixVideoStream = -1, ixStrm; for (ixStrm = 0; ixStrm &lt; pcxFormat-&gt;nb_streams; ++ixStrm) { if (pcxFormat-&gt;streams [ixStrm]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO) { ixVideoStream = ixStrm; break; } } </code></pre> <p>and it exits with a segfault. gdb says:</p> <pre><code>(gdb) r test.mp4 out ... Program received signal SIGSEGV, Segmentation fault. 0xb7f572c5 in avformat_open_input () from /usr/lib/libavformat.so.53 </code></pre> <p>how is it possible that <code>avformat_open_input</code> segfaults because of code added <em>after</em> it is called? I even tested it with a regular i=0; i&lt;100 for-loop and it still segfaults! is this a bug? For reference, my system is:</p> <pre><code>$ gcc --version gcc (GCC) 4.7.0 20120414 (prerelease) $ uname -srvmpio Linux 3.3.4-1-ARCH #1 SMP PREEMPT Sat Apr 28 06:04:27 UTC 2012 i686 Intel(R) Core(TM)2 Duo CPU P7450 @ 2.13GHz GenuineIntel GNU/Linux $ ffmpeg -version ffmpeg version 0.10.2 built on Mar 17 2012 08:53:01 with gcc 4.6.3 configuration: --prefix=/usr --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-libgsm --enable-libspeex --enable-postproc --enable-shared --enable-x11grab --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libschroedinger --enable-libopenjpeg --enable-librtmp --enable-libpulse --enable-gpl --enable-version3 --enable-runtime-cpudetect --disable-debug --disable-static libavutil 51. 35.100 / 51. 35.100 libavcodec 53. 61.100 / 53. 61.100 libavformat 53. 32.100 / 53. 32.100 libavdevice 53. 4.100 / 53. 4.100 libavfilter 2. 61.100 / 2. 61.100 libswscale 2. 1.100 / 2. 1.100 libswresample 0. 6.100 / 0. 6.100 libpostproc 52. 0.100 / 52. 0.100 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload