Keylost / jetson-ffmpeg

ffmpeg support on nvidia jetson
Other
78 stars 26 forks source link

Max bitrate dosen't work #5

Open YannickPerret opened 1 year ago

YannickPerret commented 1 year ago

hello @Keylost I'm trying to stream on twitch sending a 6000k bitrate (maxrate), but the codec doesn't seem to take my settings into account. I end up with a bitrate of 10'000k and twitch crashes because I send it too much bitrate. Do you have any idea why?

logs :

● BeyondStream.service - BeyondSpeedRuns Loaded: loaded (/etc/systemd/system/BeyondStream.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2023-05-25 18:59:37 CEST; 2min 30s ago Main PID: 12147 (node) Tasks: 48 (limit: 4181) CGroup: /system.slice/BeyondStream.service ├─12147 /home/tchoune/.nvm/versions/node/v16.20.0/bin/node /home/tchoune/Twitch/Speedrun/server.js └─12193 ffmpeg -nostdin -f concat -safe 0 -i concat:playlist.txt|control.txt -i images/logo.png -filter_complex [0:v]scale=1920:-1,fps=60[video]; [1:v]scale=200:-1[logo]; [video][logo]overlay=W

Mai 25 19:02:03 tchoune-desktop node[12147]: Video stderr: frame=17252 fps=120 q=-0.0 size= 280988kB time=00:04:47.64 bitrate=8002.3kbits/s speed= 2x Mai 25 19:02:04 tchoune-desktop node[12147]: Video stderr: frame=17311 fps=120 q=-0.0 size= 282092kB time=00:04:48.57 bitrate=8007.9kbits/s speed= 2x Mai 25 19:02:04 tchoune-desktop node[12147]: Video stderr: frame=17370 fps=120 q=-0.0 size= 283079kB time=00:04:49.50 bitrate=8010.1kbits/s speed= 2x Mai 25 19:02:05 tchoune-desktop node[12147]: Video stderr: frame=17435 fps=120 q=-0.0 size= 284108kB time=00:04:50.56 bitrate=8009.9kbits/s speed= 2x Mai 25 19:02:05 tchoune-desktop node[12147]: Video stderr: frame=17499 fps=120 q=-0.0 size= 285082kB time=00:04:51.63 bitrate=8008.0kbits/s speed= 2x Mai 25 19:02:06 tchoune-desktop node[12147]: Video stderr: frame=17555 fps=120 q=-0.0 size= 286108kB time=00:04:52.56 bitrate=8011.1kbits/s speed= 2x Mai 25 19:02:06 tchoune-desktop node[12147]: Video stderr: frame=17611 fps=120 q=-0.0 size= 287427kB time=00:04:53.50 bitrate=8022.5kbits/s speed= 2x Mai 25 19:02:07 tchoune-desktop node[12147]: Video stderr: frame=17671 fps=120 q=-0.0 size= 288588kB time=00:04:54.61 bitrate=8024.4kbits/s speed= 2x Mai 25 19:02:07 tchoune-desktop node[12147]: Video stderr: frame=17737 fps=120 q=-0.0 size= 289672kB time=00:04:55.60 bitrate=8027.7kbits/s speed= 2x Mai 25 19:02:08 tchoune-desktop node[12147]: Video stderr: frame=17803 fps=120 q=-0.0 size= 290722kB time=00:04:56.70 bitrate=8026.9kbits/s speed= 2x

my command : js ffmpegVideo = spawn('ffmpeg', [ '-nostdin', '-f', 'concat', '-safe', '0', '-i', 'concat:playlist.txt|control.txt', '-i', 'images/logo.png', '-filter_complex', '[0:v]scale=1920:-1,fps=60[video]; [1:v]scale=200:-1[logo]; [video][logo]overlay=W-w-5:5[main]; [main]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:textfile=runne$ '-s', '1920x1080', '-c:v', 'h264_nvmpi', '-pix_fmt', 'yuv420p', '-r', '60', '-g','60', '-b:v', '6000k', '-minrate', '5000k', '-maxrate', '6000k', '-bufsize', '6000k', '-keyint_min', '60', '-preset', 'slow', '-rc', 'vbr', '-acodec', 'aac', '-ac', '2', '-f', 'flv', ]);

Keylost commented 1 year ago

Hi! Try to rebuild the library and ffmpeg with patches from master branch with the latest changes.

YannickPerret commented 1 year ago

Okay greate thanks i will test ! Is it possible to have all the parameters with the name you've configured for your codec?

YannickPerret commented 1 year ago

Hey @Keylost

I just tried with '-rc_max_rate', '-max_rate', '-maxrate', '-maxbitrate', '-max-bitrate' and nothing works. My bitrate increases to more than 10M whereas I blocked it at 6M. Have I set the wrong parameters? i use Patch for ffmpeg6.0 in clean install.

I've tried adding '-rc', 'cbr' it doesn't change the result, would it be possible to implement a constant bitrate mode?

` stderr: ffmpeg version 549430e Copyright (c) 2000-2023 the FFmpeg developers built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) configuration: --enable-nvmpi --enable-libfreetype

stderr: libavutil 58. 2.100 / 58. 2.100 libavcodec 60. 3.100 / 60. 3.100 libavformat 60. 3.100 / 60. 3.100 libavdevice 60. 1.100 / 60. 1.100 libavfilter 9. 3.100 / 9. 3.100 libswscale 7. 1.100 / 7. 1.100 libswresample 4. 10.100 / 4. 10.100

stderr: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x558ecd1ac0] Auto-inserting h264_mp4toannexb bitstream filter

Durée de la vidéo : 2641.618141 stderr: Input #0, concat, from 'concat:playlist.txt|control.txt': Duration: N/A, start: 0.000000, bitrate: 3809 kb/s

stderr: Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 3681 kb/s, 60 fps, 60 tbr, 15360 tbn Metadata: handler_name : ISO Media file produced by Google Inc. vendor_id : [0][0][0][0] Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s Metadata: handler_name : ISO Media file produced by Google Inc. vendor_id : [0][0][0][0]

stderr: Input #1, png_pipe, from 'images/logo.png': Duration: N/A, bitrate: N/A

stderr: Stream #1:0: Video: png, rgba(pc), 4000x3001 [SAR 5669:5669 DAR 4000:3001], 25 fps, 25 tbr, 25 tbn

stderr: Stream mapping: Stream #0:0 (h264) -> scale:default (graph 0) Stream #1:0 (png) -> scale:default (graph 0) drawtext:default (graph 0) stderr: -> Stream #0:0 (h264_nvmpi) Stream #0:1 -> #0:1 (aac (native) -> aac (native))

stderr: NvMMLiteOpen : Block : BlockType = 4

stderr: ===== NVMEDIA: NVENC ===== NvMMLiteBlockCreate : Block : BlockType = 4

stdout: Opening in BLOCKING MODE 875967048 842091865

stderr: H264: Profile = 100, Level = 51

stderr: NVMEDIA_ENC: bBlitMode is set to TRUE

stderr: NvMMLiteOpen : Block : BlockType = 4

stderr: ===== NVMEDIA: NVENC ===== NvMMLiteBlockCreate : Block : BlockType = 4

stdout: Got 0 size buffer in capture Opening in BLOCKING MODE 875967048 842091865

stderr: H264: Profile = 100, Level = 51

stderr: Output #0, flv, to 'rtmp://live.twitch.tv/app/API_key': Metadata: encoder : Lavf60.3.100 Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 5000 kb/s, 60 fps, 1k tbn Metadata: encoder : Lavc60.3.100 h264_nvmpi Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 160 kb/s Metadata:

stderr: handler_name : ISO Media file produced by Google Inc. vendor_id : [0][0][0][0] encoder : Lavc60.3.100 aac

stderr: frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.02 bitrate= 135.4kbits/s speed=0.0371x
stderr: NVMEDIA_ENC: bBlitMode is set to TRUE

stderr: frame= 17 fps= 15 q=-0.0 size= 189kB time=00:00:00.34 bitrate=4440.4kbits/s speed=0.308x
stderr: frame= 64 fps= 39 q=-0.0 size= 1252kB time=00:00:01.11 bitrate=9203.0kbits/s speed=0.683x
stderr: frame= 115 fps= 54 q=-0.0 size= 2428kB time=00:00:01.95 bitrate=10198.7kbits/s speed=0.915x
stderr: frame= 152 fps= 58 q=-0.0 size= 3071kB time=00:00:02.57 bitrate=9761.7kbits/s speed=0.979x
stderr: frame= 182 fps= 58 q=-0.0 size= 3441kB time=00:00:03.06 bitrate=9197.2kbits/s speed=0.978x
stderr: frame= 211 fps= 58 q=-0.0 size= 3966kB time=00:00:03.57 bitrate=9086.6kbits/s speed=0.983x
stderr: frame= 242 fps= 58 q=-0.0 size= 4551kB time=00:00:04.08 bitrate=9122.2kbits/s speed=0.987x
stderr: frame= 272 fps= 58 q=-0.0 size= 5144kB time=00:00:04.57 bitrate=9211.5kbits/s speed=0.984x
stderr: frame= 302 fps= 59 q=-0.0 size= 6142kB time=00:00:05.08 bitrate=9894.0kbits/s speed=0.987x
stderr: frame= 332 fps= 59 q=-0.0 size= 6718kB time=00:00:05.59 bitrate=9834.7kbits/s speed=0.988x
stderr: frame= 363 fps= 59 q=-0.0 size= 7399kB time=00:00:06.08 bitrate=9963.6kbits/s speed=0.987x
stderr: frame= 393 fps= 59 q=-0.0 size= 8052kB time=00:00:06.59 bitrate=10002.4kbits/s speed=0.989x
stderr: frame= 423 fps= 59 q=-0.0 size= 8675kB time=00:00:07.10 bitrate=10001.3kbits/s speed=0.991x
stderr: frame= 454 fps= 59 q=-0.0 size= 9387kB time=00:00:07.61 bitrate=10096.3kbits/s speed=0.992x
stderr: frame= 484 fps= 59 q=-0.0 size= 9888kB time=00:00:08.12 bitrate=9967.2kbits/s speed=0.993x
stderr: frame= 515 fps= 59 q=-0.0 size= 10508kB time=00:00:08.61 bitrate=9992.8kbits/s speed=0.991x
stderr: frame= 544 fps= 59 q=-0.0 size= 11136kB time=00:00:09.12 bitrate=9997.3kbits/s speed=0.993x
stderr: frame= 575 fps= 59 q=-0.0 size= 11862kB time=00:00:09.63 bitrate=10084.5kbits/s speed=0.994x
stderr: frame= 604 fps= 59 q=-0.0 size= 12432kB time=00:00:10.12 bitrate=10059.5kbits/s speed=0.993x
stderr: frame= 636 fps= 59 q=-0.0 size= 13112kB time=00:00:10.63 bitrate=10100.3kbits/s speed=0.993x
stderr: frame= 666 fps= 59 q=-0.0 size= 13757kB time=00:00:11.14 bitrate=10111.5kbits/s speed=0.994x
stderr: frame= 696 fps= 59 q=-0.0 size= 14372kB time=00:00:11.65 bitrate=10100.7kbits/s speed=0.994x
stderr: frame= 727 fps= 59 q=-0.0 size= 15004kB time=00:00:12.16 bitrate=10101.8kbits/s speed=0.995x
stderr: frame= 758 fps= 60 q=-0.0 size= 15660kB time=00:00:12.67 bitrate=10118.5kbits/s speed=0.996x
stderr: frame= 788 fps= 60 q=-0.0 size= 16232kB time=00:00:13.16 bitrate=10100.0kbits/s speed=0.995x
stderr: frame= 817 fps= 59 q=-0.0 size= 16762kB time=00:00:13.67 bitrate=10040.3kbits/s speed=0.995x
stderr: frame= 848 fps= 60 q=-0.0 size= 17368kB time=00:00:14.16 bitrate=10044.8kbits/s speed=0.994x
stderr: frame= 878 fps= 60 q=-0.0 size= 17800kB time=00:00:14.67 bitrate=9936.5kbits/s speed=0.995x
`

my command : ffmpegVideo = spawn('ffmpeg', [ '-nostdin', '-re', '-f', 'concat', '-safe', '0', '-i', 'concat:playlist.txt|control.txt', '-i', 'images/logo.png', '-filter_complex', '[0:v]scale=1920:-1,fps=60[video];[1:v]scale=200:-1[logo];[video][logo]overlay=W-w-5:5[main]; [main]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:te$ '-vcodec', 'h264_nvmpi', '-s', '1920x1080', '-preset', 'slow', '-profile:v', 'high', '-pix_fmt', 'yuv420p', '-b:v', '5M', '-maxrate', '6M', '-bufsize', '8M', '-acodec', 'aac', '-b:a', '160k', '-ac', '2', '-f', 'flv', rtmp://live.twitch.tv/app/${twitchStreamKey} ]);

Keylost commented 1 year ago

Weird, I can't reproduce this issue:( But I have an idea. The nvmpi library ignored the bufsize option. Perhaps this is the reason that the previous fix didn't help. Fixed in the last commit. Try to rebuild ffmpeg and lib.

ffmpeg -i /media/SSD/tmp3.mp4 -c:v h264_nvmpi -pix_fmt yuv420p -s 1920x1080 -profile:v high -level:v 4.2 -rc:v cbr -b:v 5M -bufsize:v 5M -r:v 60 /media/SSD/tmp.flv
ffmpeg version a0d6566 Copyright (c) 2000-2023 the FFmpeg developers
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/media/SSD/tmp3.mp4':
  Duration: 00:00:24.93, start: 0.000000, bitrate: 14180 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 3840x2160, 14178 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvmpi))
Output #0, flv, to '/media/SSD/tmp.flv':
  Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1920x1080, q=2-31, 5000 kb/s, 60 fps, 1k tbn (default)

frame= 1496 fps=100 q=-0.0 Lsize=   14442kB time=00:00:24.91 bitrate=4748.2kbits/s speed=1.66x    
video:14413kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.205368%
Keylost commented 1 year ago

vbr:

ffmpeg -i /media/SSD/tmp3.mp4 -c:v h264_nvmpi -pix_fmt yuv420p -s 1920x1080 -profile:v high -level:v 4.2 -rc:v vbr -b:v 5M -minrate:v 5M -maxrate:v 6M -bufsize:v 5M -r:v 60 /media/SSD/tmp.flv

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/media/SSD/tmp3.mp4':
  Duration: 00:00:24.93, start: 0.000000, bitrate: 14180 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 3840x2160, 14178 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvmpi))
H264: Profile = 100, Level = 42 
Output #0, flv, to '/media/SSD/tmp.flv':
  Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1920x1080, q=2-31, 5000 kb/s, 60 fps, 1k tbn (default)

frame=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speedNVMEDIA_ENC: bBlitMode is set to TRUE 
frame=    7 fps=0.0 q=-0.0 size=      81kB time=00:00:00.11 bitrate=5699.2kbits/s speed=0.1
frame=   59 fps= 49 q=-0.0 size=     512kB time=00:00:00.98 bitrate=4266.8kbits/s speed=0.8
frame=  115 fps= 68 q=-0.0 size=    1024kB time=00:00:01.91 bitrate=4375.9kbits/s speed=1.1
frame=  171 fps= 77 q=-0.0 size=    1280kB time=00:00:02.85 bitrate=3679.2kbits/s speed=1.2
frame=  220 fps= 81 q=-0.0 size=    1792kB time=00:00:03.65 bitrate=4021.9kbits/s speed=1.3
frame=  272 fps= 85 q=-0.0 size=    2304kB time=00:00:04.53 bitrate=4163.8kbits/s speed=1.4
frame=  320 fps= 86 q=-0.0 size=    3072kB time=00:00:05.33 bitrate=4718.9kbits/s speed=1.4
frame=  370 fps= 88 q=-0.0 size=    3584kB time=00:00:06.18 bitrate=4748.5kbits/s speed=1.4
frame=  421 fps= 89 q=-0.0 size=    4096kB time=00:00:07.00 bitrate=4793.5kbits/s speed=1.4
frame=  468 fps= 90 q=-0.0 size=    4608kB time=00:00:07.80 bitrate=4839.6kbits/s speed=1.4
frame=  523 fps= 91 q=-0.0 size=    5120kB time=00:00:08.71 bitrate=4811.6kbits/s speed=1.5
frame=  579 fps= 92 q=-0.0 size=    5632kB time=00:00:09.63 bitrate=4789.5kbits/s speed=1.5
frame=  632 fps= 93 q=-0.0 size=    6400kB time=00:00:10.53 bitrate=4977.6kbits/s speed=1.5
frame=  682 fps= 94 q=-0.0 size=    6912kB time=00:00:11.35 bitrate=4988.8kbits/s speed=1.5
frame=  735 fps= 94 q=-0.0 size=    7680kB time=00:00:12.25 bitrate=5135.9kbits/s speed=1.5
frame=  789 fps= 95 q=-0.0 size=    8192kB time=00:00:13.13 bitrate=5109.9kbits/s speed=1.5
frame=  842 fps= 96 q=-0.0 size=    8704kB time=00:00:14.01 bitrate=5086.9kbits/s speed=1.5
frame=  900 fps= 96 q=-0.0 size=    8960kB time=00:00:14.98 bitrate=4898.9kbits/s speed= 1.
frame=  956 fps= 97 q=-0.0 size=    9728kB time=00:00:15.93 bitrate=5001.7kbits/s speed=1.6
frame= 1010 fps= 98 q=-0.0 size=   10240kB time=00:00:16.83 bitrate=4983.4kbits/s speed=1.6
frame= 1065 fps= 98 q=-0.0 size=   10752kB time=00:00:17.75 bitrate=4962.3kbits/s speed=1.6
frame= 1117 fps= 98 q=-0.0 size=   11264kB time=00:00:18.60 bitrate=4961.0kbits/s speed=1.6
frame= 1173 fps= 99 q=-0.0 size=   11776kB time=00:00:19.53 bitrate=4938.8kbits/s speed=1.6
frame= 1227 fps= 99 q=-0.0 size=   12288kB time=00:00:20.46 bitrate=4918.3kbits/s speed=1.6
frame= 1279 fps= 99 q=-0.0 size=   12800kB time=00:00:21.31 bitrate=4919.0kbits/s speed=1.6
frame= 1336 fps=100 q=-0.0 size=   13568kB time=00:00:22.25 bitrate=4995.5kbits/s speed=1.6
frame= 1392 fps=100 q=-0.0 size=   14080kB time=00:00:23.20 bitrate=4971.7kbits/s speed=1.6
frame= 1450 fps=100 q=-0.0 size=   14336kB time=00:00:24.15 bitrate=4863.0kbits/s speed=1.6
frame= 1496 fps=101 q=-0.0 Lsize=   15180kB time=00:00:24.91 bitrate=4990.6kbits/s speed=1.68x    
video:15150kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.195371%
YannickPerret commented 1 year ago

@Keylost It's still not working. I don't know why I can't get the same result as you. At first I thought it might be my concat system to make a video playlist (720-1080p), but no, with a single input it does the same thing. I tried setting and removing the :v sub-parameter at the different rates, but still the same problem. My fps are stuck at 60, which is good news. I used your example to be consistent.

tchoune@tchoune-desktop:~/Twitch/Speedrun$ ffmpeg -i /mnt/my_usb/zelda/BOTW/AllDungeon.mp4 -c:v h264_nvmpi -pix_fmt yuv420p -s 1920x1080 -profile:v high -level:v 4.2 -rc:v cbr -b:v 6M -minrate:v 5M -maxrate:v 6M -bufsize:v 6M -r:v 60 -acodec aac -b:a 160k -ac 2 -f flv 'rtmp://live.twitch.tv/app/APIKEY
ffmpeg version 549430e Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  configuration: --enable-nvmpi --enable-libfreetype
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/mnt/my_usb/zelda/BOTW/AllDungeon.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2023-04-30T20:01:39.000000Z
  Duration: 01:40:22.75, start: 0.000000, bitrate: 1534 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 1403 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      creation_time   : 2023-04-30T20:01:39.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 04/30/2023.
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2023-04-30T20:01:39.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 04/30/2023.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvmpi))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
875967048
842091865
H264: Profile = 100, Level = 42 
NVMEDIA_ENC: bBlitMode is set to TRUE 
Got 0 size buffer in capture 
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 4 
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4 
875967048
842091865
H264: Profile = 100, Level = 42 
NVMEDIA_ENC: bBlitMode is set to TRUE 
Output #0, flv, to 'rtmp://live.twitch.tv/app/APIKEY':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf60.3.100
  Stream #0:0(und): Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 6000 kb/s, 60 fps, 1k tbn (default)
    Metadata:
      creation_time   : 2023-04-30T20:01:39.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 04/30/2023.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.3.100 h264_nvmpi
  Stream #0:1(und): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
      creation_time   : 2023-04-30T20:01:39.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 04/30/2023.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.3.100 aac
