hldh214 / recorder

stream recorder && automatic upload
https://youtu.be/Yw8OxtN28hQ
MIT License
6 stars 1 forks source link

Stream `reinit` issue #6

Closed hldh214 closed 1 year ago

hldh214 commented 2 years ago

Need detect Reinit context message and restart recorder thread due to the stream's resolution change.

hldh214@DESKTOP-N2TM6A2 MINGW64 ~/Videos
$ ffmpeg -loglevel verbose -y -hide_banner -i "https://bd.flv.huya.com/huyalive/518051590-518051590-2225014636690800640-1036226636-10057-A-0-1.flv?wsSecret=801370fe841889dbd1cc8d8b9f7034e6&wsTime=6225f0c6&seqid=1647085303043&ctype=tars_mobile&ver=1&txyp=o%3Ac12%3B&fs=bgct&t=103&uid=518051590&uuid=234526471&t=103&sv=2110211124" test-bitrate-change.mp4
[tcp @ 0000027ff6c59880] Starting connection attempt to 127.0.0.1 port 7890
[tcp @ 0000027ff6c59880] Successfully connected to 127.0.0.1 port 7890
[h264 @ 0000027ff6ca07c0] Reinit context to 1920x1088, pix_fmt: yuv420p
Input #0, flv, from 'https://bd.flv.huya.com/huyalive/518051590-518051590-2225014636690800640-1036226636-10057-A-0-1.flv?wsSecret=801370fe841889dbd1cc8d8b9f7034e6&wsTime=6225f0c6&seqid=1647085303043&ctype=tars_mobile&ver=1&txyp=o%3Ac12%3B&fs=bgct&t=103&uid=518051590&uuid=234526471&t=103&sv=2110211124':
  Metadata:
    authors         : bce.baidu.com
    codecname       : h264
    displayHeight   : 1080
    displayWidth    : 1920
    mau             : bd
    server          : LSS
    cdn_ip          : 58.216.2.84
    server_version  : 2.0.209/1645135925746
    cascadeID       : /[22686][7478]/[13485][390017]/[11657][5183870]/[11657][5183869]/[27910][5097427]/[27910][5097425]/[4113][18803196]/[4113][18818987]/[30744][18950276]/[30744][18950274]
    cascadeTs       : /1646574082978/1646574082978/1646574082842/1646574082842/1646574083135/1646574087105/1646574086500/1646574087273
  Duration: N/A, start: 8521.307000, bitrate: 4096 kb/s
  Stream #0:0: Subtitle: text
  Stream #0:1: Video: h264 (High), 1 reference frame, yuv420p(progressive), 1920x1080 (1920x1088), 4096 kb/s, 24 fps, 24 tbr, 1k tbn
  Stream #0:2: Audio: aac (LC), 44100 Hz, stereo, fltp
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:2 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0000027ff73500c0] Reinit context to 1920x1088, pix_fmt: yuv420p
[graph_1_in_0_2 @ 0000027ff752d700] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
[graph 0 input from stream 0:1 @ 0000027ff770b680] w:1920 h:1080 pixfmt:yuv420p tb:1/1000 fr:24/1 sar:0/1
[libx264 @ 0000027ff6c9f1c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000027ff6c9f1c0] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0000027ff6c9f1c0] 264 - core 161 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 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=9 lookahead_threads=1 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=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test-bitrate-change.mp4':
  Metadata:
    authors         : bce.baidu.com
    codecname       : h264
    displayHeight   : 1080
    displayWidth    : 1920
    mau             : bd
    server          : LSS
    cdn_ip          : 58.216.2.84
    server_version  : 2.0.209/1645135925746
    cascadeID       : /[22686][7478]/[13485][390017]/[11657][5183870]/[11657][5183869]/[27910][5097427]/[27910][5097425]/[4113][18803196]/[4113][18818987]/[30744][18950276]/[30744][18950274]
    cascadeTs       : /1646574082978/1646574082978/1646574082842/1646574082842/1646574083135/1646574087105/1646574086500/1646574087273
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264, 1 reference frame (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 (0x0), q=2-31, 24 fps, 12288 tbn
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
    Metadata:
      encoder         : Lavc58.134.100 aac
[h264 @ 0000027ff6f80140] Reinit context to 960x544, pix_fmt: yuv420p196.5kbits/s speed=1.65x
[graph 0 input from stream 0:1 @ 0000027ff8ba2c80] w:960 h:540 pixfmt:yuv420p tb:1/1000 fr:24/1 sar:0/1
[scaler_out_0_0 @ 0000027ff8ba3d80] w:1920 h:1080 flags:'bicubic' interl:0
[scaler_out_0_0 @ 0000027ff8ba3d80] w:960 h:540 fmt:yuv420p sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x4
*** 29 dup!
*** 1 dup!2 fps= 33 q=28.0 size=    2048kB time=00:00:13.31 bitrate=1259.7kbits/s dup=29 drop=0 speed= 1.4x
    Last message repeated 11 times
*** 1 dup!7 fps= 34 q=28.0 size=    2304kB time=00:00:14.75 bitrate=1278.9kbits/s dup=41 drop=0 speed=1.46x
    Last message repeated 3 times
*** 1 dup!9 fps= 34 q=28.0 size=    2304kB time=00:00:15.23 bitrate=1238.6kbits/s dup=45 drop=0 speed=1.43x
    Last message repeated 3 times
*** 1 dup!2 fps= 33 q=28.0 size=    2304kB time=00:00:15.84 bitrate=1190.9kbits/s dup=49 drop=0 speed=1.41x
    Last message repeated 4 times
*** 1 dup!6 fps= 33 q=28.0 size=    2560kB time=00:00:16.35 bitrate=1282.0kbits/s dup=54 drop=0 speed=1.39x
    Last message repeated 3 times
*** 1 dup!8 fps= 33 q=28.0 size=    2560kB time=00:00:16.86 bitrate=1243.2kbits/s dup=58 drop=0 speed=1.38x
    Last message repeated 3 times
*** 1 dup!1 fps= 32 q=28.0 size=    2560kB time=00:00:17.44 bitrate=1201.9kbits/s dup=62 drop=0 speed=1.36x
    Last message repeated 4 times
*** 1 dup!5 fps= 32 q=28.0 size=    2816kB time=00:00:18.00 bitrate=1281.0kbits/s dup=67 drop=0 speed=1.35x
    Last message repeated 3 times
*** 1 dup!7 fps= 32 q=28.0 size=    2816kB time=00:00:18.49 bitrate=1247.0kbits/s dup=71 drop=0 speed=1.34x
    Last message repeated 3 times
*** 1 dup!9 fps= 31 q=28.0 size=    2816kB time=00:00:19.00 bitrate=1213.6kbits/s dup=75 drop=0 speed=1.33x
    Last message repeated 5 times
*** 1 dup!8 fps= 32 q=28.0 size=    3072kB time=00:00:19.81 bitrate=1269.8kbits/s dup=81 drop=0 speed=1.34x
    Last message repeated 4 times
*** 1 dup!2 fps= 31 q=28.0 size=    3072kB time=00:00:20.37 bitrate=1234.9kbits/s dup=86 drop=0 speed=1.32x
    Last message repeated 3 times
*** 1 dup!4 fps= 31 q=28.0 size=    3072kB time=00:00:20.85 bitrate=1206.5kbits/s dup=90 drop=0 speed=1.31x
    Last message repeated 3 times
*** 1 dup!7 fps= 31 q=28.0 size=    3328kB time=00:00:21.41 bitrate=1272.9kbits/s dup=94 drop=0 speed= 1.3x
    Last message repeated 3 times
*** 1 dup!8 fps= 31 q=28.0 size=    3328kB time=00:00:21.85 bitrate=1247.2kbits/s dup=98 drop=0 speed=1.29x
    Last message repeated 3 times
*** 1 dup!1 fps= 30 q=28.0 size=    3328kB time=00:00:22.41 bitrate=1216.1kbits/s dup=102 drop=0 speed=1.28x
    Last message repeated 4 times
*** 1 dup!5 fps= 30 q=28.0 size=    3584kB time=00:00:22.99 bitrate=1276.6kbits/s dup=107 drop=0 speed=1.27x
    Last message repeated 3 times
*** 1 dup!8 fps= 30 q=28.0 size=    3584kB time=00:00:23.55 bitrate=1246.3kbits/s dup=111 drop=0 speed=1.27x
    Last message repeated 3 times
[h264 @ 0000027ff6f83800] Reinit context to 1920x1088, pix_fmt: yuv420p
*** 1 dup!0 fps= 28 q=28.0 size=    3584kB time=00:00:25.10 bitrate=1169.3kbits/s dup=115 drop=0 speed=1.25x
    Last message repeated 2 times
[graph 0 input from stream 0:1 @ 0000027ff8ba3880] w:1920 h:1080 pixfmt:yuv420p tb:1/1000 fr:24/1 sar:0/1
[scaler_out_0_0 @ 0000027ff8ba2c80] w:1920 h:1080 flags:'bicubic' interl:0
[scaler_out_0_0 @ 0000027ff8ba2c80] w:1920 h:1080 fmt:yuv420p sar:0/1 -> w:1920 h:1080 fmt:yuv420p sar:0/1 flags:0x4
*** 26 dup!
frame= 1507 fps= 26 q=-1.0 Lsize=   14694kB time=00:01:02.97 bitrate=1911.3kbits/s dup=144 drop=0 speed= 1.1x
video:14615kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.431495%
Input file #0 (https://bd.flv.huya.com/huyalive/518051590-518051590-2225014636690800640-1036226636-10057-A-0-1.flv?wsSecret=801370fe841889dbd1cc8d8b9f7034e6&wsTime=6225f0c6&seqid=1647085303043&ctype=tars_mobile&ver=1&txyp=o%3Ac12%3B&fs=bgct&t=103&uid=518051590&uuid=234526471&t=103&sv=2110211124):
  Input stream #0:0 (subtitle): 1 packets read (601 bytes);
  Input stream #0:1 (video): 1369 packets read (25982407 bytes); 1364 frames decoded;
  Input stream #0:2 (audio): 2713 packets read (1007931 bytes); 2713 frames decoded (2778112 samples);
  Total: 4083 packets (26990939 bytes) demuxed
Output file #0 (test-bitrate-change.mp4):
  Output stream #0:0 (video): 1507 frames encoded; 1507 packets muxed (14965372 bytes);
  Output stream #0:1 (audio): 2713 frames encoded (2778112 samples); 2714 packets muxed (16482 bytes);
  Total: 4221 packets (14981854 bytes) muxed
[AVIOContext @ 0000027ff7134640] Statistics: 2 seeks, 61 writeouts
[libx264 @ 0000027ff6c9f1c0] frame I:7     Avg QP:15.53  size: 54570
[libx264 @ 0000027ff6c9f1c0] frame P:382   Avg QP:18.64  size: 20133
[libx264 @ 0000027ff6c9f1c0] frame B:1118  Avg QP:22.10  size:  6165
[libx264 @ 0000027ff6c9f1c0] consecutive B-frames:  0.9%  0.4%  0.2% 98.5%
[libx264 @ 0000027ff6c9f1c0] mb I  I16..4: 33.1% 58.1%  8.8%
[libx264 @ 0000027ff6c9f1c0] mb P  I16..4:  4.2%  8.1%  0.3%  P16..4: 32.9%  6.7%  3.5%  0.0%  0.0%    skip:44.4%
[libx264 @ 0000027ff6c9f1c0] mb B  I16..4:  0.3%  0.9%  0.0%  B16..8: 25.1%  0.9%  0.1%  direct: 2.2%  skip:70.4%  L0:48.5% L1:50.0% BI: 1.5%
[libx264 @ 0000027ff6c9f1c0] 8x8 transform intra:65.9% inter:75.5%
[libx264 @ 0000027ff6c9f1c0] coded y,uvDC,uvAC intra: 33.8% 17.3% 2.3% inter: 6.2% 5.1% 0.0%
[libx264 @ 0000027ff6c9f1c0] i16 v,h,dc,p: 16% 30% 14% 39%
[libx264 @ 0000027ff6c9f1c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 15% 49%  3%  3%  3%  3%  2%  3%
[libx264 @ 0000027ff6c9f1c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 20% 26%  4%  5%  7%  4%  3%  3%
[libx264 @ 0000027ff6c9f1c0] i8c dc,h,v,p: 67% 14% 16%  3%
[libx264 @ 0000027ff6c9f1c0] Weighted P-Frames: Y:0.3% UV:0.3%
[libx264 @ 0000027ff6c9f1c0] ref P L0: 56.6%  7.2% 26.4%  9.8%  0.0%
[libx264 @ 0000027ff6c9f1c0] ref B L0: 82.0% 14.6%  3.4%
[libx264 @ 0000027ff6c9f1c0] ref B L1: 94.5%  5.5%
[libx264 @ 0000027ff6c9f1c0] kb/s:1906.58
[aac @ 0000027ff7134040] Qavg: 65536.000
[AVIOContext @ 0000027ff6c6e300] Statistics: 27086641 bytes read, 0 seeks

hldh214@DESKTOP-N2TM6A2 MINGW64 ~/Videos
$
hldh214 commented 2 years ago

Plus, we need a config for high-end user to use custom codec for ffmpeg command instead of -c copy

hldh214 commented 1 year ago

Added a checklist for error detection in 0e9b2413e74fc6a67e2526cd9e8657d0a9265d1d