From 70d6c7366ac133b3ef1a5f6ea8d3bfe380fa98fb Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 7 Jun 2022 19:35:35 -0700 Subject: [PATCH] mp3 and mjpeg tests mjpeg in mov is not working in hls with multiple segments on ios mp3 raw with id3 timestamps works best on ios hls mp3 in ts works on ios, but seems stuttery weirdly! mp3 in mp4 just don't work --- caminandes-llamigos.webm.audio.mp3.mp4.m3u8 | 68 ++++++++++++-------- transcode-segment.php | 71 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 26 deletions(-) diff --git a/caminandes-llamigos.webm.audio.mp3.mp4.m3u8 b/caminandes-llamigos.webm.audio.mp3.mp4.m3u8 index bc34161..3262043 100644 --- a/caminandes-llamigos.webm.audio.mp3.mp4.m3u8 +++ b/caminandes-llamigos.webm.audio.mp3.mp4.m3u8 @@ -3,37 +3,53 @@ #EXT-X-TARGETDURATION:10 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD -#EXT-X-MAP:URI="init.mp4" -#EXTINF:10.005397, -caminandes-llamigos.webm.audio.mp3.0000.mp4 +#EXT-X-MAP:URI="caminandes-llamigos.webm.audio.mp3.mp4.mp4",BYTERANGE="755@0" +#EXTINF:10.005896, +#EXT-X-BYTERANGE:163302@755 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0001.mp4 +#EXT-X-BYTERANGE:163302@164057 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0002.mp4 +#EXT-X-BYTERANGE:163303@327359 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.004580, +#EXT-X-BYTERANGE:163302@490662 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.005057, +#EXT-X-BYTERANGE:163302@653964 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:9.978617, +#EXT-X-BYTERANGE:162877@817266 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.005215, +#EXT-X-BYTERANGE:163302@980143 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0003.mp4 +#EXT-X-BYTERANGE:163303@1143445 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0004.mp4 +#EXT-X-BYTERANGE:163302@1306748 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.004739, +#EXT-X-BYTERANGE:163302@1470050 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:9.978776, -caminandes-llamigos.webm.audio.mp3.0005.mp4 +#EXT-X-BYTERANGE:162877@1633352 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.005057, +#EXT-X-BYTERANGE:163302@1796229 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.004739, +#EXT-X-BYTERANGE:163302@1959531 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 +#EXTINF:10.005057, +#EXT-X-BYTERANGE:163303@2122833 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0006.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0007.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0008.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0009.mp4 -#EXTINF:9.978776, -caminandes-llamigos.webm.audio.mp3.0010.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0011.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0012.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0013.mp4 -#EXTINF:10.004898, -caminandes-llamigos.webm.audio.mp3.0014.mp4 +#EXT-X-BYTERANGE:163302@2286136 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXTINF:0.119819, -caminandes-llamigos.webm.audio.mp3.0015.mp4 +#EXT-X-BYTERANGE:2270@2449438 +caminandes-llamigos.webm.audio.mp3.mp4.mp4 #EXT-X-ENDLIST diff --git a/transcode-segment.php b/transcode-segment.php index 749fd46..b6bdcdc 100644 --- a/transcode-segment.php +++ b/transcode-segment.php @@ -40,6 +40,8 @@ class Audio { '-b:a', '96k', ], ], + // with the added id3 timestamps this work great with iOS HLS + // but mac safari doesn't seem happy with anything i do with them 'mp3' => [ 'container' => 'mp3', 'options' => [ @@ -49,6 +51,27 @@ class Audio { '-b:a', '128k', ], ], + // works on iOS HLS but seems stuttery? i dunno why + // mac safari doesn't seem to like it either + 'mp3.ts' => [ + 'container' => 'ts', + 'options' => [ + '-acodec', 'libmp3lame', + '-ar', 44100, + '-ac', 2, + '-b:a', '128k', + ], + ], + // no dice on ios or macos safari + 'mp3.mp4' => [ + 'container' => 'mp4', + 'options' => [ + '-acodec', 'libmp3lame', + '-ar', 44100, + '-ac', 2, + '-b:a', '128k', + ], + ] ]; } @@ -60,6 +83,25 @@ class Video { ]; public const FORMATS = [ + 'mjpeg' => [ + // it doesn't seem to like this after all. worth trying! + 'container' => 'mov', + 'options' => [ + 'common' => [ + '-vcodec', 'mjpeg', + ], + 'fallback' => [ + // no specific options :D + ], + ], + 'resolutions' => [ + '144p' => [ + 'width' => 176, + 'height' => 144, + 'bitrate' => '1024k', + ] + ] + ], 'vp9' => [ 'container' => 'mp4', 'options' => [ @@ -222,6 +264,30 @@ class Transcoder { '-hls_segment_filename', $segment, '-y', $playlist, ]; + } elseif ( $container == 'ts' ) { + $segment = "$outfile.$container"; + $segmentOptions = [ + '-f', 'hls', + '-hls_segment_type', 'mpegts', + '-hls_flags', 'single_file', + '-hls_time', '10', + '-hls_playlist_type', 'vod', + '-hls_segment_filename', $segment, + '-y', $playlist, + ]; + } elseif ( $container == 'mov' ) { + // For MJPEG, MP4 doesn't work in Apple HLS for some reason + // but QuickTime is sortof ok for one segment? + // Note segment won't make single fMP4-style files though. + $segment = "$outfile.%04d.$container"; + $segmentOptions = [ + '-f', 'segment', + //'-segment_format_options', 'movflags=frag_keyframe+empty_moov', + //'-segment_format_options', 'movflags=+frag_keyframe+empty_moov+default_base_moof+faststart', + '-segment_time', '10', + '-segment_list', $playlist, + '-y', $segment + ]; } elseif ( $container == 'mp3' ) { // For MP3, segment it raw. // We'll need to postprocess to add an ID3 tag with timestamp @@ -309,6 +375,11 @@ foreach ( $infiles as $filename ) { $codec->audio('aac'); $codec->audio('opus'); $codec->audio('mp3'); + $codec->audio('mp3.ts'); + $codec->audio('mp3.mp4'); + foreach ( Video::FORMATS['mjpeg']['resolutions'] as $res => $format ) { + $codec->video('mjpeg', $res, 'fallback'); + } foreach ( Video::FORMATS['vp9']['resolutions'] as $res => $format ) { if ( $format['width'] <= $source->width && $format['height'] <= $source->height ) { $codec->video('vp9', $res, 'fast');