<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=big5">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:新細明體;
        panose-1:2 2 5 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@新細明體";
        panose-1:2 2 5 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
 /* Page Definitions */
 @page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=ZH-TW link=blue vlink=purple style='text-justify-trim:punctuation'>

<div class=Section1>

<p class=MsoNormal><span lang=EN-US>Dear Libav:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  Sorry for my poor english first.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  When using avcode_alloc_frame with
avcodec_decode_video2 to decode h264 stream, I found out that the data pointer
of AVFrame will change everytime i decode a new frame.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>So if i need to buffer the decoded frame, i
must copy the image data to other place (which allocate to store the image
data).<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Could I not to allocate memory to store the
image data (decode frame), because it will cost me 10 ms every frame ( 8 M
resolution picture)?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>If I just store the AVFrame 's data pointer
for every frames, It only had three sets of data pointer, so frames will be
overwrite if you decode more than three times before to use it (to display it
on the screen).<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>Three sets of data pointer(3 frames buffer)
is not enough for my implement of buffering decoded frame, I want to buffer 10
frames (decode 10 frames before to display it to the screen). Because I frame
of H264 ( 8M resolution) will recevie very slow  (more than 100 ms) and
decode very slow (more than 100 ms), so I need buffer 10 frames to let display
the stream smoothly.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>My question is : <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  1. Could ffmpeg decode h264 use 10
sets of data pointer (not just three sets of data pointer)?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  or <o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  2. Could I allocate my own memory to
the data[] array to AVFrame (not allocate by the ffmpeg library)?<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>example code is describe as follow:<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>/* c code bellow */<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  AVFrame * pFrame;<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  pFrame = avcode_alloc_frame();<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  while (still_has_h264_frame)<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  {<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>   
avcodec_decode_video2(avctx, pFrame,....);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>    printf(" data
pointer of pFrame: %d %d %d \n", pFrame->data[0], pFrame->data[1],
pFrame->data[2]);<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>  }<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>/*  result print log */<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 396361792 395445504
401670240<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 405536832 402628512
402864768<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 430506048 431489120
431725376<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 396361792 395445504
401670240   <---  from here , the data point is the same as
1'th frame<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 405536832 402628512
402864768   <---  from here , the data point is the same as
2'th frame<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>data pointer of pFrame: 430506048 431489120
431725376   <---  from here , the data point is the same as
3'th frame<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US>......<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-family:"Tahoma","sans-serif";
color:#333333'>Best Regards,<o:p></o:p></span></p>

<p class=MsoNormal><b><span lang=EN-US style='font-family:"Tahoma","sans-serif";
color:#333333'>Antony Lin<o:p></o:p></span></b></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>

</div>

</body>

</html>