<p>I missed the <a href="https://ffmpeg.org/ffmpeg.html#Advanced-options" rel="nofollow noreferrer">-re</a> flag that would limit speed of reading the generators at a speed of playback.</p>

<p>My ffmpeg was streaming data to Periscope as fast as it can, much faster than a live stream would, thus exceeding the bitrate limits.</p>

<p>Working code, that will stream a test table with a timecode running on top of it to Periscope:</p>

<pre><code>ffmpeg \
    -re \
    -f lavfi \
    -i testsrc=rate=30:size=960x540,format=yuv420p \
    -re \
    -f lavfi \
    -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 22 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 2400k \
        -g 60 \
    -c:a aac \
        -ac 2 \
        -b:a 96k \
        -maxrate:a 96k \
        -bufsize:a 192k \
    -f flv \
    -flvflags no_duration_filesize \
    -y  -hide_banner \
    rtmp://de.pscp.tv:80/x/MYSECRETCODE
</code></pre>

CC BY-SA 3.0
2017-10-06T08:36:32.370Z
2017-10-06T08:36:32.370Z
Serge
<p>You can use option <code>-ab</code>, like <code>-ab 32000</code> for 32kbit/s bitrate audio. But here may be problem: not all codecs (encoders) can support so small bitrate. For example, libaacplus can do even smaller, but it was removed from ffmpeg.</p>

<p>You can use options <code>-qmix</code> and <code>-qmax</code> for define video quality. Try something like <code>-qmin 32 -qmax 64</code>. Also, check <code>-bufsize</code>, you set it to 1400k.</p>

CC BY-SA 3.0
2017-10-05T14:58:08.420Z
Thanks! I tried `-ab 128k` with no improvement: my ffmpeg lists 323kbps, Periscope goes crazy with 591kbps sound bitrate. `qmin/qmax` are video options. Somehow video bitrate is okay for P. 

Setting bufsize doesn't seem to affect "periscope bitrate".
Serge
CC BY-SA 3.0
2017-10-06T07:05:36.283Z
try very low values like -ab 32000 -qmin 50 -qmax 64
bukkojot
CC BY-SA 3.0
2017-10-06T08:31:02.357Z
I already found the cause of error: missed the `-re` option. Without it my ffmpeg was streaming content as fast as it could: ahead of "live" time.
Serge
CC BY-SA 3.0
2017-10-05T14:15:54.670Z
2017-10-05T14:15:54.670Z
bukkojot
<p>I just noticed Periscope <a href="https://www.pscp.tv/help/external-encoders" rel="nofollow noreferrer">Producer</a> capability to accept live streaming from external sources. </p>

<p>A quick test with ffmpeg fails to fit bitrate requirements of 160kbps max for audio. Periscope says my audio bitrate is "475.243 kbps", while allowd max is 160kbps. </p>

<p>"testsrc" creates a test pattern video and "sine" filter generates a 440Hz tone with beeps. I tried various settings to limit video and audio bitrate, but none seems to work. Here's the latest test:</p>

<pre><code>ffmpeg -f lavfi -i testsrc=rate=30:size=960x540,format=yuv420p \
    -f lavfi -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 26 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 1400k \
        -bt:v 100k \
        -g 60 \
        -b:v 600k \
    -c:a aac \
        -bt:a 10k \
        -b:a  128k \
        -y  -hide_banner \
    -f flv \
    -flvflags no_duration_filesize \
    rtmp://de.pscp.tv:80/x/MYSECRETKEY
</code></pre>

<p>Periscope complains:
<a href="https://i.sstatic.net/FRoEl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FRoEl.png" alt="screen shot"></a></p>

<p><strong>Please advice how to limit aac audio bitrate so it fits under 160kbps?</strong></p>

<p>ffmpeg displays this while running:</p>

<pre><code>Input #0, lavfi, from 'testsrc=rate=30:size=960x540,format=yuv420p':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn, 30 tbc
Input #1, lavfi, from 'sine=frequency=440:sample_rate=44100:beep_factor=4':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
  Stream #0:0 -&gt; #0:0 (rawvideo (native) -&gt; h264 (libx264))
  Stream #1:0 -&gt; #0:1 (pcm_s16le (native) -&gt; aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fcd5b050800] using SAR=1/1
