@@ -686,6 +686,7 @@ async fn generate_and_upload_opener(
686686fn opener_ffmpeg_args ( source_path : & Path , source_probe : & SourceProbe ) -> Vec < OsString > {
687687 let copy_video = source_probe. video_codec . as_deref ( ) == Some ( "h264" )
688688 && source_probe. width . max ( source_probe. height ) <= OPENER_MAX_DIMENSION ;
689+ let keyframe_interval = hls_keyframe_interval_frames ( source_probe) . to_string ( ) ;
689690 let mut args = vec ! [
690691 os( "-y" ) ,
691692 os( "-i" ) ,
@@ -712,6 +713,17 @@ fn opener_ffmpeg_args(source_path: &Path, source_probe: &SourceProbe) -> Vec<OsS
712713 os ( OPENER_VIDEO_CRF ) ,
713714 os ( "-pix_fmt" ) ,
714715 os ( "yuv420p" ) ,
716+ os ( "-g" ) ,
717+ os ( & keyframe_interval) ,
718+ os ( "-keyint_min" ) ,
719+ os ( & keyframe_interval) ,
720+ os ( "-sc_threshold" ) ,
721+ os ( "0" ) ,
722+ os ( "-force_key_frames" ) ,
723+ os ( & format ! (
724+ "expr:gte(t,n_forced*{})" ,
725+ HLS_TARGET_SEGMENT_SECONDS
726+ ) ) ,
715727 ] ) ;
716728 }
717729 if source_probe. has_audio {
@@ -724,6 +736,8 @@ fn opener_ffmpeg_args(source_path: &Path, source_probe: &SourceProbe) -> Vec<OsS
724736 args. extend ( [
725737 os ( "-movflags" ) ,
726738 os ( "+frag_keyframe+empty_moov+default_base_moof" ) ,
739+ os ( "-frag_duration" ) ,
740+ os ( "1000000" ) ,
727741 os ( "-f" ) ,
728742 os ( "mp4" ) ,
729743 os ( "pipe:1" ) ,
@@ -3004,6 +3018,16 @@ mod tests {
30043018 assert ! ( args. windows( 2 ) . any( |pair| pair == [ "-b:a" , "96k" ] ) ) ;
30053019 assert ! ( args. iter( ) . any( |value| value. contains( "min(640,iw)" ) ) ) ;
30063020 assert ! ( args. iter( ) . any( |value| value. contains( "min(640,ih)" ) ) ) ;
3021+ assert ! ( args. windows( 2 ) . any( |pair| pair == [ "-g" , "30" ] ) ) ;
3022+ assert ! ( args. windows( 2 ) . any( |pair| pair == [ "-keyint_min" , "30" ] ) ) ;
3023+ assert ! (
3024+ args. windows( 2 )
3025+ . any( |pair| pair == [ "-force_key_frames" , "expr:gte(t,n_forced*1)" ] )
3026+ ) ;
3027+ assert ! (
3028+ args. windows( 2 )
3029+ . any( |pair| pair == [ "-frag_duration" , "1000000" ] )
3030+ ) ;
30073031 assert ! (
30083032 args. iter( )
30093033 . any( |value| value == "+frag_keyframe+empty_moov+default_base_moof" )
@@ -3031,6 +3055,10 @@ mod tests {
30313055 assert ! ( args. windows( 2 ) . any( |pair| pair == [ "-c:v" , "copy" ] ) ) ;
30323056 assert ! ( args. windows( 2 ) . any( |pair| pair == [ "-c:a" , "copy" ] ) ) ;
30333057 assert ! ( !args. iter( ) . any( |value| value == "-vf" ) ) ;
3058+ assert ! (
3059+ args. windows( 2 )
3060+ . any( |pair| pair == [ "-frag_duration" , "1000000" ] )
3061+ ) ;
30343062 }
30353063
30363064 #[ test]
0 commit comments