<div dir="ltr"><div><div>Hi, FFmpeg users!<br><br></div>I'm developing a stream recording application. So it takes arbitrary stream and records it in chunks of approx 20 minutes, splitting input stream at key frame boundaries.<br></div><div><br>I'm using this stream for testing purposes (recording only video stream): <a href="http://bitmovin-a.akamaihd.net/content/playhouse-vr/m3u8s/105560.m3u8">http://bitmovin-a.akamaihd.net/content/playhouse-vr/m3u8s/105560.m3u8</a><br></div><div>It initializes properly and first packets, including first key frame, are good. I save them with output context without any problem.<br><br></div><div>But when next key frames arrive their PTS/DTS are set to AV_NOPTS_VALUE. av_interleaved_write_frame function expectedly complains about it and produces garbled videos. This is strange, because av_read_frame function states that<br><br> * pkt->pts, pkt->dts and pkt->duration are always set to correct<br> * values in AVStream.time_base units (and guessed if the format cannot<br> * provide them).<br><br>I've tried to open this stream by ffmpeg with '-fdebug t' option and it also shows key frame packets  without PTS:<br><br>$ ffmpeg -fdebug ts -i <a href="http://bitmovin-a.akamaihd.net/content/playhouse-vr/m3u8s/105560.m3u8">http://bitmovin-a.akamaihd.net/content/playhouse-vr/m3u8s/105560.m3u8</a> -an -f null<br>...<br>[hls,applehttp @ 0xe004e0] ff_read_packet stream=1, pts=NOPTS, dts=NOPTS, size=464722, duration=3003, flags=1<br>[hls,applehttp @ 0xe004e0] read_frame_internal stream=1, pts=NOPTS, dts=NOPTS, size=464722, duration=3003, flags=1<br>[hls,applehttp @ 0xe004e0] ff_read_packet stream=1, pts=1099098, dts=1084083, size=223452, duration=3003, flags=0<br>[hls,applehttp @ 0xe004e0] read_frame_internal stream=1, pts=1099098, dts=1084083, size=223452, duration=3003, flags=0<br>...<br></div><div>As you can see, PTS/DTS are missing only in key frame (flags=1).<br><br></div><div>Remuxing this stream to mp4 with ffmpeg gives no artifacts on the video and no errors are shown in the output. So it fixes PTS/DTS somehow to maintain their sequence.<br><br>Now I simply keep track of previous packet PTS/DTS values and alter them according to duration. But this approach can handle only PTS/DTS loss only in presence of duration (which is not reliable also).<br><br>So, what is the best way to fix input stream PTS/DTS returned from av_read_frame?<br></div><div></div><div><br></div>Yurii<br></div>