Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit c5075df

Browse files
committed
video_codec: default define by dict
This helps transition to H.265 without user needing to think about it
1 parent caf30fb commit c5075df

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ DirectShow didn't seem to work on Windows, so we used gdigrab instead.
279279

280280
* [YouTube Live parameters](https://support.google.com/youtube/answer/2853702)
281281
* [Facebook Live parameters](https://www.facebook.com/business/help/162540111070395)
282+
* [Owncast parameters](https://owncast.online/docs/codecs/)
282283
* [IBM Cloud Video parameters](https://support.video.ibm.com/hc/en-us/articles/207852117-Internet-connection-and-recommended-encoding-settings)
283284
* [Vimeo](https://help.vimeo.com/hc/en-us/articles/12426924775953-Encoder-guide)
284285

src/pylivestream/data/pylivestream.json

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"audio_rate": 44100,
88
"audio_bps": 128000,
99
"preset": "veryfast",
10-
"video_codec": "libx264",
1110
"audio_codec": "aac",
1211
"exe": "ffmpeg",
1312
"ffprobe_exe": "ffprobe",

src/pylivestream/stream.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@
2323
FPS: float = 30.0 # default frames/sec if not defined otherwise
2424

2525

26+
def get_video_codec(site: str) -> str:
27+
"""
28+
Get the suggested video codec for a given site.
29+
30+
YouTube: https://support.google.com/youtube/answer/2853702
31+
Facebook: https://www.facebook.com/business/help/162540111070395
32+
Owncast: https://owncast.online/docs/codecs/
33+
Twitch: https://www.facebook.com/business/help/162540111070395
34+
Vimeo: https://help.vimeo.com/hc/en-us/articles/12426924775953-Encoder-guide
35+
"""
36+
37+
video_codecs = {
38+
"youtube": "libx265",
39+
"facebook": "libx264",
40+
"owncast": "libx264",
41+
"twitch": "libx264",
42+
"vimeo": "libx264",
43+
"default": "libx264",
44+
}
45+
46+
return video_codecs.get(site, video_codecs["default"])
47+
48+
2649
# %% top level
2750
class Stream:
2851
def __init__(self, inifn: Path, site: str, **kwargs):
@@ -116,7 +139,7 @@ def osparam(self, fn: Path) -> None:
116139
self.hcam: str = syscfg.get("hcam")
117140

118141
# H.265 suggested by YouTube, but not yet by Facebook.
119-
self.video_codec = C.get("video_codec", "libx264")
142+
self.video_codec = C.get("video_codec", get_video_codec(self.site))
120143

121144
self.audio_codec = C.get("audio_codec")
122145
self.video_format = syscfg.get("video_format")

0 commit comments

Comments
 (0)