ffmpeg 4.1 not setting i-frame/keyframe on start of segment












0















I'm trying to build a few automation scripts to transcode videos using ffmpeg and I'm the keyframes end up in the wrong places when the format is set to HLS. This happens with different sources (one for example a 4k rendition of Big Buck Bunny). I'm using a static compiled version of ffmpeg 4.1 from John Vansickle.



When I transcode to mp4/h264, the keyframes are in the expected timecode (every 2 seconds). This is the command I run:



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high 
-level 4.1 -crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2)"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k video-360p.mp4
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k video-480p.mp4
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 96k video-720p.mp4


And the command I run to see the keyframes is



 ffprobe -v error -skip_frame nokey -show_entries frame=pkt_pts_time 
-select_streams v -of csv=p=0 video-360p.mp4


which outputs



0.000000
2.000000
4.000000
[...]


When I transcode the same video to ts/x264 (HLS) the keyframes are shifted by 1.466 seconds. This is the command I'm using (the same issue happens if the output is segmented rather than in one file)



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high -level 4.1 
-crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2) -hls_time 6
-hls_playlist_type vod -hls_flags single_file"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k
-hls_segment_filename "video-360p.ts" video-360p.m3u8
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k
-hls_segment_filename "video-480p.ts" video-480p.m3u8
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 64k
-hls_segment_filename "video-720p.ts" video-720p.m3u8


And run ffprobe on any of the ts files, I get the following timecodes for the keyframes:



1.466667
3.466667
5.466667
[...]


when I play any of the ts files the first 1.46 second the image is frozen.



I'm wondering if anyone could help me figure out what's going on and how to fix this.










share|improve this question


















  • 1





    TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

    – Gyan
    Jan 14 at 15:30











  • @Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

    – Augusto
    Jan 15 at 3:28













  • The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

    – Gyan
    Jan 15 at 4:19











  • Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

    – Augusto
    Jan 15 at 5:04













  • This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

    – Augusto
    Jan 15 at 5:42


















0















I'm trying to build a few automation scripts to transcode videos using ffmpeg and I'm the keyframes end up in the wrong places when the format is set to HLS. This happens with different sources (one for example a 4k rendition of Big Buck Bunny). I'm using a static compiled version of ffmpeg 4.1 from John Vansickle.



When I transcode to mp4/h264, the keyframes are in the expected timecode (every 2 seconds). This is the command I run:



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high 
-level 4.1 -crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2)"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k video-360p.mp4
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k video-480p.mp4
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 96k video-720p.mp4


And the command I run to see the keyframes is



 ffprobe -v error -skip_frame nokey -show_entries frame=pkt_pts_time 
-select_streams v -of csv=p=0 video-360p.mp4


which outputs



0.000000
2.000000
4.000000
[...]


When I transcode the same video to ts/x264 (HLS) the keyframes are shifted by 1.466 seconds. This is the command I'm using (the same issue happens if the output is segmented rather than in one file)



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high -level 4.1 
-crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2) -hls_time 6
-hls_playlist_type vod -hls_flags single_file"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k
-hls_segment_filename "video-360p.ts" video-360p.m3u8
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k
-hls_segment_filename "video-480p.ts" video-480p.m3u8
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 64k
-hls_segment_filename "video-720p.ts" video-720p.m3u8


And run ffprobe on any of the ts files, I get the following timecodes for the keyframes:



1.466667
3.466667
5.466667
[...]


when I play any of the ts files the first 1.46 second the image is frozen.



I'm wondering if anyone could help me figure out what's going on and how to fix this.










share|improve this question


















  • 1





    TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

    – Gyan
    Jan 14 at 15:30











  • @Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

    – Augusto
    Jan 15 at 3:28













  • The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

    – Gyan
    Jan 15 at 4:19











  • Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

    – Augusto
    Jan 15 at 5:04













  • This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

    – Augusto
    Jan 15 at 5:42
















0












0








0








I'm trying to build a few automation scripts to transcode videos using ffmpeg and I'm the keyframes end up in the wrong places when the format is set to HLS. This happens with different sources (one for example a 4k rendition of Big Buck Bunny). I'm using a static compiled version of ffmpeg 4.1 from John Vansickle.



When I transcode to mp4/h264, the keyframes are in the expected timecode (every 2 seconds). This is the command I run:



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high 
-level 4.1 -crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2)"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k video-360p.mp4
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k video-480p.mp4
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 96k video-720p.mp4


And the command I run to see the keyframes is



 ffprobe -v error -skip_frame nokey -show_entries frame=pkt_pts_time 
-select_streams v -of csv=p=0 video-360p.mp4


which outputs



0.000000
2.000000
4.000000
[...]


When I transcode the same video to ts/x264 (HLS) the keyframes are shifted by 1.466 seconds. This is the command I'm using (the same issue happens if the output is segmented rather than in one file)



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high -level 4.1 
-crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2) -hls_time 6
-hls_playlist_type vod -hls_flags single_file"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k
-hls_segment_filename "video-360p.ts" video-360p.m3u8
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k
-hls_segment_filename "video-480p.ts" video-480p.m3u8
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 64k
-hls_segment_filename "video-720p.ts" video-720p.m3u8


