1

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: screen shot

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
  • Your total bitrate in that execution is 313 kbps, so audio can't be 475 kbps. Save to FLV file and check. – Gyan Oct 5 '17 at 9:45
  • I see that too and I'm completely lost: why does Periscope show those irrelevant high bps numbers? Periscope bug? – Serge Oct 5 '17 at 9:55
  • [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 Oct 5 '17 at 15:16
  • Interesting. Strange that Periscope does not check incoming timestamps for this. – Gyan Oct 5 '17 at 15:19
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.

  • 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 Oct 5 '17 at 14:58
  • try very low values like -ab 32000 -qmin 50 -qmax 64 – bukkojot Oct 6 '17 at 7:05
  • 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 Oct 6 '17 at 8:31
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.