Need to Install these packages
apt-get install ffmpeg git zip build-essential libpcre3-dev libssl-dev zlib1g-dev
mkdir build
cd build/
git clone https://github.com/arut/nginx-rtmp-module.git
git clone https://github.com/nginx/nginx.git
cd nginx
./auto/configure --add-module=../nginx-rtmp-module
make && make install
wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx && chmod +755 /etc/init.d/nginx
update-rc.d nginx defaults
/usr/local/nginx/sbin/nginx -t && nginx -s reload
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.orginal
> /usr/local/nginx/conf/nginx.conf
add new nginx.conf
./mp3-hls.sh SOURCE_FILE [OUTPUT_NAME]
./live-hls.sh SOURCE_FILE [OUTPUT_NAME]
./vod-hls.sh SOURCE_FILE [OUTPUT_NAME]
The script creates an "output" directory. It also overlays the PNG logo file on the video using FFmpeg's overlay filter. The script sets the logo_pos variable to "main_w-overlay_w-10:10", which positions the logo at the top right corner of the video, with a 10-pixel margin from the right and top edges. The output files are named "output.m3u8" that contains all the different bitrates. The playlist file is written in the "output" directory.
- To run the script, save it to a file (e.g. "set-logo.sh"), make it executable with chmod +x set-logo.sh, and run it with
./set-logo.sh
Here’s a command that will resize the video, adjust the bitrate, and compress the audio to help reduce the overall file size to around 500 MB.
ffmpeg -i input.mp4 -c:v libx264 -b:v 1000k -vf scale=1280:720 -preset medium -c:a aac -b:a 128k -movflags +faststart output.mp4
- -i input.mp4: Specifies the input file.
- -c:v libx264: Uses the libx264 codec for video encoding, which is efficient for compressing videos.
- -b:v 1000k: Sets the video bitrate to 1000 kbps. Adjusting this value (e.g., between 800k to 1500k) can help reach your desired file size. Lower values will produce smaller file sizes but may reduce video quality.
- -vf scale=1280:720: Resizes the video to 720p resolution (1280x720). Reducing the resolution helps to significantly decrease the file size.
- -preset medium: Controls the encoding speed vs. compression ratio. Options include ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, and veryslow. The slower the preset, the better the compression, but it will take longer to encode.
- -c:a aac: Uses the aac codec for audio compression.
- -b:a 128k: Sets the audio bitrate to 128 kbps. Adjust this value if you need further compression.
- -movflags +faststart: Optimizes the file for streaming by placing the index at the beginning of the file.
- output.mp4: Specifies the output file name.
- Adjust the -b:v value: Lowering the video bitrate will reduce the file size, but be careful not to set it too low, as it will impact the video quality. If 1000k results in a file that is still too large, try 800k or even lower.
- Change the Resolution: Lowering the resolution further (e.g., scale=854:480) will reduce the size but may affect the viewing experience.
- Adjust -preset: Using a slower preset (e.g., slow or veryslow) will take longer to encode but can achieve better compression without significantly impacting quality.
If you want to ensure a smaller file size by reducing the resolution to 480p:
ffmpeg -i input.mp4 -c:v libx264 -b:v 700k -vf scale=854:480 -preset slow -c:a aac -b:a 96k -movflags +faststart output.mp4
This command further reduces the video bitrate and resolution, which should result in a smaller output file size. Adjust these parameters based on your desired quality and file size.