<div dir="ltr">I have an RTSP video stream encoded by h264 that carries camera's timestamps inside SEI NAL units. <div>I'm not sure where those units are exactly located, but I have an example of how to output them using a patch for ffmpeg:</div><div><br></div>





<div><span style="color:rgb(0,0,0);font-family:"Times New Roman"">libavcodec/h2645_parse.c:</span></div><div><br></div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">...</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+ #include <inttypes.h></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">...</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">static int h264_parse_nal_header(H2645NAL *nal, void *logctx)</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">     </span>nal->ref_idc = get_bits(gb, 2);</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">     </span>nal->type<span class="gmail-Apple-converted-space">    </span>= get_bits(gb, 5);</p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0);min-height:11px"><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+<span class="gmail-Apple-converted-space">    </span>if( nal->type == 6 ) {</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+<span class="gmail-Apple-converted-space">        </span>uint64_t* ts = (uint64_t*)(nal->data+3);</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+<span class="gmail-Apple-converted-space">        </span>av_log(logctx, AV_LOG_DEBUG,</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+ <span class="gmail-Apple-converted-space">              </span>"nal_unit_type: %d(%s), nal_ref_idc: %d, ts: %"PRId64"\n",</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+ <span class="gmail-Apple-converted-space">              </span>nal->type, h264_nal_unit_name(nal->type), nal->ref_idc, *ts );</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:"Times New Roman";color:rgb(0,0,0)">+<span class="gmail-Apple-converted-space">        </span>return 1;</p>
<div><span style="color:rgb(0,0,0);font-family:"Times New Roman"">+</span><span class="gmail-Apple-converted-space" style="color:rgb(0,0,0);font-family:"Times New Roman"">    </span><span style="color:rgb(0,0,0);font-family:"Times New Roman"">}</span>    <br clear="all"><div><br></div><div>After applying this patch ffmpeg starts showing timestamps that I need.</div><div><br></div><div>Is it possible to decode those timestamps alongside with video frames using libav* libraries? Since I'm not a video or C programming expert, ideally I'd like to do it using Python (OpenCV or PyAV), but any help is appreciated. </div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Andrey</div></div></div></div></div>