title: Adding current time as timestamp in H.264 raw stream with few frames
body: <p>I have a program that spits out an H.264 raw stream (namely, <code>screenrecord</code> on Android). I'm using <a href="https://en.wikipedia.org/wiki/FFmpeg" rel="nofollow noreferrer">FFmpeg</a> to add a PTS (presentation time stamp) on the frames as follows:</p>
  
  <pre><code>$ my-program | ffmpeg -i - -filter:v setpts='(RTCTIME - RTCSTART) / (TB * 1000000)' out.mp4
  </code></pre>
  
  <p>This filter computes the current time, and puts it as the PTS.</p>
  
  <p>The trouble is that <code>my-program</code> does not produce any output if there isn't any change in the video. Since FFmpeg seems to wait for a bunch of frames before putting them through the <code>setpts</code> filter, the computed PTS won't be correct. In particular, the last frame of a sequence will be timestamped when the next sequence starts.</p>
  
  <p>Is there a way (with FFmpeg or otherwise) to add the current time as PTS to H.264 raw frames, where "current time" is when <em>receiving</em> the frame, rather than outputting it?</p>
  
  <p><em>Note:</em> The problem is <em>not</em> from buffering from the pipe.</p>