39 lines
1 KiB
Bash
Executable file
39 lines
1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Uso: $0 <input_file> <output_dir>"
|
|
exit 1
|
|
fi
|
|
|
|
INPUT="$1"
|
|
OUTDIR="$2"
|
|
|
|
# Controlli preliminari
|
|
if [ ! -f "$INPUT" ]; then
|
|
echo "Errore: file di input non trovato: $INPUT"
|
|
exit 2
|
|
fi
|
|
|
|
# Crea la directory di output se non esiste
|
|
mkdir -p "$OUTDIR"
|
|
chmod 0755 "$OUTDIR"
|
|
|
|
# Evita che ffmpeg appenda a playlist esistenti accidentalmente
|
|
MASTER="${OUTDIR%/}/master.m3u8"
|
|
if [ -f "$MASTER" ]; then
|
|
echo "Attenzione: master.m3u8 esistente verrà sovrascritto: $MASTER"
|
|
fi
|
|
|
|
# Comando ffmpeg per VOD: mantiene tutti i segmenti (-hls_list_size 0) e non cancella nulla
|
|
ffmpeg -hide_banner -y \
|
|
-i "$INPUT" \
|
|
-c:v libx264 -profile:v high -level 4.1 -preset veryfast -tune zerolatency \
|
|
-b:v 5000k -maxrate 6000k -bufsize 12000k \
|
|
-r 30 -g 90 -keyint_min 90 -sc_threshold 0 -x264-params "nal-hrd=cbr" \
|
|
-pix_fmt yuv420p \
|
|
-c:a aac -b:a 160k -ac 2 -ar 48000 \
|
|
-f hls \
|
|
-hls_time 3 -hls_list_size 0 -hls_playlist_type vod \
|
|
-hls_segment_type mpegts \
|
|
-hls_segment_filename "${OUTDIR%/}/segment_%05d.ts" \
|
|
"${MASTER}"
|