title: FFMPEG - RTMP to HLS no audio output
body: <p>I am currently developing a dynamic HLS segmenter for our livecam application.
  Therefor I catch the external RTMP stream and convert it into segments with ffmpeg.</p>
  
  <p>The following command works:</p>
  
  <pre><code>ffmpeg -i rtmp://"$serverip"/"$application"/mp4:"$stream_name".f4v -c:v libx264 -profile:v baseline -level 5.1 \
  -c:a aac -strict experimental -flags +global_header -f mpegts - | ffmpeg -i - -c copy -map 0 -f segment \
  -segment_list /tmp/hls/"$id"/"$stream_name".m3u8 -segment_format libmp3lame -segment_time 10 \
  -segment_wrap 4 /tmp/hls/"$id"/"$stream_name"%03d.ts
  </code></pre>
  
  <p>But with this command I do have a huge latency between the livestream and the HLS output (around 1-2 minutes!).</p>
  
  <p>So I tried another command, which results in a latency of 20-30 seconds! My only problem is, that the audio stream is not recognized and also not put to HLS files (means I only got the video, but no audio at all):</p>
  
  <pre><code>ffmpeg -probesize 50k -i rtmp://"$serverip"/"$application"/mp4:"$stream_name".f4v \
  -c:v libx264 -b:v 128k -g 90 -c:a aac -strict experimental -flags -global_header -map 0 \
  -f segment -segment_time 3 -segment_list /tmp/hls/"$id"/"$stream_name".m3u8 -segment_list_flags +live \
  -segment_list_type m3u8 -segment_list_size 5 -segment_format mpegts /tmp/hls/"$id"/"$stream_name"%d.ts
  </code></pre>
  
  <p>I thought, the -c:a aac Flag should do the job for muxing the audio as well.</p>
  
  <p>Do you have any suggestions what went wrong on the second command? I definitly have to segement the audio stream as well!</p>
  
  <p>Thanks in advance</p>
  
  <p>Update:</p>
  
  <p>Some outputs of the FFMPEG command:</p>
  
  <p>I started the command (2) ones, and got an audio output, but it seems not to work everytime.</p>
  
  <p>Output from working command 2, audio is working:
  <a href="http://pastebin.com/bhxfNQBg" rel="nofollow">http://pastebin.com/bhxfNQBg</a></p>
  
  <p>Output from working command 2, audio not working (nothing changed):
  <a href="http://pastebin.com/engEuSdn" rel="nofollow">http://pastebin.com/engEuSdn</a></p>
  
  <p>Whats strange for me, is the line:</p>
  
  <pre><code>[flv @ 0x1eed900] New audio stream 0:1 at pos:716680 and DTS:0s
  </code></pre>
  
  <p>This only occurs, if the audio on hls side is NOT working. </p>
  
  <p>Any help will be appreciated</p>
  
  <p>Update 2:<br>
  It seems like there is a problem when I start the ffmpeg command after the stream is already published.<br>
  If I follow these steps, everything works fine:<br>
  1. Start Stream (nc Connection to AMS is established)<br>
  2. Start FFMPEG command (it will idle until the stream publishes)<br>
  3. Start publishing<br><br></p>
  
  <p>But If I do it like that (which we will need), no audio will be present:<br>
  1. Start Stream<br>
  2. User join, start publishing<br>
  3. Trigger ffmpeg command</p>