- commit
- c633dba9a615f926188f748cf36c24895f376e82
- parent
- 4f2084275e9234070beba31b5a8f6dd9ca172f63
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-02-07 12:28
calculate CO₂ intensity of videos
Diffstat
M | dropin.py | 26 | ++++++++++++++++++++++++++ |
M | static/video.js | 2 | +- |
M | templates/video.html | 4 | ++-- |
3 files changed, 29 insertions, 3 deletions
diff --git a/dropin.py b/dropin.py
@@ -62,6 +62,32 @@ def duration(value): 62 62 env.filters['duration'] = duration 63 63 64 64 -1 65 def co2(bytes, green_hosting=0): -1 66 # https://sustainablewebdesign.org/estimating-digital-emissions/ -1 67 -1 68 # kWh/GB -1 69 operational_datacenter = 0.055 -1 70 operational_network = 0.059 -1 71 operational_device = 0.08 -1 72 embodied_datacenter = 0.012 -1 73 embodied_network = 0.013 -1 74 embodied_device = 0.081 -1 75 -1 76 # CO2e/kWh -1 77 grid_intensity = 494 -1 78 -1 79 grams = bytes / 1_000_000_000 * grid_intensity * sum([ -1 80 operational_datacenter * (1 - green_hosting), -1 81 operational_network, -1 82 operational_device, -1 83 embodied_datacenter, -1 84 embodied_network, -1 85 embodied_device, -1 86 ]) -1 87 return f'{grams:.3g}g CO₂' -1 88 env.filters['co2'] = co2 -1 89 -1 90 65 91 def linebreaks(text): 66 92 return Markup('').join( 67 93 Markup('<p>{}</p>').format(
diff --git a/static/video.js b/static/video.js
@@ -35,7 +35,7 @@ var applyQuality = function(quality, lazy) { 35 35 var createMenu = function() { 36 36 var sources = Array.from(video.querySelectorAll('[data-quality]')).reverse(); 37 37 var ul = h('ul', {'class': 'quality'}, sources.map(source => h('li', {}, [38 -1 h('button', {'type': 'button'}, [source.dataset.quality]),-1 38 h('button', {'type': 'button', 'title': source.dataset.co2}, [source.dataset.quality]), 39 39 ]))); 40 40 ul.append(h('li', {}, [ 41 41 h('button', {'type': 'button'}, ['auto']),
diff --git a/templates/video.html b/templates/video.html
@@ -5,8 +5,8 @@ 5 5 {% block content %} 6 6 <div class="relative"> 7 7 <video controls poster="{{ thumbnail.large }}" preload="none" crossorigin="anonymous">8 -1 {% for format, type, quality in FORMATS %}9 -1 <source type="{{ type }}" src="/video/{{ id }}-{{ quality }}.{{ format }}" {% if quality != 'adaptive' %}media="(min-height: {{ quality }}x)" data-quality="{{ quality }}"{% endif %}>-1 8 {% for file in _embedded.files %} -1 9 <source type="{{ file.mime_type }}" src="/video/{{ id }}-{{ file.quality }}.{{ file.format }}" {% if file.quality != 'adaptive' %}media="(min-height: {{ file.quality }}x)" data-quality="{{ file.quality }}" data-co2="{{ file.size.formatted }} (~{{ file.size.bytes|co2 }})"{% endif %}> 10 10 {% endfor %} 11 11 {% for track in tracks.subtitles %} 12 12 <track kind="{{ track.kind }}" label="{{ track.label }}" srclang="{{ track.srclang }}" src="{{ track._links.vtt.href }}">