Back

24-hour live broadcast using Linux

are prohibited from being abused. 阅读《24-hour live broadcast using Linux》了解更多。

Featured image of post 24-hour live broadcast using Linux

Table of contents

# 24-hour live broadcast using Linux

TL;DR / [Geek Summary]:

  • Compute Democracy: Repurpose old Android phones into 24/7 streaming servers using Linux Deploy or Termux.
  • Core Engine: Deploy FFmpeg as the stream pusher combined with Screen for background persistence and crash recovery.
  • Traffic Optimization: Tailor RTMP scripts for platforms like Bilibili and YouTube for low-power, “digital life” style continuous broadcasting.

The methods in this article are prohibited from being abused.

Please read the video website TOS before use, and do not violate the video website discipline.

# 24-hour live broadcast using Linux

Materials:

A mobile phone and an unlimited network

If you have any questions, please ask in the comment area

# Install Ubuntu (required)

# 24-hour live broadcast on mobile phone

Power saving and quietness are lower cost than cloud servers

# LinuxDeploy (root permission required)

Scenery

linux deploy When setting up the environment, I consulted a lot of information on the Internet and felt that the performance of the mobile phone as a Linux server was unsatisfactory. (But it is enough for live broadcast)

If you are a beginner in Linux, using a mobile phone as a server to learn is a good choice (encounter problems and then solve them). There are very few phones on the market that can be rooted (if your phone is OnePlus or Xiaomi, you can try rooting)

# Rootable phones

All Xiaomi Redmi models: Xiaomi Redmi phones have always supported the official unlock BL (usually unlocked in 7 days). After unlocking BL, you can flash the phone to get root operations, etc. Xiaomi’s unlock BL is also the most magical, supporting WeChat Alipay fingerprint payment, which is perfect.

Samsung/OnePlus/Realme/Lenovo/Asus ROG models These 5 major models also support the official unlock BL. Generally, the official provides unlocking methods, which are the fastest and do not require waiting. Some are unlocked by unlocking commands, and some are unlocked by official unlocking tools. After unlocking BL, it still supports playing with the phone and flashing operations, but after the above models unlock BL, the system no longer supports WeChat fingerprint payment, and must rely on the mask fingerprint module, or lock BL

Nubia Red Magic/Meizu/Black Shark/LG models The above 5 models do not support official unlock BL, so unlocking BL and flashing the phone depends entirely on developers. Fortunately, the above models can basically be unlocked and flashed by the official BL, and then get perfect root, etc. Unofficial unlocking of BL may cause the phone to lose its warranty function. Friends who hope to get warranty need to flash back to the official system before warranty, and then re-lock BL. OPPO models that can be deeply tested. There are not many OPPO models that can be rooted at present, and they all need to pass the official deep test. There is currently no unlocking and rooting method for models that are not officially open for deep testing. It is known that only these models can apply for testing, and the application time is the 1st or 15th of each month. Users who need to unlock root should apply in time. Unlocking BL will cause data to be cleared. Please back up your data before flashing. Fingerprint payment will also become invalid, the same plus model

Support Find X/R17 Pro/Reno/Reno Ace/Find X2 series/Ace2/Reno3 series/R17 full network/K1/K3 /K5/R15x official version/Reno4, Reno4 Pro, Reno4 SE 5G/Reno5 Pro+, Reno5 Pro, Reno5

Root is not standardized and becomes bricked two lines of tears

Issues and summary to pay attention to when using:

  • ~~ In the Linux Deploy settings, the BusyBox installation path needs to be set in Path (default /system/xbin)~~ BusyBox can’t be opened after installation

  • When enabling the permission to mount resources on Android, pay attention to the mount point name. The name in the document is inconsistent with the name used by your own mobile phone (you can view it through the file management tool)

  • Download network speed is a hard flaw. When installing the system, the foreign server connected may time out for download

  • Do not download apk from the app store, go directly to github and download the latest apk

The above problems may cause ssh and other services to fail to start and cannot be used normally.

Mount SD card

SD card mounting example


# Use environment

Download Xshell

A rooted mobile phone

A computer

Use ssh to access linux deploy


# Front-end server installation instructions

# Install BusyBox app on mobile phone

https://github.com/meefik/busybox/releases

Application interface, select install (use default configuration/system/xbin) Please try it yourself. If it fails, reinstall Linux Deploy

# Install linux deploy on mobile phone

Releases · meefik/linuxdeploy · GitHub

# Modify linux deploy configuration

linux In the deploy interface, select the icon in the upper left corner - Configuration:

PropertiesConfiguration
Screen always onSelect
Lock Wi-FiSelect
CPU wake-upSelect
PATH variableSame as the configuration in BusyBox /system/xbin

After modification, select “Update environment” and save the configuration.

# Modify Linux installation properties

Linux deploy interface, select the icon in the lower right corner:

PropertiesConfigurationDescription
Release version GNU/LinuxUbuntuUbuntu is the easiest to install
Architecturearm64You can view the mobile phone CPU architecture through the icon-status in the upper right corner of Linux deploy
Release versionDefault
Image size4096Supports up to 4096MB
File systemext4Keep default
User namerootUsed when logging in with ssh
User passwordSet it yourselfEnglish uppercase and lowercase letters and numbers
Localizationzh_CN.UTF-8Chinese package is enough
Enable Allow the use of initialization systemDisable
Enable and allow resources on Android to be mountedSelectMount it yourself according to the above method
Mount point list/mnt/sdcard:/mntSource name: mount point name
Note: The name may be different for different phones, you can view it through the MT file viewer
Enable SSH serverSelectDefault

