<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><div>>From: mohamed_moanis@outlook.com<br>>To: libav-user@ffmpeg.org<br>>Date: Sun, 21 Jun 2015 13:57:30 +0300<br>>Subject: [Libav-user] avformat_open_input error with custom IO<br>><br><div dir="ltr"><span style="font-size: 12pt;">></span>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 <span style="font-size: 12pt;">></span><span style="font-size: 12pt;">later processing.</span></div><div dir="ltr"><div><span style="font-size: 12pt;">></span>For now my function just read the first two successive frames, then the call to </div><blockquote style="padding-right: 0px; padding-left: 0px; border: none;"><h1 style="padding: 0px; border: 0px; line-height: 1.3; color: rgb(34, 34, 34); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; background-color: rgb(255, 255, 255);"><font size="3" style="padding: 0px; border: 0px; cursor: pointer; line-height: 1.35; font-weight: normal;"><a href="http://stackoverflow.com/questions/30890744/libav-avformat-open-input-error-code-1094995529" class="ecxquestion-hyperlink" target="_blank" style="padding: 0px; border: 0px; text-decoration: none; cursor: pointer; color: rgb(34, 34, 34); line-height: 1.35;">avformat_open_input return -1094995529</a></font></h1><div><br></div><div><br></div></blockquote><div><span style="font-size: 12pt;">></span>uint8_t* buffer = NULL, * avioCxt_buffer = NULL;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>buffer_data bd;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>int ret = 0;</div><div>></div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>bd.ptr = (uint8_t *) pJPEGFrame;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>bd.size = len;</div><div>></div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>// allocate the context data structure</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>if ( (*outputFormatCxt = avformat_alloc_context() ) == NULL)</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>{</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory for context", __LINE__);</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>return -1;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>}</div><div>></div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>if ( (avioCxt_buffer = (uint8_t *) av_malloc(len)) == NULL)</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>{</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>avformat_close_input(outputFormatCxt);</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>return -1;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>}</div><div>></div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>if ( (*pAvIOCxt = avio_alloc_context(avioCxt_buffer, len, 0, &bd, read_packet, NULL, NULL)) == NULL)</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>{</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>return -1;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>}</div><div>></div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>(*outputFormatCxt)->pb = *pAvIOCxt;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>if ( (ret = avformat_open_input(outputFormatCxt, NULL, NULL, NULL)) < 0)</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>{</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>fprintf(stderr, "convert_JPEG_Frame_TO_AVFrame @line(%d) - failed to allocate memory", __LINE__);</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>return -1;</div><div><span class="ecxApple-tab-span" style="white-space: pre;"><span style="font-size: 12pt;">></span> </span>}</div><div>></div><div><span style="font-size: 12pt;">></span>I am following the avio_read example using the same read callback function for the avio context.</div><div>></div><div><span style="font-size: 12pt;">></span>Thanks in advance.</div><div><br></div><div><br></div></div></div>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.<div>I found that the problem is in the probe this function <span style="color: rgb(37, 53, 85); font-family: Roboto, sans-serif; font-size: 14px; font-weight: bold; line-height: 22px; background-color: rgb(226, 232, 242);">av_probe_input_format</span></div><div>the return score for the first two frames is correct its "jpeg_pipe"</div><div>but for the other frames it return probe_score = 1</div><div><br></div><div>so I made my turnaround by associating the iformat field of the AVFormatContext</div><div> using this code - I am guaranteed to have only jpeg files.</div><div><br></div><div><div>AVInputFormat * iformat = av_find_input_format("jpeg_pipe");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (!iformat) return -1;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>(*outputFormatCxt)->iformat = iformat;</div></div><div><br></div><div>And it worked fine!</div><div><br></div><div>I don't really understand the problem, nor I do understand what might be the consequences of that turn around.</div><div><br><div><br></div></div><style><!--
.ExternalClass .ecxhmmessage P {
padding:0px;
}
.ExternalClass body.ecxhmmessage {
font-size:12pt;
font-family:Calibri;
}
--></style> </div></body>
</html>