And run ffprobe on any of the ts files, I get the following timecodes for the keyframes:



1.466667
3.466667
5.466667
[...]


when I play any of the ts files the first 1.46 second the image is frozen.



I'm wondering if anyone could help me figure out what's going on and how to fix this.










share|improve this question














I'm trying to build a few automation scripts to transcode videos using ffmpeg and I'm the keyframes end up in the wrong places when the format is set to HLS. This happens with different sources (one for example a 4k rendition of Big Buck Bunny). I'm using a static compiled version of ffmpeg 4.1 from John Vansickle.



When I transcode to mp4/h264, the keyframes are in the expected timecode (every 2 seconds). This is the command I run:



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high 
-level 4.1 -crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2)"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k video-360p.mp4
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k video-480p.mp4
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 96k video-720p.mp4


And the command I run to see the keyframes is



 ffprobe -v error -skip_frame nokey -show_entries frame=pkt_pts_time 
-select_streams v -of csv=p=0 video-360p.mp4


which outputs



0.000000
2.000000
4.000000
[...]


When I transcode the same video to ts/x264 (HLS) the keyframes are shifted by 1.466 seconds. This is the command I'm using (the same issue happens if the output is segmented rather than in one file)



ffmpegparams="-c:a aac -ar 22050 -c:v libx264 -profile:v high -level 4.1 
-crf 20 -r 30 -g 180 -keyint_min 30
-force_key_frames expr:gte(t,n_forced*2) -hls_time 6
-hls_playlist_type vod -hls_flags single_file"
ffmpeg -hide_banner -y -i video.mp4
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 400k -maxrate 428k -bufsize 600k -b:a 64k
-hls_segment_filename "video-360p.ts" video-360p.m3u8
-vf scale=w=854:h=480:force_original_aspect_ratio=increase $ffmpegparams
-b:v 600k -maxrate 652k -bufsize 900k -b:a 64k
-hls_segment_filename "video-480p.ts" video-480p.m3u8
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease $ffmpegparams
-b:v 1000k -maxrate 1070k -bufsize 1500k -b:a 64k
-hls_segment_filename "video-720p.ts" video-720p.m3u8


And run ffprobe on any of the ts files, I get the following timecodes for the keyframes:



1.466667
3.466667
5.466667
[...]


when I play any of the ts files the first 1.46 second the image is frozen.



I'm wondering if anyone could help me figure out what's going on and how to fix this.







ffmpeg video-conversion






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 14 at 11:53









AugustoAugusto

1295




1295








  • 1





    TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

    – Gyan
    Jan 14 at 15:30











  • @Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

    – Augusto
    Jan 15 at 3:28













  • The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

    – Gyan
    Jan 15 at 4:19











  • Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

    – Augusto
    Jan 15 at 5:04













  • This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

    – Augusto
    Jan 15 at 5:42
















  • 1





    TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

    – Gyan
    Jan 14 at 15:30











  • @Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

    – Augusto
    Jan 15 at 3:28













  • The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

    – Gyan
    Jan 15 at 4:19











  • Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

    – Augusto
    Jan 15 at 5:04













  • This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

    – Augusto
    Jan 15 at 5:42










1




1





TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

– Gyan
Jan 14 at 15:30





TS files, by default, have a timestamp offset of 1.4s. So this is expected. How are you checking for the freeze?

– Gyan
Jan 14 at 15:30













@Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

– Augusto
Jan 15 at 3:28







@Gyan thanks for the info. I'm just playing the file in VLC, and the other consequence is that then I skip to an even second using a web player (videojs) the image freezes for a second before playback resumes. This doesn't happen as bad if I skip to an odd second. Do you happen to know then how HLS works? as the first frame of a segment should be a keyframe, but you are saying that keyframes are shifted 1.4 seconds...

– Augusto
Jan 15 at 3:28















The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

– Gyan
Jan 15 at 4:19





The 'position' of the KF hasn't changed. All timestamps have the offset added. You can override the default by adding -muxdelay 0 -muxpreload 0.

– Gyan
Jan 15 at 4:19













Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

– Augusto
Jan 15 at 5:04







Thanks Gyan! Just to add some confusion, I just downloaded a test file from the apple dev streaming site and it shows the same behaviour in vlc (video stuck for about a second, while audio plays). I think I need to RTFM of ts :).

– Augusto
Jan 15 at 5:04















This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

– Augusto
Jan 15 at 5:42







This was actually a non-issue, but I got confused after all the tests I've been doing as some of them had weird GOPs and keyframe intervals. VLC for some odd reason takes a moment to start playing the video (while audio does play) on a properly encoded ts file. But playing the same ts files in videojs doesn't display this behaviour at all. Thanks a lot @Gyan , your comment made me doubt what I had tried before and to re-test it.

– Augusto
Jan 15 at 5:42












0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1394089%2fffmpeg-4-1-not-setting-i-frame-keyframe-on-start-of-segment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1394089%2fffmpeg-4-1-not-setting-i-frame-keyframe-on-start-of-segment%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?