Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:35:45+00:00 2026-06-11T15:35:45+00:00

I am writing my first ffmpeg application using the tutorial linked to from the

  • 0

I am writing my first ffmpeg application using the tutorial linked to from the ffmpeg.org documentation page [tutorial] [sample]. Here is my initial code:

const char * fnmVideoIn = argv [1];
const char * fnmImageOut = argv [2];

av_register_all ();

// [] Open the file
AVFormatContext * pcxFormat;
if (avformat_open_input (&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) < 0) {
    fprintf (stderr, "Could not find stream info\n");
    return -1;
}

// [log] print stream info
av_dump_format (pcxFormat, 0, fnmVideoIn, 0);

and all is well. The program runs without errors and dumps the video info properly. but then I got to the next step…

...
// [log] print stream info
av_dump_format (pcxFormat, 0, fnmVideoIn, 0);

int ixVideoStream = -1, ixStrm;
for (ixStrm = 0; ixStrm < pcxFormat->nb_streams; ++ixStrm) {
    if (pcxFormat->streams [ixStrm]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
        ixVideoStream = ixStrm;
        break;
    }
}

and it exits with a segfault. gdb says:

(gdb) r test.mp4 out
...
Program received signal SIGSEGV, Segmentation fault.
0xb7f572c5 in avformat_open_input () from /usr/lib/libavformat.so.53

how is it possible that avformat_open_input segfaults because of code added after it is called? I even tested it with a regular i=0; i<100 for-loop and it still segfaults! is this a bug? For reference, my system is:

$ 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:35:46+00:00Added an answer on June 11, 2026 at 3:35 pm

    I am not sure of the etiquette on questions whose solutions were found elsewhere, but I’ll self-answer here anyway, for posterity.

    Anyway, the first argument to avformat_open_input is a pointer to a pointer to an AVFormatContext structure allocated using avformat_alloc_context, or if you want the function to allocate it for you, a null pointer.

    Here, I’ve made the mistake of providing the function with an uninitialized pointer, which triggers the occasional segmentation fault errors. The connection with the for-loop was only incidental, and probably has something to do with how the compiler structures the resulting machine code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my first Android application and I am liberally using asserts() from
I am writing my first .NET MVC application and I am using the Code-First
While writing my first Blackberry application using Java, I am confused between inheriting from
So i am writing my first Java application using MVP pattern. One of MVPs
I am writing my first application. I was using Sparkle framework for updating but
When writing my first asp.net MVC application using C#, I see that there are
I'm writing my first application in Ruby and I had a question. Here is
I am writing my first application in rails and here is what I did
I'm writing my first Windows Forms application using VS 2010 and C# . It
Writing my first C# application...never touched the language before and not much of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.