Skip to content

Commit

Permalink
Initial Version
Browse files Browse the repository at this point in the history
  • Loading branch information
pdgeorge committed Dec 11, 2023
0 parents commit f605be4
Show file tree
Hide file tree
Showing 9 changed files with 582 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore a specific directory
/.terraform/

# Ignore all .MP4 files in the project
*.MP4
24 changes: 24 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions JoelSpinVT.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "ffmpeg_instance" {
ami = "ami-0fa1ca9559f1892ec"
instance_type = "t3.small"
key_name = aws_key_pair.my_key_pair.key_name
vpc_security_group_ids = ["allow-ssh", "allow-s3", "allow-twitch"]
iam_instance_profile = "EC2-admin"
user_data = file("./install_ffmpeg.sh")

tags = {
Name = "JoelSpinVT"
}
}

resource "aws_key_pair" "my_key_pair" {
key_name = "my-key-pair" # Specify a name for your key pair
public_key = file("~/.ssh/id_rsa.pub") # Path to your public key file
}

# Security Group for SSH
resource "aws_security_group" "allow-ssh" {
name = "allow-ssh"
description = "Allow SSH access"

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["180.150.36.214/32"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

# Security Group for S3 Access
resource "aws_security_group" "allow-s3" {
name = "allow-s3"
description = "Allow access to S3 bucket"

ingress {
from_port = 80 # Assuming your tool uses HTTP to access S3
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 443 # Assuming your tool uses HTTPS to access S3
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

# Security Group for Twitch Streaming
resource "aws_security_group" "allow-twitch" {
name = "allow-twitch"
description = "Allow streaming to Twitch"

ingress {
from_port = 1935
to_port = 1935
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 2088
to_port = 2088
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

output "instance_ip" {
value = aws_instance.ffmpeg_instance.public_ip
}
19 changes: 19 additions & 0 deletions Notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ami = "ami-0fa1ca9559f1892ec"
instance_type = "c5a.large"
~3,425.95 KBPS unstable


ami = "ami-0fa1ca9559f1892ec"
instance_type = "t3.small"
~3,414.95 KBPS unstable

ami = "ami-0fa1ca9559f1892ec"
instance_type = "t2.micro"
~3416.96 KBPS unstable

All were primarily unstable


Ubuntu
htop for benchmarking?
Useful insights for system performance
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
This is a small project to allow creating a 24-7 radio broadcast to Twitch, assuming you already have things set up.
The video to stream must be pre-rendered, and must be uploaded somewhere. For this project the simplest solution was an S3 bucket.

# EC2
When choosing an EC2 instance, choose one with an Amazon Machine Image (AMI) of the following requirements:
Amazon Linux 2
64-bit (x86)

Tested on t2-micro, however would be more optimal to use another with higher networking capabilities.
The VT family of instances are more recommended according to research. Still to be tested.

## EC2 Pricing:

### Acceptable:

t2-micro (Can barely keep a single stream up, with lag. It is possible, however only good in a "proof of concept" sense)

**cost:** "Free tier". after free tier: $0.0116/Hour On Demand

### Premium:

VT1.3xlarge (More than enough for a single stream, can reportedly stream 2 from the same instance, however that has not been tested) With the cost listed, this option is best when it is within the price range for the project, but the account also needs to be approved by AWS to have it added.

**cost:** $0.65/Hour

# Secrets Manager
The scripts used strongly encourage the usage of uploading your desired Twitch Stream key to the AWS secrets manager.
AWS Secrets Manager pricing:
Any secret is $0.40 per month after a 30 day trial period

# S3 Bucket

As mentioned above, the video needs to be uploaded to an s3 bucket and the script(s) need to be modified accordingly.

# Final Notes:

After much testing, the limiting factor is not the network speed, but the vcpu's available. FFmpeg requires multiple vcpu cores, the minimum number for this project could not be found during testing. For the purposes of this project, from a cost standpoint, cloud hosting is not a viable option from a cost standpoint. Utilising a locally run computer is the better option, however this was still a good learning experience/experiment.
12 changes: 12 additions & 0 deletions install_ffmpeg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
sudo -E aws s3 cp s3://joelspin-bucket/ffmpeg-release-amd64-static.tar.xz /usr/local/bin/ffmpeg/ffmpeg-release-amd64-static.tar.xz
cd /usr/local/bin/ffmpeg/
sudo -E tar -xf ffmpeg-release-amd64-static.tar.xz
cd ffmpeg-6.0-amd64-static
sudo -E cp -a ./* /usr/local/bin/ffmpeg/
sudo -E ln -s /usr/local/bin/ffmpeg/ffmpeg /usr/bin/ffmpeg
sudo -E aws s3 cp s3://joelspin-bucket/JoelSpinLonger.mp4 /vids/JoelSpinLonger.mp4
cd ~
SECRET_JSON=$(aws secretsmanager get-secret-value --secret-id twitch-joelspinvt-streamkey --query SecretString --output text --region us-east-1)
STREAM_KEY=$(echo "$SECRET_JSON" | grep -oP '"stream_key":\s*"\K([^"]*)')
sudo -E nohup ffmpeg -stream_loop -1 -i /vids/JoelSpinLonger.mp4 -c:v libx264 -preset fast -b:v 6000k -c:a aac -b:a 128k -ar 44100 -f flv rtmp://jfk.contribute.live-video.net/app/$STREAM_KEY > ~/ffmpeg_output.log 2>&1 &
9 changes: 9 additions & 0 deletions terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 4,
"terraform_version": "1.6.4",
"serial": 339,
"lineage": "6d0e1666-7874-48a1-c50b-2a0674ee5972",
"outputs": {},
"resources": [],
"check_results": null
}
Loading

0 comments on commit f605be4

Please sign in to comment.