PK rounds: stick matchgop on a stable origin canvas; never copy-recover HEVC.
Browse filesSize changes pad into the first canvas so YouTube does not get a new SPS. Stall 12 unchanged. Not default 720.
- relay.py +9 -4
- youtube_manager.py +2 -3
relay.py
CHANGED
|
@@ -214,6 +214,8 @@ class Sender:
|
|
| 214 |
return False
|
| 215 |
cand=self.current_candidate or {}
|
| 216 |
blob=(str(cand.get('codec') or '')+' '+str(cand.get('label') or '')+' '+str(cand.get('brief') or '')).lower()
|
|
|
|
|
|
|
| 217 |
return any(k in blob for k in ('h264','avc'))
|
| 218 |
def request_sticky(self, mode, user, reason):
|
| 219 |
"""Per-broadcaster: stick LIGHT/matchgop and end this FFmpeg only — not the Space."""
|
|
@@ -224,6 +226,7 @@ class Sender:
|
|
| 224 |
self.sticky_mode=mode
|
| 225 |
self.sticky_since=time.monotonic()
|
| 226 |
self._recovering_copy=False
|
|
|
|
| 227 |
self.log(user, '[HEALTH] %s — sticky %s (this publisher only)'%(reason[:160], mode))
|
| 228 |
sess=self.session
|
| 229 |
if isinstance(sess, dict):
|
|
@@ -373,11 +376,13 @@ class Sender:
|
|
| 373 |
video=['-c:v','copy']
|
| 374 |
else:
|
| 375 |
if mode=='matchgop':
|
| 376 |
-
# Same-size closed GOP ~2s: YouTube buffers on open/8s copy (gopSizeLong / noData).
|
| 377 |
-
# Do NOT squash to 720 unless flap/HEVC policy asked for a constant canvas.
|
| 378 |
w=int((candidate or {}).get('width') or 0); h=int((candidate or {}).get('height') or 0)
|
| 379 |
-
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
else:
|
| 382 |
vf='scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1,format=yuv420p'
|
| 383 |
bitrate=os.getenv('VIDEO_BITRATE','').strip() or '4500k'
|
|
|
|
| 214 |
return False
|
| 215 |
cand=self.current_candidate or {}
|
| 216 |
blob=(str(cand.get('codec') or '')+' '+str(cand.get('label') or '')+' '+str(cand.get('brief') or '')).lower()
|
| 217 |
+
if any(k in blob for k in ('hevc','h265','hvc1')):
|
| 218 |
+
return False
|
| 219 |
return any(k in blob for k in ('h264','avc'))
|
| 220 |
def request_sticky(self, mode, user, reason):
|
| 221 |
"""Per-broadcaster: stick LIGHT/matchgop and end this FFmpeg only — not the Space."""
|
|
|
|
| 226 |
self.sticky_mode=mode
|
| 227 |
self.sticky_since=time.monotonic()
|
| 228 |
self._recovering_copy=False
|
| 229 |
+
self._gop_w=0; self._gop_h=0
|
| 230 |
self.log(user, '[HEALTH] %s — sticky %s (this publisher only)'%(reason[:160], mode))
|
| 231 |
sess=self.session
|
| 232 |
if isinstance(sess, dict):
|
|
|
|
| 376 |
video=['-c:v','copy']
|
| 377 |
else:
|
| 378 |
if mode=='matchgop':
|
|
|
|
|
|
|
| 379 |
w=int((candidate or {}).get('width') or 0); h=int((candidate or {}).get('height') or 0)
|
| 380 |
+
w,h=w-w%2,h-h%2
|
| 381 |
+
if not getattr(self,'_gop_w',0) and w>=16 and h>=16:
|
| 382 |
+
self._gop_w,self._gop_h=w,h
|
| 383 |
+
cw,ch=int(getattr(self,'_gop_w',0) or w), int(getattr(self,'_gop_h',0) or h)
|
| 384 |
+
if cw>=16 and ch>=16:
|
| 385 |
+
vf=self.canvas(cw,ch)
|
| 386 |
else:
|
| 387 |
vf='scale=trunc(iw/2)*2:trunc(ih/2)*2,setsar=1,format=yuv420p'
|
| 388 |
bitrate=os.getenv('VIDEO_BITRATE','').strip() or '4500k'
|
youtube_manager.py
CHANGED
|
@@ -885,10 +885,9 @@ class ManagedYouTube:
|
|
| 885 |
self.retry[user]=self.retry_min
|
| 886 |
break
|
| 887 |
except FormatChanged:
|
| 888 |
-
# Source resolution/layout changed (PK round started or ended, app
|
| 889 |
-
# resumed). Reconnect straight away so YouTube re-detects the new size.
|
| 890 |
sender.note_format_change()
|
| 891 |
-
|
|
|
|
| 892 |
restart_at=time.monotonic();sent=True;break
|
| 893 |
except Exception as e:
|
| 894 |
self.log(user,'تعثر إرسال الفيديو؛ نفس الحدث سيُستخدم — '+self.safe_error(e)[:160])
|
|
|
|
| 885 |
self.retry[user]=self.retry_min
|
| 886 |
break
|
| 887 |
except FormatChanged:
|
|
|
|
|
|
|
| 888 |
sender.note_format_change()
|
| 889 |
+
sender.request_sticky('matchgop', user, 'PK/layout size change — keep YouTube canvas')
|
| 890 |
+
self.log(user,'تغيرت أبعاد المصدر (جولة PK)؛ نثبت matchgop على نفس حدث يوتيوب')
|
| 891 |
restart_at=time.monotonic();sent=True;break
|
| 892 |
except Exception as e:
|
| 893 |
self.log(user,'تعثر إرسال الفيديو؛ نفس الحدث سيُستخدم — '+self.safe_error(e)[:160])
|