title: FFmpeg efficient capture from rtsp ipcamera
body: <p>I need to capture an audio/video rtsp stream uncompressed in a file from ipcamera. Audio (pcm_alaw) and video (h264) must be synchronized. It is necessary that the file does not get corrupted if the camera loses the connection for a few moments (mp4).</p>
  <p>At the moment I use the command below, but the ts codec does not support pcm_alaw and therefore the audio is not heard:</p>
  <pre><code>ffmpeg -stimeout 2000000 -rtsp_transport tcp -i rtsp://admin:1234@192.168.5.22/h264 -c:v copy -c:a copy -f mpegts -y main.ts
  </code></pre>
  <p>I use the mpegts codec because I need to check the duration of the capture in real time with the command:</p>
  <pre><code>ffprobe -i /home/pi/NAS/main.mov -show_entries format=duration -v quiet -of csv=&quot;p=0&quot;
  </code></pre>
  <p>If i use mkv or avi its output would be:</p>
  <pre><code>N/A
  </code></pre>
  <p>The verification of the duration is important because I capture files of about 3 hours and at my choice I perform some data while the capture is in progress. I prefer not to compress the audio because I have often noticed some asynchrony with respect to the video when cutting.</p>
  <p>Thank you.</p>