# Install Ubuntu

linux deploy icon in the upper right corner-install

# Install dependencies

1
sudo apt install ffmpeg screen

Just press Y

# Termux (universal method without root)

Note in advance that this method has weaker performance

Run FFmpeg on Android with Termux and Ubuntu 22. However, it requires setting up a lot of commands manually, be careful not to skip any steps. Note that this may take 10 to 20 minutes or more, depending on your technical knowledge level. Internet speed and CPU speed.

# Installation

# Termux

Warning

The Play Store version of Termux is outdated and unsupported, do not use it, use the Github one opens in a new window

Go to the Termux Github latest version opens in a new window , download debug_universal.apk, unzip it and run it.

Tips

**If your file manager does not allow you to run APK files, install and use MT File Manager and allow it to install third-party apps when requested. **

IMPORTANT WARNING

**Once you have Termux installed, open it, pull down the Android menu to notifications, in the Termux notification, drag down until you see the following option: Exit | Acquire wakelock, click Acquire wakelock and allow Termux to have battery optimization exclusion permissions when asked. If you don’t do this, your performance will be much worse and Termux may be killed by Android while running in the background! **

# Install Ubuntu 22.04

For installing Ubuntu 22. In Termux, you will need wget and proot, we will install them in the next step.

Once you have Termux installed open and run the following commands (in order):

  1. pkg update

  2. pkg upgrade

  3. pkg install proot wget

Tips

If you are asked to press Y/N during the update/upgrade command, just type Y and press Enter

You will then need to download the installation script using the following command:

1
wget https://raw.githubusercontent.com/MFDGaming/ubuntu-in-termux/master/ubuntu.sh

Once the script has downloaded run it:

1
bash ubuntu.sh

You will then be asked a question, type Y and press Enter.

Once the installation is complete, you can start Ubuntu with:

1
./startubuntu.sh

# Install dependencies

First, we need to update the APT package manager repository and install dependencies.

To update the APT repository, runRun the following command:

1
apt update -y && apt upgrade -y

After completion, we need to install the dependencies, the command is as follows:

1
sudo apt install ffmpeg screen

# Introduction to FFmpeg

FFmpeg is a very powerful command line utility that can run on Linux distributions, Windows, and macOS, and supports multiple architectures. FFmpeg is written in C and assembly language, with powerful performance and cross-platform support.

# FFmpeg Installation

On Linux distributions such as Ubuntu, FFmpeg is relatively simple to install. Open the terminal and run the following command to install it.

# Ubuntu and similar distributions

1
sudo apt install FFmpeg

After FFmpeg is installed, you can enter the following command to check whether the installation is successful.

1
ffmpeg --version

Test installation

# File transfer

This is very important for whether your live broadcast can be opened

You need to install Xftp

Then you will find an Xftp button on the far right. Click it (you must connect to SSH to use it)

Demonstration file transfer

linuxdeploy The path is like this

1
/root

And Termux needs to install SSHD to use SFTP

1
pkg install sshd

Run after installation

1
sshd

Set password

1
passwd

Query the mobile phone ip, based on the actual mobile phone ip

1
ifconfig

Query the current user

1
whoami

Confirm the listening port of the ssh service

1
netstat -ntlp | grep sshd

The default SSH port is the 8022 port of this phone

The default path is here

1
/data/data/com.termux/files/home/ubuntu-fs/root

# Preparation before starting the live broadcast

Youtube preparation

You cannot broadcast copyrighted content on Youtube live broadcast (in simple terms, it means things that are popular on Youtube)

For example, the content of my live broadcast is Ding Zhen, so it’s okay

Those who are capable can click on the link to watch Snow Leopard live broadcast doge

I Got Smoke Ding Zhen Infinite Loop 24H*7Days - YouTube

Live broadcast example

Youtube live broadcast is too difficult for you

# Bilibili Live

Account requires real name (18 years or older)

IP address needs to be in mainland China

Those not in mainland China can use Guiyan Accelerator (Search by yourself)

https://live.bilibili.com/24595202

bili Live

If you meet these conditions, please continue reading

# Live script

Please encapsulate the following content into .sh format For example: 535ir.sh

Create a folder

1
mkdir zhibo

Enter the folder

1
cd zhibo

Add script

1
nano zhibo.sh

If you don’t have NANO, install it

1
apt install nano

# Youtube live script

1
2
3
4
5
#!/bin/bash
while true
do
    ffmpeg -re -i "Video.mp4" -vcodec copy -acodec copy -f flv "Server address/live code"
done

# Bilibili live script

1
2
3
4
5
#!/bin/bash
while true
do
    ffmpeg -re -i "Video.mp4" -vcodec copy -acodec copy -f flv "Server address/live code"
done

# Run live

Add a virtual terminal

1
screen -S custom name
1
Run ./script name.sh

Return to the virtual terminal

1
screen -r the name you just customized

Exit from the virtual terminal

1
Press Ctrl+a d in the screen terminal

If you encounter any problems, please search for related issues on Bing

Or ask questions in the comment section