[Libav-user] avformat_open_input error with custom IO

Mohamed Moanis mohamed_moanis at outlook.com
Sun Jun 21 14:19:37 CEST 2015


>From: mohamed_moanis at outlook.com
>To: libav-user at ffmpeg.org
>Date: Sun, 21 Jun 2015 13:57:30 +0300
>Subject: [Libav-user] avformat_open_input error with custom IO
>
>I am trying to implement a custom IO read, where I have some jpeg frames coming as byte array and I have to decode them for >later processing.>For now my function just read the first two successive frames, then the call to avformat_open_input return -1094995529

>uint8_t* buffer = NULL, * avioCxt_buffer = NULL;>		buffer_data bd;>		int ret = 0;>>		bd.ptr = (uint8_t *) pJPEGFrame;>		bd.size = len;>>		// allocate the context data structure>		if ( (*outputFormatCxt = avformat_alloc_context() ) == NULL)>		{>			fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory for context", __LINE__);>			return -1;>		}>>		if ( (avioCxt_buffer = (uint8_t *) av_malloc(len)) == NULL)>		{>			fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);>			avformat_close_input(outputFormatCxt);>			return -1;>		}>>		if ( (*pAvIOCxt = avio_alloc_context(avioCxt_buffer, len, 0, &bd, read_packet, NULL, NULL)) == NULL)>		{>			fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);>			return -1;>		}>>		(*outputFormatCxt)->pb = *pAvIOCxt;>		if ( (ret = avformat_open_input(outputFormatCxt, NULL, NULL, NULL)) < 0)>		{>			fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);>			return -1;>		}>>I am following the avio_read example using the same read callback function for the avio context.>>Thanks in advance.

I tried to make a turn around after reading the source code of the library - I am working on windows, I can't do much debuging.I found that the problem is in the probe this function av_probe_input_formatthe return score for the first two frames is correct its "jpeg_pipe"but for the other frames it return probe_score = 1
so I made my turnaround by associating the iformat field of the AVFormatContext using this code - I am guaranteed to have only jpeg files.
AVInputFormat * iformat = av_find_input_format("jpeg_pipe");		if (!iformat) return -1;		(*outputFormatCxt)->iformat = iformat;
And it worked fine!
I don't really understand the problem, nor I do understand what might be the consequences of that turn around.

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150621/77182b09/attachment.html>


More information about the Libav-user mailing list