[FFmpeg-user] RTSP to Twitch

Sébastien Bonaimé s.bonaime at gmail.com
Thu Mar 11 12:24:44 EET 2021


I found my solution :

I set my camera to CBR 30 FPS smart codec OFF ad I have an output
bitrate of 3532Kbps

And here is my script

        cbr="3000k" #
        threads="4" #
        probesize="4M"

        ffmpeg      -probesize ${probesize} -hide_banner
-rtsp_transport tcp -thread_queue_size 3000k \
                      -i $url \
                -c:a copy \
                -c:v copy   \
                     -threads ${threads} -strict normal \
                             -bufsize ${cbr} \
                             -f flv $twitch_url


Now, I have 30 FPS  ! Before, I was making tests at night when the
camera was completely in the dark. Thus, with VBR, the FPS was really
low as nothing was moving. Now with CBR I have all the time 30 FPS

Thanks

Le jeu. 11 mars 2021 à 07:37, Sébastien Bonaimé <s.bonaime at gmail.com> a écrit :
>
> Thanks for your advice. Here is my changes :
>
> - changes my camera settings to VBR with 3532kb/s and  30 FPS
> - With VLC, I can see the RTSP stream which is 1920x1080 @29.970030
> FPS with H264 - MPEG-4 AVC (part10) (H264)
>
> -compile ffmpeg on my pi4. Now I have ffmpeg version 4.3.2 Copyright
> (c) 2000-2021 the FFmpeg developers
>   built with gcc 8 (Raspbian 8.3.0-6+rpi1)
>   configuration: --extra-cflags=-I/usr/local/include
> --extra-ldflags=-L/usr/local/lib --extra-libs='-lpthread -lm -latomic'
> --arch=armel --enable-gmp --enable-gpl --enable-libaom --enable-libass
> --enable-libdav1d --enable-libdrm --enable-libfdk-aac
> --enable-libfreetype --enable-libkvazaar --enable-libmp3lame
> --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus
> --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libssh
> --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libzimg
> --enable-libx264 --enable-libxml2 --enable-mmal --enable-nonfree
> --enable-omx --enable-omx-rpi --enable-version3 --target-os=linux
> --enable-pthreads --enable-openssl --enable-hardcoded-tables
>
> - I simplify my ffmpeg command with this one
>         ffmpeg     r  -rtsp_transport tcp -thread_queue_size 3000k \
>                       -i $url \
>                 -vsync 0 -enc_time_base -1 \
>                 -c:a copy \
>                 -c:v copy   \
>                 -f flv $twitch_url
>
>
>
> Now, I have only 11 FPS ! Why  am I not able to reach 30 FPS ?
>
> [rtsp @ 0x1899220] Missing PPS in sprop-parameter-sets, ignoring
> Guessed Channel Layout for Input Stream #0.1 : mono
> Input #0, rtsp, from 'rtsp://view3:my_pass@192.168.1.32:8554/0/av0':
>   Metadata:
>     title           : Session Streamed by LIBZRTSP
>     comment         : 0
>   Duration: N/A, start: 0.000000, bitrate: N/A
>     Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive),
> 1920x1080, 10 fps, 10 tbr, 90k tbn, 180k tbc
>     Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
> Output #0, flv, to 'rtmp://cdg.contribute.live-video.net/app/my_key':
>   Metadata:
>     title           : Session Streamed by LIBZRTSP
>     comment         : 0
>     encoder         : Lavf58.20.100
>     Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007),
> yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 10 fps, 10 tbr,
> 1k tbn, 90k tbc
>     Stream #0:1: Audio: pcm_mulaw ([8][0][0][0] / 0x0008), 8000 Hz,
> mono, s16, 64 kb/s
> Stream mapping:
>   Stream #0:0 -> #0:0 (copy)
>   Stream #0:1 -> #0:1 (copy)
> Press [q] to stop, [?] for help
> [flv @ 0x18b5ee0] Timestamps are unset in a packet for stream 0. This
> is deprecated and will stop working in the future. Fix your code to
> set the timestamps properly
> frame=  684 fps= 11 q=-1.0 size=    8797kB time=00:01:08.40
> bitrate=1053.6kbits/s speed=1.07x
>
> If I turn the rtsp_transport to udp, I still have 11 FPS and I miss
> some packets.
>
> Press [q] to stop, [?] for help
> [flv @ 0x1ecd190] Timestamps are unset in a packet for stream 0. This
> is deprecated and will stop working in the future. Fix your code to
> set the timestamps properly
> [rtsp @ 0x1e70220] max delay reached. need to consume packet
> [rtsp @ 0x1e70220] RTP: missed 31 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume
> packetbitrate=1008.1kbits/s speed=1.14x
> [rtsp @ 0x1e70220] RTP: missed 3 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume packetbitrate=
> 982.2kbits/s speed=1.12x
> [rtsp @ 0x1e70220] RTP: missed 4 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume packet
> [rtsp @ 0x1e70220] RTP: missed 1 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume packetbitrate=
> 993.0kbits/s speed= 1.1x
> [rtsp @ 0x1e70220] RTP: missed 1 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume
> packetbitrate=1004.5kbits/s speed=1.08x
> [rtsp @ 0x1e70220] RTP: missed 7 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume packet
> [rtsp @ 0x1e70220] RTP: missed 1 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume
> packetbitrate=1008.6kbits/s speed=1.07x
> [rtsp @ 0x1e70220] RTP: missed 7 packets
> [rtsp @ 0x1e70220] max delay reached. need to consume
> packetbitrate=1010.3kbits/s speed=1.04x
> [rtsp @ 0x1e70220] RTP: missed 10 packets
> frame=  954 fps= 10 q=-1.0 size=   11858kB time=00:01:35.74
> bitrate=1014.6kbits/s speed=1.04xPress [q] to stop, [?] for help
>
> Thanks
>
> Le mer. 10 mars 2021 à 14:58, Moritz Barsnick <barsnick at gmx.net> a écrit :
> >
> > Hi Sébastien,
> >
> > On Wed, Mar 10, 2021 at 12:55:25 +0100, Sébastien Bonaimé wrote:
> >
> > > included x264 codec are : libx264 libx264rgb h264_omx h264_v4l2m2m h264_vaapi
> >
> > >         ffmpeg  -probesize  10M  -rtsp_transport tcp -thread_queue_size 1000k \
> > >                   -i $url \
> > >                 -vsync 0 -enc_time_base -1 \
> > >                  -bufsize 1024k -preset "$QUAL" \
> > >                 -b:v $CBR  -minrate $CBR -maxrate $CBR   -keyint_min 24 -g 24 \
> > >                 -crf 10  -c:v libx264    \
> > >                 -f flv $twitch_url
> > >
> > > With camera in CBR mode, I can't reach 25 FPS but only 14. And the
> > > stream to twitch does not last more than ew seconds. What can I do to
> > > improve the command ?
> >
> > - Do you really need to reencode for twitch? Does it need CBR?
> >   Otherwise, you could just use the "copy" codec.
> >
> > - AFAIU, you cannot combine "-b:v" and "-crf". I believe (fro mlooking
> >   at your logs) that the latter is being ignored.
> >
> > - CRF 10 is really really low. What are you trying to achieve? Is the
> >   default of CRF 27 not good enough? CRF 10 is bound to take a lot of
> >   additional compute power (if not ignored).
> >
> > - You listed other available encoders. Have you tried any of them? (I
> >   have no experience with HW accel on RaspPi, others may pitch in.)
> >
> > > FFmpeg version is
> > > ffmpeg version 4.1.6-1~deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
> >
> > You should try to get hold of a newer version of ffmpeg. You may have
> > to compile yourself though. A newer version probably won't help with
> > the speed of libx264, but the support for the other HWAccels may have
> > improved.
> >
> > Cheers,
> > Moritz
> > _______________________________________________
> > ffmpeg-user mailing list
> > ffmpeg-user at ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-user mailing list