[libx264 @ 0x7fcd5b050800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fcd5b050800] profile High, level 3.1
[libx264 @ 0x7fcd5b050800] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=26.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=600 vbv_bufsize=2400 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://de.pscp.tv:80/x/MYSECRETKEY':
  Metadata:
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p(progressive), 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 600 kb/s, 30 fps, 1k tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 600000/0/600000 buffer size: 2400000 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, mono, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.89.100 aac
frame= 8146 fps=156 q=32.0 size=   10323kB time=00:04:29.93 bitrate= 313.3kbits/s speed=5.17x  
</code></pre>

<hr>

<p><strong>[SOLVED]</strong> My fault: missed the <a href="https://ffmpeg.org/ffmpeg.html#Advanced-options" rel="nofollow noreferrer">-re</a> flag that would limit speed of reading the generators at a speed of playback. My ffmpeg was streaming data to Periscope much faster than the playback, thus exceeding the bitrate limits. Following is the working code:</p>

<pre><code>ffmpeg \
    -re \
    -f lavfi \
    -i testsrc=rate=30:size=960x540,format=yuv420p \
    -re \
    -f lavfi \
    -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 22 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 2400k \
        -g 60 \
    -c:a aac \
        -ac 2 \
        -b:a 96k \
        -maxrate:a 96k \
        -bufsize:a 192k \
    -f flv \
    -flvflags no_duration_filesize \
    -y  -hide_banner \
    rtmp://de.pscp.tv:80/x/MYSECRETCODE
</code></pre>

CC BY-SA 3.0
2017-10-05T09:45:39.793Z
Your total bitrate in that execution is 313 kbps, so audio can't be 475 kbps. Save to FLV file and check.
Gyan
CC BY-SA 3.0
2017-10-05T09:55:02.553Z
I see that too and I'm completely lost: why does Periscope show those irrelevant high bps numbers?  Periscope bug?
Serge
CC BY-SA 3.0
2017-10-05T15:16:03.400Z
[SOLVED] My fault: missed the `-re` flag that would limit speed of reading the generators at a speed of playback. My ffmpeg was streaming data to Periscope much faster than the playback, thus exceeding the bitrate limits.
Serge
CC BY-SA 3.0
2017-10-05T15:19:04.797Z
Interesting. Strange that Periscope does not check incoming timestamps for this.
Gyan
<ffmpeg><bitrate>
ffmpeg live streaming to Periscope: bitrate appears too high
Serge
# ffmpeg live streaming to Periscope: bitrate appears too high

(Asked by: username_0 on 2017-10-05)

I just noticed Periscope Producer capability to accept live streaming from external sources. 
A quick test with ffmpeg fails to fit bitrate requirements of 160kbps max for audio. Periscope says my audio bitrate is "475.243 kbps", while allowd max is 160kbps. 
"testsrc" creates a test pattern video and "sine" filter generates a 440Hz tone with beeps. I tried various settings to limit video and audio bitrate, but none seems to work. Here's the latest test:
ffmpeg -f lavfi -i testsrc=rate=30:size=960x540,format=yuv420p \
    -f lavfi -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 26 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 1400k \
        -bt:v 100k \
        -g 60 \
        -b:v 600k \
    -c:a aac \
        -bt:a 10k \
        -b:a  128k \
        -y  -hide_banner \
    -f flv \
    -flvflags no_duration_filesize \
    rtmp://de.pscp.tv:80/x/MYSECRETKEY

Periscope complains:

Please advice how to limit aac audio bitrate so it fits under 160kbps?
ffmpeg displays this while running:
Input #0, lavfi, from 'testsrc=rate=30:size=960x540,format=yuv420p':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn, 30 tbc
Input #1, lavfi, from 'sine=frequency=440:sample_rate=44100:beep_factor=4':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7fcd5b050800] using SAR=1/1
[libx264 @ 0x7fcd5b050800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fcd5b050800] profile High, level 3.1
[libx264 @ 0x7fcd5b050800] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=60 keyint_min=6 scenecut=0 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=26.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=600 vbv_bufsize=2400 crf_max=0.0 nal_hrd=none filler=0 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://de.pscp.tv:80/x/MYSECRETKEY':
  Metadata:
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p(progressive), 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 600 kb/s, 30 fps, 1k tbn, 30 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 600000/0/600000 buffer size: 2400000 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, mono, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.89.100 aac
frame= 8146 fps=156 q=32.0 size=   10323kB time=00:04:29.93 bitrate= 313.3kbits/s speed=5.17x  


