![MPEG 视频未在准确的时间戳处暂停](https://linux22.com/image/1573384/MPEG%20%E8%A7%86%E9%A2%91%E6%9C%AA%E5%9C%A8%E5%87%86%E7%A1%AE%E7%9A%84%E6%97%B6%E9%97%B4%E6%88%B3%E5%A4%84%E6%9A%82%E5%81%9C.png)
我们使用 xuggle API 创建图像间持续时间可变的 MP4 文件。以下是示例代码
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();
生成的视频播放时没有任何问题,并且每个图像之间的延迟符合预期,但是当我们暂停视频时,它似乎暂停了,但移动到下一个图像。
例如,当我们在第二分钟暂停视频时,它会在几秒钟后移动到下一张幻灯片,并且不会永久暂停。
有什么方法可以使用 ffmpeg 重新编码视频来解决这个问题?
以下是ffprobe信息:
> 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
答案1
我的问题解决了,我已经用 avcon 工具重新编码了(用 ffmpeg 尝试时浪费了很多时间)。唯一的问题是 1.50 分钟的视频编码大约需要 40 分钟。
avconv -i output.mp4 -vcodec libx264 -crf 27 -preset veryfast -c:a copy -s 3840x2060 fixed_keyframe_output.mp4