Thursday, January 19, 2012

Problem with avformat_open_input()

I lost too much time because of a misleading error message reported by avformat_open_input function! I used cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following code that exhibit cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 error:
AVFormatContext *pFormatCtx = NULL;
...
ret = avformat_open_input(&pFormatCtx, argv[1], NULL, NULL);
if (ret < 0)
   print_error_and_exit(ret, "avformat_open_input()");
print_error_and_exit() is a helper function that uses av_strerror() to give textual representation of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 error code stored in ret. Running this code produced cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following output:
$ ./a.out infile.wav outfile.wav
avformat_open_input(): No such file or directory
But cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 infile.wav was cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re! Using strace I found that open system call wasn't called and so it was certainly an internal error. This was frustrating! The reason I started to write this code was to find out why I'm getting anocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r error in VoIP tool simulator, but I was stuck on something even more basic: Not being able to open a wav file. Googling around I finally found cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 following link which explained me a real cause of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 error, i.e. I forgot to call av_register_all() initialization function.

This again shows how important good error reporting is, in both libraries and application programs!

I had also anocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r problem with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 previous code. It was segfaulting within avformat_open_input(). At first, I thought that I found a bug within a library but cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n I realized I forgot to initialize pFormatCtx to NULL. Namely, allocating a dynamic variable on stack didn't zero it so it was non-NULL and avformat_open_input() misbehaved. Mea culpa! :)

8 comments:

Unknown said...
This comment has been removed by cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 author.
Unknown said...

I have a probleme with avformat_open_input() function;
it works fine with an http url, but it won't work with an mms url.. any ideas?

Unknown said...

I have a probleme with avformat_open_input() function;
it works fine with an http url, but it won't work with an mms url.. any ideas?

Stjepan Groš (sgros) said...

Are you certain that mms url is supported?

Unknown said...

ffmpeg doesn't support mms:// in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 URL try mmsh:// instead. That fixed my problem

Unknown said...
This comment has been removed by cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 author.
Mark Glines said...

"I forgot to initialize pFormatCtx to NULL."

I ran into cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same thing. This just saved me some valuable debugging time, thanks!

Unknown said...

thank you so much for that "I forgot to initialize pFormatCtx to NULL." bit. saved me several hours and headaches.

About Me

scientist, consultant, security specialist, networking guy, system administrator, philosopher ;)

Blog Archive