title: RTSP to HLS with GStreamer
body: <p>I'm trying to capture RTSP (H264 / AAC) stream with GStreamer and save it to HLS. The command runnung is:</p>
  
  <pre><code>gst-launch-1.0 -v -e rtspsrc protocols=tcp \
      location=rtsp://${AXIS_CAMERA_ADDR}/axis-media/media.amp \
      ! queue ! rtph264depay ! h264parse ! mpegtsmux \
      ! hlssink location="%06d.ts" target-duration=5
  </code></pre>
  
  <p>At first glance everything looks fine: *.ts files and playlist are generated. But *.ts are invalid - no player can play them (VLC, Safari, MPV). Interestingly, that the very first 000000.ts file is OK.</p>
  
  <p>I also tried to perform same job with FFMPEG:</p>
  
  <pre><code>ffmpeg -rtsp_flags prefer_tcp \
      -i rtsp://${AXIS_CAMERA_ADDR}/axis-media/media.amp \
      -acodec copy -vcodec copy -f ssegment \
      -segment_list ffmpeg.m3u8 \
      -segment_list_flags +live \
      -segment_time 5 \
      ffmpeg%06d.ts
  </code></pre>
  
  <p>and it's working as expected.</p>
  
  <p>What is wrong with my GStreamer command? Also I noticed that GStreamer and FFMPEG produces different *.ts files headers.</p>
  
  <p>GStreamer TS-header: <code>4740 003a a600 ffff ffff ffff ffff ffff
  ffff ffff ffff ...</code></p>
  
  <p>FFMPEG TS-header: <code>4740 1110 0042 f03b 0001 c100 00ff 01ff
  0001 fc80 2a48 2801 0646 466d 7065 671f
  5365 7373 696f 6e20 7374 7265 616d 6564
  2077 6974 6820 4753 7472 6561 6d65 7251
  f383 85ff ffff ffff ffff ffff ffff ffff
  ffff ffff ffff ffff</code></p>
  
  <p>looks like FFMPEG produces headers with more info.</p>
  
  <p>And btw saving to MKV (matroskamux) from RTSP with GStreamer works fine.</p>