Compare commits
10 Commits
982c2a99f1
...
68125f4a15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68125f4a15 | ||
|
|
b4201be474 | ||
|
|
6e1407b875 | ||
|
|
ea16014711 | ||
|
|
26cbd03bfc | ||
|
|
6f8841a542 | ||
|
|
18d37cadc0 | ||
|
|
1967866480 | ||
|
|
a6ba656aff | ||
|
|
963b623778 |
151
content/maker-portfolio/light-weight-video-streaming.md
Normal file
151
content/maker-portfolio/light-weight-video-streaming.md
Normal file
@@ -0,0 +1,151 @@
|
||||
---
|
||||
title: Light Weight Video Streaming Server
|
||||
date: 2024-12-24
|
||||
---
|
||||
|
||||
> [!NOTE]
|
||||
> This is another installation in my *magnum opus*, "Random-Things-I-Make-for-Absolutely-no-Reason".
|
||||
|
||||
# The Problem
|
||||
|
||||
I've picked up watching portions of shows and dropping them on a whim, but generally don't want to stream them thanks to the network load caused by my other projects[^1]. This requires downloading and hosting the files myself, perfectly feasible given my resources.
|
||||
Hosting these files over the internet, however, would not be feasible due to the low outgoing upload speeds provided by my godforsaken ISP. The client, in cases would just be my phone or laptop. I will acknowledge, though, that options like Plex, Jellyfin, and others exist to manage almost the same requirements.
|
||||
The sole reason I've chosen not to go with these is the resource overhead demanded. I spun up an instance of Jellyfin to prove this point. At idle, $\ge0.5$ GB of memory was used alongside a not insignificant CPU/GPU allocation.
|
||||
Looking further into the processes involved, I found that servers like Jellyfin and Plex use the HSL video streaming paradigm, requiring server-side segmentation, encoding/decoding, and scaling. In my situation, bandwidth was an unlimited resource, so the overhead was unnecessary.
|
||||
|
||||
# The Solution
|
||||
|
||||
I really just had to write a script to present all the videos on a webserver in a drop-down list with a decent video player. Although there is nothing I hate more in the world than a Python network application, I'm too lazy to do anything else.
|
||||
|
||||
Flask python API/`html` proxy (`server.py`):
|
||||
|
||||
```python
|
||||
from flask import Flask, jsonify, send_from_directory, render_template
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Get the current working directory (where the Python script is run from)
|
||||
video_dir = os.getcwd() # Ensure this is where your .mp4 files and index.html are located
|
||||
|
||||
@app.route('/')
|
||||
def serve_index():
|
||||
"""Serve the index.html file."""
|
||||
return send_from_directory(video_dir, 'index.html')
|
||||
|
||||
@app.route('/videos')
|
||||
def list_videos():
|
||||
"""Return a list of .mp4 files in the directory."""
|
||||
files = [f for f in os.listdir(video_dir) if f.endswith('.mp4')]
|
||||
return jsonify(files)
|
||||
|
||||
@app.route('/videos/<filename>')
|
||||
def serve_file(filename):
|
||||
"""Serve video files to the browser from the videos directory."""
|
||||
return send_from_directory(video_dir, filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=8080)
|
||||
|
||||
```
|
||||
|
||||
And the `html` front-end (`index.html`):
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>4K Video Player</title>
|
||||
<link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f4f4f9;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.video-container {
|
||||
max-width: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>4K Video Player</h1>
|
||||
<select id="videoList" onchange="loadVideo(this.value)">
|
||||
<option value="">Select a video</option>
|
||||
</select>
|
||||
<div class="video-container">
|
||||
<video id="player" class="video-js vjs-default-skin" controls>
|
||||
<source id="videoSource" src="" type="video/mp4">
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/video.js/dist/video.min.js"></script>
|
||||
<script>
|
||||
var player = videojs('player', {
|
||||
controls: true,
|
||||
autoplay: false,
|
||||
preload: 'auto',
|
||||
width: '100%',
|
||||
height: 'auto',
|
||||
poster: 'path/to/your/poster-image.jpg', // Optional: add a thumbnail image for video preview
|
||||
fluid: true, // Ensures responsive video sizing
|
||||
playbackRates: [0.5, 1, 1.5, 2], // Allow the user to control playback speed
|
||||
controlBar: {
|
||||
playToggle: true,
|
||||
volumePanel: { inline: false }, // Displays volume control as a separate panel
|
||||
currentTimeDisplay: true,
|
||||
timeDivider: true,
|
||||
durationDisplay: true,
|
||||
remainingTimeDisplay: true,
|
||||
fullscreenToggle: true
|
||||
},
|
||||
sources: [{
|
||||
type: 'video/mp4',
|
||||
src: ''
|
||||
}]
|
||||
});
|
||||
|
||||
// Populate video dropdown list
|
||||
const videoList = document.getElementById('videoList');
|
||||
|
||||
fetch('/videos')
|
||||
.then(response => response.json())
|
||||
.then(files => {
|
||||
files.forEach(file => {
|
||||
const option = document.createElement('option');
|
||||
option.value = file;
|
||||
option.textContent = file;
|
||||
videoList.appendChild(option);
|
||||
});
|
||||
});
|
||||
|
||||
// Load the selected video into the player
|
||||
function loadVideo(src) {
|
||||
if (!src) return; // If no video selected, do nothing
|
||||
const videoSource = document.getElementById('videoSource');
|
||||
videoSource.src = '/videos/' + src.replace('.mkv', '.mp4'); // Set video source path
|
||||
|
||||
player.src({ type: 'video/mp4', src: '/videos/' + src.replace('.mkv', '.mp4') });
|
||||
player.play(); // Start playback automatically after video is loaded
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
Resulting in:
|
||||

|
||||
|
||||
|
||||
[^1]: I will write these up here at some point.
|
||||
BIN
content/maker-portfolio/maker-portfolio-1.png
Normal file
BIN
content/maker-portfolio/maker-portfolio-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
content/maker-portfolio/maker-portfolio-2.png
Normal file
BIN
content/maker-portfolio/maker-portfolio-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
76
content/physics/general-relativity.md
Normal file
76
content/physics/general-relativity.md
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
title: Introduction to General Relativity
|
||||
date: 2025-01-04
|
||||
---
|
||||
|
||||
# The Introduction to the Introduction
|
||||
|
||||
I pulled all of this from a certain immensely helpful textbook[^1]. The need for special relativity arises from the limitations of Newton's theory of gravitation. We've all seen the following equation:
|
||||
|
||||
$$
|
||||
\textbf{F}=-\frac{MmG}{r^3}\textbf{r}
|
||||
$$
|
||||
|
||||
$\textbf{r}$ is the direction vector, or unit direction vector from masses $M$ and $m$. The problem is that most of these quantities vary over time. For example, if $M$ was a function of $t$:
|
||||
|
||||
$$
|
||||
\textbf{F}(t)=-\frac{M(t)mG}{r^3}\textbf{r}
|
||||
$$
|
||||
|
||||
> [!NOTE]
|
||||
> $G$ is the gravitational constant.
|
||||
|
||||
The problem here is that a variation in mass creates a delayed reaction in gravitation, but our formula with Newtonian mechanics does not provide for that. Above, a variation in any quantity yields instant variation in force. In reality, gravity moves at the speed of light.
|
||||
Why you can't just use $t-r/c$ as the parameter will be covered sometime later. For now, just know Einstien Enstiened here. Such remodeling of Newton's law was attempted and then met with failure. The intensity of the gravitational field at any distance $r$ from the center of mass and direction $\hat{r}$ is provided by:
|
||||
$$
|
||||
\textbf{g}=-\frac{GM}{r^2}\hat{r}
|
||||
$$
|
||||
|
||||
This is not entirely accurate, since what is actually being described here is the gradient field of attractive forces, written so:
|
||||
$$
|
||||
\textbf{g}=-\nabla\phi, \phi(r)=-\frac{GM}{r}
|
||||
$$
|
||||
|
||||
The function $\phi(r)$ is the gravitational *potential*, a scalar field. Each scalar value in the field represents the work needed to be done to move mass $m$ there from $r=0$. Specifically, this is the change in potential energy, meaning an upward motion out of the gravitational well caused by a mass $M$ results in a positive change in potential energy.
|
||||
The potential $\phi$ satisfies field equations.
|
||||
|
||||
$$
|
||||
\text{(Laplace, in a vacuum) } \nabla^2\phi=0
|
||||
$$
|
||||
|
||||
$$
|
||||
\text{(Poisson, with matter) } \nabla^2\phi=4\pi G \rho
|
||||
$$
|
||||
|
||||
The field $\textbf{g}$ depends on $r$ but not $t$, meaning the partial derivative with respect to $r$ equals $0$.
|
||||
|
||||
## Equivalence Principle
|
||||
|
||||
> [!NOTE] definition
|
||||
> **The Equivalence Principle states:** No experiment in mechanics can distinguish between a gravitational field and an accelerating frame of reference.
|
||||
|
||||
After reading this, I realized that the textbook has it worded horribly. It means that the two — gravity and acceleration are locally indistinguishable.
|
||||
There are three relevant equations. The Force acting on an object:
|
||||
$$
|
||||
\vec{F}=m_i \vec{a}
|
||||
$$
|
||||
The above equation describes force opposite to inertia. The below equation describes force appeared to have been exerted by the gravitational field:
|
||||
$$
|
||||
\vec{F}=m_g \vec{g}
|
||||
$$
|
||||
|
||||
Here, $m_g$ is the *gravitational mass* of the particle. Gravitational Mass is a measure of the response of a particle to the gravitational field. These are conceptually different things. The gravitational mass depends on the scalar gravitational potential field. Of course, there are several experiments to prove this, but the equation of note is as follows:
|
||||
|
||||
$$
|
||||
\vec{a}=\frac{\vec{F}}{m_i}=\frac{m_g}{m_i}\vec{g}
|
||||
$$
|
||||
|
||||
# Einstien's Train
|
||||
|
||||
|
||||
|
||||
|
||||
[^1]: Ryder, L. (2009). Introduction to General Relativity. Singapore: Cambridge University Press.
|
||||
|
||||
|
||||
#physics
|
||||
@@ -25,7 +25,7 @@ When it comes to energy transfer and phase changes there are only two useful equ
|
||||
|
||||
These equations together describe the heat energy required for changing the temperature of a substance and for changing its phase.
|
||||
|
||||
**It is important to note the alternate arrangement of both:
|
||||
**It is important to note the alternate arrangement of both**:
|
||||
$$
|
||||
Q=nc_{\mathrm{mol}}\Delta T = \Delta \textbf{KE}
|
||||
$$
|
||||
@@ -57,4 +57,145 @@ $$
|
||||
|
||||
Provides the power per unit area of the black body, from the interval $\left[\lambda, \lambda + \mathrm{d}\lambda\right]$, given that $\mathrm{d}\lambda$ is an infinitesimally small quantity.
|
||||
|
||||
## Wien's displacement law.
|
||||
|
||||
Wien's law states the wavelength of peak intensity at a given temperature in Kelvin $T$ is given by:
|
||||
|
||||
$$
|
||||
\lambda_{\text{peak}}=\frac{b}{T}
|
||||
$$
|
||||
|
||||
Where $b$ is Wien's displacement constant, equal to $2.897771955\cdot 10^{-3} \mathrm{m}\cdot\mathrm{K}$.
|
||||
|
||||
> [!NOTE]
|
||||
> The material does not matter. All black bodies emit radiation over all wavelengths.
|
||||
|
||||
## Stefan Boltzmann Law of Radiation
|
||||
This law describes the emissive power of a Black Body per unit area.
|
||||
|
||||
$$
|
||||
E_b=\varepsilon \sigma\cdot T^4
|
||||
$$
|
||||
|
||||
In the above equation,:
|
||||
|
||||
- $E_b$ is the **Emissive Power** of a black body, per unit time, per unit area.
|
||||
- $\varepsilon$ is the emissivity of an object
|
||||
- $\sigma$ is the Boltzmann constant, about $\approx 5.670374419\cdot 10^{-8} \mathrm{W}\cdot\mathrm{m}^{-2}\cdot \mathrm{K}^{-4}$
|
||||
- A perfect black body has an emissivity of $1$, and an albedo of $0$
|
||||
- always work in default SI units
|
||||
|
||||
If you desire the total power across the entirety of the surface:
|
||||
$$
|
||||
P_b=A\varepsilon \sigma\cdot T^4
|
||||
$$
|
||||
Where $A$ is the area of the exposed surface.
|
||||
|
||||
## Emissivity and Albedo
|
||||
|
||||
Emissivity $\varepsilon$ is given by :
|
||||
$$
|
||||
\varepsilon=\frac{P_{\text{obj}}}{P_b}
|
||||
$$
|
||||
Albedo is given by:
|
||||
$$
|
||||
\alpha=\frac{P_\text{reflected}}{P_{\text{incoming}}}
|
||||
$$
|
||||
This is where the Boltzmann law comes in to play. In order to calculate the emissivity of an object, you first need bot: the power of emissions from the target object, and the Power that would be emitted by a black body of the same temperature. This value can be procured using the Stefan Boltzmann Law of Radiation.
|
||||
|
||||
Albedo, however, is a far simpler quantity, relying only on the input and output energies of the object.
|
||||
|
||||
## Inverse Square Law and Apparent brightness
|
||||
|
||||
If $b$ is the Power experienced at a radius $r$:
|
||||
|
||||
$$
|
||||
b=\frac{L}{4\pi r^2}
|
||||
$$
|
||||
|
||||
The above is true when $L$ is procured from the source, most likely using the Boltzmann's law.
|
||||
# Gas Laws and the Ideal Gas Law
|
||||
|
||||
## Ideal Gas Law
|
||||
The **Ideal Gas Law** is a fundamental equation describing the behavior of ideal gases:
|
||||
|
||||
$$
|
||||
PV = nRT
|
||||
$$
|
||||
|
||||
Where:
|
||||
- $P$ = Pressure (in atm, Pa, or another unit)
|
||||
- $V$ = Volume (in liters or cubic meters)
|
||||
- $n$ = Number of moles of gas
|
||||
- $R$ = Ideal gas constant ($0.0821 \, \mathrm{L \cdot atm \cdot mol^{-1} \cdot K^{-1}}$)
|
||||
- $T$ = Temperature (in Kelvin)
|
||||
|
||||
This equation relates the pressure, volume, temperature, and quantity of an ideal gas.
|
||||
|
||||
---
|
||||
|
||||
## Boyle's Law
|
||||
**Boyle's Law** states that the pressure of a gas is inversely proportional to its volume when temperature and the number of moles are constant:
|
||||
|
||||
$$
|
||||
P \propto \frac{1}{V} \quad \text{or} \quad P_1V_1 = P_2V_2
|
||||
$$
|
||||
|
||||
### Key Points:
|
||||
- As volume decreases, pressure increases.
|
||||
- The relationship is hyperbolic.
|
||||
|
||||
---
|
||||
|
||||
## Charles's Law
|
||||
**Charles's Law** states that the volume of a gas is directly proportional to its absolute temperature when pressure and the number of moles are constant:
|
||||
|
||||
$$
|
||||
V \propto T \quad \text{or} \quad \frac{V_1}{T_1} = \frac{V_2}{T_2}
|
||||
$$
|
||||
|
||||
### Key Points:
|
||||
- As temperature increases, volume increases.
|
||||
- Temperature must be in Kelvin.
|
||||
|
||||
---
|
||||
|
||||
## Gay-Lussac's Law
|
||||
**Gay-Lussac's Law** states that the pressure of a gas is directly proportional to its absolute temperature when volume and the number of moles are constant:
|
||||
|
||||
$$
|
||||
P \propto T \quad \text{or} \quad \frac{P_1}{T_1} = \frac{P_2}{T_2}
|
||||
$$
|
||||
|
||||
### Key Points:
|
||||
- As temperature increases, pressure increases.
|
||||
- Temperature must be in Kelvin.
|
||||
|
||||
---
|
||||
|
||||
## Avogadro's Law
|
||||
**Avogadro's Law** states that the volume of a gas is directly proportional to the number of moles when pressure and temperature are constant:
|
||||
|
||||
$$
|
||||
V \propto n \quad \text{or} \quad \frac{V_1}{n_1} = \frac{V_2}{n_2}
|
||||
$$
|
||||
|
||||
### Key Points:
|
||||
- Adding more gas increases volume proportionally.
|
||||
- This law explains why equal volumes of gases contain equal numbers of molecules at the same temperature and pressure.
|
||||
|
||||
---
|
||||
|
||||
## Combined Gas Law
|
||||
The **Combined Gas Law** combines Boyle's, Charles's, and Gay-Lussac's Laws into one equation when the number of moles is constant:
|
||||
|
||||
$$
|
||||
\frac{P_1V_1}{T_1} = \frac{P_2V_2}{T_2}
|
||||
$$
|
||||
|
||||
This equation can be used to calculate changes in pressure, volume, or temperature of a gas sample.
|
||||
|
||||
---
|
||||
|
||||
Use these laws to analyze relationships between variables and predict gas behavior under different conditions!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user