[vost#0:0/h264_nvmpi @ 0x55a45855d0] More than 1000 frames duplicated203.1kbits/s dup=994 drop=0 speed=2.35x    
Got 0 size buffer in capture ze=  265000kB time=00:04:10.31 bitrate=8672.5kbits/s dup=7513 drop=0 speed=2.41x    
[flv @ 0x55a463ad60] Failed to update header with correct duration.
[flv @ 0x55a463ad60] Failed to update header with correct filesize.
frame=15054 fps=145 q=-0.0 Lsize=  265956kB time=00:04:10.88 bitrate=8684.2kbits/s dup=7527 drop=0 speed=2.41x    
video:261085kB audio:4398kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.178439%
[aac @ 0x55a43336d0] Qavg: 8935.576
Exiting normally, received signal 2.

every time, I do a make uninstall and empty my folders in /var/local to be sure, then start again with a freshly compiled installation.

I've also tried again with my nodejs script (which uses exec to run the ffmpeg command) and I'm sending you 2min40 of logs in the pastebin.

my command :

 ffmpegVideo = spawn('ffmpeg', [
                '-nostdin', '-re', '-f', 'concat', '-safe', '0',
                '-i', 'concat:playlist.txt|control.txt',
                '-i', 'images/logo.png',
                '-filter_complex', '[0:v]scale=1920:-1,fps=60[video];[1:v]scale=200:-1[logo];[video][logo]overlay=W-w-5:5[main]; [main]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:te.....
                '-vcodec', 'h264_nvmpi',
                '-pix_fmt', 'yuv420p',
                '-s', '1920x1080',
                '-preset','slow',
                '-rc:v','cbr',
                '-b:v','6M',
                '-minrate:v','6M',
                '-maxrate:v','6M',
                '-bufsize:v','8M',
                '-acodec', 'aac',
                '-b:a', '160k',
                '-ac', '2',
                '-f', 'flv',
                `rtmp://live.twitch.tv/app/${twitchStreamKey}`
            ]);

pastebin : https://pastebin.com/5vRgRn3k

Could this be due to the flv output format? If you need more information, don't hesitate to ask me. It doesn't really take into account minrate, maxrate and the cbr doesn't seem very constant, with 6M bitrate I fluctuate between 5M and 8.5M.

I can suggest that you try your tests with my configuration on the twitch servers. Can you tell me that the problem is with the live... Because the big problem is that if I send more than 6M to Twitch my live is black screen and many lags occur on the stream.

YannickPerret commented 1 year ago

New tested, other paramters same results : https://pastebin.com/hcYmYjDg

Keylost commented 1 year ago

What board are you using? What version of jetpack/l4t? Does it work fine with x264 encoder? Could u try this command? ffmpegVideo = spawn('ffmpeg', [ '-nostdin', '-re', '-f', 'concat', '-safe', '0', '-i', 'concat:playlist.txt|control.txt', '-i', 'images/logo.png', '-filter_complex', '[0:v]scale=1920:-1,fps=60[video];[1:v]scale=200:-1[logo];[video][logo]overlay=W-w-5:5[main]; [main]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:te$ '-c:v', 'h264_nvmpi', '-pix_fmt', 'yuv420p', '-s', '1920x1080', '-profile:v', 'high', '-level:v', '4.2', '-rc:v','vbr', '-b:v','4640k', '-maxrate:v','5800k', '-bufsize:v','4000k', '-c:a', 'aac', '-b:a', '160k', '-ac', '2', '-f', 'flv', rtmp://live.twitch.tv/app/${twitchStreamKey} ]);

YannickPerret commented 1 year ago

i'm using : nVidia Kit de developpment Jetson Nano 4 Go => https://www.digitec.ch/en/s1/product/nvidia-jetson-nano-4gb-development-kit-cortex-a57-development-boards-kits-24227789?supplier=406802

My version is :

tchoune@tchoune-desktop:~$ dpkg-query --show nvidia-l4t-core
nvidia-l4t-core 32.7.3-20221122092935

With jetson I hardly ever use h264lib because my processor quickly goes up to 80-90%, with I'm around h264_nvmpi. But it's true that I've never had so much variation in bitrate when I did my tests on my Mac with h264.

I'm testing your command and back with logs

YannickPerret commented 1 year ago

I've tried your command. It seems to be fine in terms of lags on the stream, but in the logs I'm still going higher than the max authorized bitrate. I'm afraid that over time (I stream 24h) it will rise to over 7000k and the stream will still lag or cut.

here my last pastebin with your command : https://pastebin.com/svAhK9Ye I'm going to leave my stream on for a few hours to see if any lags occur. If you want to see, here's the link https://www.twitch.tv/beyondspeedruns . In the player options, you can see the advanced stream information.

Updating : The bitrate rises much more slowly than before, but I broke 6500k after 30 minutes live, and micro-lagging can be felt at times.

Mai 31 22:48:25 tchoune-desktop node[12409]: stderr: frame=156987 fps= 60 q=-0.0 size= 2088209kB time=00:43:36.43 bitrate=6538.1kbits/s speed= 1x Mai 31 22:48:25 tchoune-desktop node[12409]: stderr: frame=157015 fps= 60 q=-0.0 size= 2088628kB time=00:43:36.90 bitrate=6538.3kbits/s speed= 1x Mai 31 22:48:26 tchoune-desktop node[12409]: stderr: frame=157047 fps= 60 q=-0.0 size= 2089239kB time=00:43:37.53 bitrate=6538.6kbits/s speed= 1x Mai 31 22:48:26 tchoune-desktop node[12409]: stderr: frame=157078 fps= 60 q=-0.0 size= 2089719kB time=00:43:38.00 bitrate=6538.9kbits/s speed= 1x Mai 31 22:48:27 tchoune-desktop node[12409]: stderr: frame=157108 fps= 60 q=-0.0 size= 2090048kB time=00:43:38.46 bitrate=6538.8kbits/s speed= 1x Mai 31 22:48:27 tchoune-desktop node[12409]: stderr: frame=157138 fps= 60 q=-0.0 size= 2090635kB time=00:43:38.98 bitrate=6539.4kbits/s speed= 1x Mai 31 22:48:28 tchoune-desktop node[12409]: stderr: frame=157169 fps= 60 q=-0.0 size= 2091150kB time=00:43:39.46 bitrate=6539.8kbits/s speed= 1x Mai 31 22:48:28 tchoune-desktop node[12409]: stderr: frame=157199 fps= 60 q=-0.0 size= 2091559kB time=00:43:39.96 bitrate=6539.8kbits/s speed= 1x Mai 31 22:48:29 tchoune-desktop node[12409]: stderr: frame=157229 fps= 60 q=-0.0 size= 2092004kB time=00:43:40.46 bitrate=6539.9kbits/s speed= 1x Mai 31 22:48:29 tchoune-desktop node[12409]: stderr: frame=157259 fps= 60 q=-0.0 size= 2092433kB time=00:43:40.96 bitrate=6540.0kbits/s speed= 1x

But for the time being, I have the impression that the log side remains fairly close to 6,500k.

YannickPerret commented 1 year ago

any ideas ? :)

Keylost commented 1 year ago

@YannickPerret Unfortunately, I have no new ideas at the moment. :(