gpt4 book ai didi

c - 由于for循环而使用ffmpeg段错误的应用程序?

转载 作者:太空宇宙 更新时间:2023-11-04 03:00:49 25 4
gpt4 key购买 nike

我正在使用从 ffmpeg.org 文档页面链接到的教程编写我的第一个 ffmpeg 应用程序 [ tutorial ] [ sample ].这是我的初始代码:

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

一切顺利。该程序运行无误,并正确转储视频信息。但后来我进入了下一步......

...
// [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;
}
}

并且它以段错误退出。 gdb 说:

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

avformat_open_input 怎么可能因为在 之后添加的代码被调用而出现段错误?我什至用常规的 i=0 测试过它; i<100 for-loop,它仍然是段错误!这是一个错误吗?作为引用,我的系统是:

$ 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

最佳答案

我不确定在其他地方找到解决方案的问题的礼节,但我还是会在这里 self 回答,以供后代使用。

无论如何,avformat_open_input 的第一个参数是指向使用 avformat_alloc_context 分配的 AVFormatContext 结构的指针,或者如果您想要函数为你分配它,一个空指针。

在这里,我犯了一个错误,即为函数提供了一个未初始化的指针,这偶尔会触发段错误。与 for 循环的联系只是偶然的,可能与编译器如何构造生成的机器代码有关。

关于c - 由于for循环而使用ffmpeg段错误的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12361377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com