[SOLVED] My fault: missed the -re flag that would limit speed of reading the generators at a speed of playback. My ffmpeg was streaming data to Periscope much faster than the playback, thus exceeding the bitrate limits. Following is the working code:
ffmpeg \
    -re \
    -f lavfi \
    -i testsrc=rate=30:size=960x540,format=yuv420p \
    -re \
    -f lavfi \
    -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 22 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 2400k \
        -g 60 \
    -c:a aac \
        -ac 2 \
        -b:a 96k \
        -maxrate:a 96k \
        -bufsize:a 192k \
    -f flv \
    -flvflags no_duration_filesize \
    -y  -hide_banner \
    rtmp://de.pscp.tv:80/x/MYSECRETCODE

**Tags:** ffmpeg, bitrate

> **Comments:**
> **username_1**: Your total bitrate in that execution is 313 kbps, so audio can't be 475 kbps. Save to FLV file and check.  
> **username_0**: I see that too and I'm completely lost: why does Periscope show those irrelevant high bps numbers?  Periscope bug?  
> **username_0**: [SOLVED] My fault: missed the `-re` flag that would limit speed of reading the generators at a speed of playback. My ffmpeg was streaming data to Periscope much faster than the playback, thus exceeding the bitrate limits.  
> **username_1**: Interesting. Strange that Periscope does not check incoming timestamps for this.  

---

## 2 answers

### Answer by username_0 on 2017-10-06. Score: 1

I missed the -re flag that would limit speed of reading the generators at a speed of playback.
My ffmpeg was streaming data to Periscope as fast as it can, much faster than a live stream would, thus exceeding the bitrate limits.
Working code, that will stream a test table with a timecode running on top of it to Periscope:
ffmpeg \
    -re \
    -f lavfi \
    -i testsrc=rate=30:size=960x540,format=yuv420p \
    -re \
    -f lavfi \
    -i "sine=frequency=440:sample_rate=44100:beep_factor=4" \
    -vf "
  drawtext
    =fontfile='/Library/Fonts/MyriadPro-Regular.otf'
    :fontcolor='#ff6600'
    :fontsize=64
    :text='%{pts}'
    :x='w/2 - text_w/2'
    :y='h/2 - text_h/2'
" \
    -c:v libx264 \
        -crf:v 22 \
        -preset:v fast \
        -pix_fmt yuv420p \
        -x264opts keyint=60:no-scenecut=1 \
        -maxrate:v 600k \
        -bufsize:v 2400k \
        -g 60 \
    -c:a aac \
        -ac 2 \
        -b:a 96k \
        -maxrate:a 96k \
        -bufsize:a 192k \
    -f flv \
    -flvflags no_duration_filesize \
    -y  -hide_banner \
    rtmp://de.pscp.tv:80/x/MYSECRETCODE


---

### Answer by username_2 on 2017-10-05. Score: 1

You can use option `-ab`, like `-ab 32000` for 32kbit/s bitrate audio. But here may be problem: not all codecs (encoders) can support so small bitrate. For example, libaacplus can do even smaller, but it was removed from ffmpeg.

You can use options `-qmix` and `-qmax` for define video quality. Try something like `-qmin 32 -qmax 64`. Also, check `-bufsize`, you set it to 1400k.

> **Comments:**
> **username_0**: Thanks! I tried `-ab 128k` with no improvement: my ffmpeg lists 323kbps, Periscope goes crazy with 591kbps sound bitrate. `qmin/qmax` are video options. Somehow video bitrate is okay for P.   Setting bufsize doesn't seem to affect "periscope bitrate".  
> **username_2**: try very low values like -ab 32000 -qmin 50 -qmax 64  
> **username_0**: I already found the cause of error: missed the `-re` option. Without it my ffmpeg was streaming content as fast as it could: ahead of "live" time.  

---

