WIP m3u8 gen
This commit is contained in:
parent
def37f3c5a
commit
a3844d9c44
2 changed files with 76 additions and 11 deletions
26
make-fmp4.sh
26
make-fmp4.sh
|
@ -1,5 +1,6 @@
|
|||
interval=10
|
||||
MOVFLAGS="-movflags +frag_keyframe+empty_moov -force_key_frames expr:gte(t,n_forced*$interval)"
|
||||
#MOVFLAGS="-movflags +frag_keyframe+empty_moov -force_key_frames expr:gte(t,n_forced*$interval)"
|
||||
MOVFLAGS="-movflags +frag_keyframe+empty_moov"
|
||||
AUDFLAGS="-movflags +empty_moov -frag_duration ${interval}000000"
|
||||
BITRATE_HI="-b:v 1250k"
|
||||
BITRATE_LO="-b:v 1000k"
|
||||
|
@ -18,20 +19,23 @@ INFILE=caminandes-llamigos.webm
|
|||
set -e
|
||||
|
||||
# Audio for HLS
|
||||
ffmpeg -i $INFILE -vn $AUDIO_MP3 -y fmp4.audio.mp3
|
||||
ffmpeg -i $INFILE -vn $AUDIO_MP3 -y fmp4.audio.mpeg.mp3
|
||||
ffmpeg -i $INFILE -vn $AUDIO_AAC $AUDFLAGS -y fmp4.audio.aac.mp4
|
||||
ffmpeg -i $INFILE -vn $AUDIO_OPUS $AUDFLAGS -y fmp4.audio.opus.mp4
|
||||
|
||||
# Video for HLS
|
||||
ffmpeg -i $INFILE -an $VIDEO_H264 $MOVFLAGS -pass 1 -y fmp4.video.h264.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_H264 $MOVFLAGS -pass 2 -y fmp4.video.h264.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_H264 $MOVFLAGS -pass 1 -y fmp4.480p.h264.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_H264 $MOVFLAGS -pass 2 -y fmp4.480p.h264.mp4
|
||||
|
||||
ffmpeg -i $INFILE -an $VIDEO_VP9 $MOVFLAGS -pass 1 -y fmp4.video.vp9.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_VP9 $MOVFLAGS -pass 2 -y fmp4.video.vp9.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_VP9 $MOVFLAGS -pass 1 -y fmp4.480p.vp9.mp4
|
||||
ffmpeg -i $INFILE -an $VIDEO_VP9 $MOVFLAGS -pass 2 -y fmp4.480p.vp9.mp4
|
||||
|
||||
# Playlist processing
|
||||
#php extract-playlist.php fmp4.audio.mp3 fmp4.audio.mp3.m3u8
|
||||
#php extract-playlist.php fmp4.audio.aac.mp4 fmp4.audio.aac.mp4.m3u8
|
||||
#php extract-playlist.php fmp4.audio.opus.mp4 fmp4.audio.opus.mp4.m3u8
|
||||
#php extract-playlist.php fmp4.video.h264.mp4 fmp4.video.h264.mp4.m3u8
|
||||
#php extract-playlist.php fmp4.video.vp9.mp4 fmp4.video.vp9.mp4.m3u8
|
||||
php extract-playlist.php fmp4.audio.mpeg.mp3 > fmp4.audio.mpeg.mp3.m3u8
|
||||
php extract-playlist.php fmp4.audio.aac.mp4 > fmp4.audio.aac.mp4.m3u8
|
||||
php extract-playlist.php fmp4.audio.opus.mp4 > fmp4.audio.opus.mp4.m3u8
|
||||
php extract-playlist.php fmp4.480p.h264.mp4 > fmp4.480p.h264.mp4.m3u8
|
||||
php extract-playlist.php fmp4.480p.vp9.mp4 > fmp4.480p.vp9.mp4.m3u8
|
||||
|
||||
php meta-playlist.php fmp4 audio.opus.mp4 audio.mpeg.mp3 480p.vp9.mp4 > fmp4.vp9.m3u8
|
||||
php meta-playlist.php fmp4 audio.opus.mp4 audio.mpeg.mp3 480p.vp9.mp4 480p.h264.mp4 > fmp4.vp9-h264.m3u8
|
||||
|
|
61
meta-playlist.php
Normal file
61
meta-playlist.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
$argv = $_SERVER['argv'];
|
||||
$self = array_shift( $argv );
|
||||
$base = array_shift( $argv ); // "fmp4"
|
||||
$audio = [];
|
||||
$video = [];
|
||||
|
||||
$audioCodecs = [
|
||||
'mpeg' => 'mp4a.40.34',
|
||||
'opus' => 'opus'
|
||||
];
|
||||
|
||||
// @fixme use correct settings based on the file
|
||||
$videoCodecs = [
|
||||
'vp9' => 'vp09.00.10.08',
|
||||
'h264' => 'avc1.42e00a',
|
||||
];
|
||||
|
||||
|
||||
while ( count( $argv ) > 0 ) {
|
||||
$track = array_shift( $argv );
|
||||
[ $res, $codec, $ext ] = explode( '.', $track, 3 );
|
||||
$filename = "$base.$res.$codec.$ext";
|
||||
$playlist = "$filename.m3u8";
|
||||
|
||||
if ( $res === 'audio' ) {
|
||||
$name = 'English'; // @fixme use correct unknown marker
|
||||
$language = 'en-US'; // @fixme
|
||||
$channels = 2; // @fixme
|
||||
$uri = urlencode( $filename );
|
||||
$audio[$codec] = "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"$codec\",NAME=\"$name\",LANGUAGE=\"$language\",AUTOSELECT=YES,DEFAULT=YES,CHANNELS=\"$channels\",URI=\"$uri\"";
|
||||
} else {
|
||||
$bandwidth = 1250000; // @fixme
|
||||
$width = 854; // @fixme
|
||||
$height = 480; // @fixme
|
||||
$fps = 24.0; // @fixme
|
||||
$baseLine = "#EXT-X-STREAM-INFO:BANDWIDTH=$bandwidth,RESOLUTION={$width}x{$height},FRAME-RATE={$fps}";
|
||||
if ( count( $audio ) > 1 ) {
|
||||
foreach ( array_keys( $audio ) as $audioCodec ) {
|
||||
$codecs = implode( ',', [
|
||||
$videoCodecs[$codec],
|
||||
$audioCodecs[$audioCodec],
|
||||
] );
|
||||
$line = "$baseLine,CODECS=\"$codecs\"";
|
||||
}
|
||||
} else {
|
||||
$codecs = $videoCodecs[$codec];
|
||||
$line = "$baseLine,CODECS=\"$codecs\",AUDIO=\"$audioCodec\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$lines = array_concat(
|
||||
[ '#EXTM3U' ],
|
||||
array_values( $audio ),
|
||||
$video
|
||||
);
|
||||
|
||||
$m3u8 = implode( "\n", $lines );
|
||||
print $m3u8;
|
Loading…
Reference in a new issue