MPEG video not pausing at accurate timestamp

1

We are using xuggle API to create MP4 file with variable duration between images. Following is the sample code

final com.xuggle.mediatool.IMediaWriter writer = com.xuggle.mediatool.ToolFactory.makeWriter("C:\\Media\\img\\output.mp4");
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, 3840, 2060);
String[] imgFiles = FileUtil.getFiles("chapter1");// List of image filenames

long nextFrameTime = 0;

for(int i=0;i<imgFiles.length();i++)
{
    String fileName = imgFiles[i];
    long delay = ImgUtil.getDelay(fileName);
    nextFrameTime += (delay * 1000);
    videoImage = ImageIO.read(new File("C:\\Media\\img\\img\\"+fileName));
    writer.encodeVideo(0, videoImage,nextFrameTime, TimeUnit.MICROSECONDS);
}

writer.close();

The generated video plays without any issues and the delays between each images as expected however when we pause video it appears it paused but moves to next image.

For example when we pause video at 2rd min it moves to next slide after few secs and its not pausing permanently.

Is there any way i can re-encode video using ffmpeg to fix this issue?

Following is the ffprobe information:

> ffprobe output.mp4 -show_entries frame=key_frame,pkt_pts_time -select_streams v -of compact=p=0

key_frame=1|pkt_pts_time=0.000000
key_frame=0|pkt_pts_time=30.039994
key_frame=0|pkt_pts_time=122.095995
key_frame=0|pkt_pts_time=215.875990
key_frame=0|pkt_pts_time=298.108995
key_frame=0|pkt_pts_time=377.050996
key_frame=0|pkt_pts_time=457.769986
key_frame=0|pkt_pts_time=549.354986
key_frame=0|pkt_pts_time=632.162997
key_frame=0|pkt_pts_time=711.653986
key_frame=0|pkt_pts_time=800.103990
key_frame=0|pkt_pts_time=882.286000
key_frame=1|pkt_pts_time=963.317998
key_frame=0|pkt_pts_time=1051.639994
key_frame=0|pkt_pts_time=1134.159991
key_frame=0|pkt_pts_time=1217.589990
key_frame=0|pkt_pts_time=1302.699992
key_frame=0|pkt_pts_time=1382.899992
key_frame=0|pkt_pts_time=1471.059998
key_frame=0|pkt_pts_time=1556.299992
key_frame=0|pkt_pts_time=1635.629999
key_frame=0|pkt_pts_time=1720.739986
key_frame=0|pkt_pts_time=1817.729992
key_frame=0|pkt_pts_time=1902.109987
key_frame=1|pkt_pts_time=1993.459998
key_frame=0|pkt_pts_time=2090.628992
key_frame=0|pkt_pts_time=2174.539986
key_frame=0|pkt_pts_time=2269.279988
key_frame=0|pkt_pts_time=2357.029999
key_frame=0|pkt_pts_time=2452.429999
key_frame=0|pkt_pts_time=2532.179995
key_frame=0|pkt_pts_time=2614.539986
key_frame=0|pkt_pts_time=2690.719997
key_frame=0|pkt_pts_time=2777.419989
key_frame=0|pkt_pts_time=2868.429999
key_frame=0|pkt_pts_time=2961.759991
key_frame=1|pkt_pts_time=3044.649989
key_frame=0|pkt_pts_time=3134.589990
key_frame=0|pkt_pts_time=3220.479988
key_frame=0|pkt_pts_time=3300.079988
key_frame=0|pkt_pts_time=3379.829999
key_frame=0|pkt_pts_time=3457.699992
key_frame=0|pkt_pts_time=3542.619989
key_frame=0|pkt_pts_time=3623.209995
key_frame=0|pkt_pts_time=3720.569986
key_frame=0|pkt_pts_time=3798.439994
key_frame=0|pkt_pts_time=3878.949996
key_frame=0|pkt_pts_time=3968.969986
key_frame=1|pkt_pts_time=4064.179995

ram4sof

Posted 2018-10-24T02:02:47.693

Reputation: 21

Hmm, I wonder if your player only likes pausing at keyframes, and since this is a slideshow of still images, the keyframes only happen when a new picture appears. If so, you might be able to work around this by using a player that can pause on non-keyframes, or by generating the video in such a way that there is more than one keyframe per still image. – Spiff – 2018-10-24T03:19:10.317

Thank you for responding, how can i generate the video with more than one keyframe per still image using ffmpeg? – ram4sof – 2018-10-24T03:47:59.063

This looks to be player related. Try another player. Which player? – Gyan – 2018-10-24T05:10:53.293

The issue persists when i upload to google drive and in Windows media player, it plays properly in VLC Player, My main requirement is to play in google drive for sharing purpose – ram4sof – 2018-10-24T11:12:08.087

Answers

1

My problem is resolved, i have re-encoded with avcon tool (wasted lot of time trying with ffmpeg). The only issue is the encoding takes about 40mins for 1.50min video.

avconv -i output.mp4 -vcodec libx264 -crf 27 -preset veryfast -c:a copy -s 3840x2060 fixed_keyframe_output.mp4

ram4sof

Posted 2018-10-24T02:02:47.693

Reputation: 21