Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

请问,通过recordPacket对mp4文件进行hls切片,切片后ts文件数量正常,但是m3u8文件里每片的时长不对 #6

Open
bug-rabbit opened this issue Jul 26, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@bug-rabbit
Copy link

bug-rabbit commented Jul 26, 2019

hls切片时间设置的是5s,一个29s的mp4视频,切片后,切片数量是5 正常,也能正常播放,但是m3u8文件里每片时长只有1s左右,导致播放器显示的总时长不对:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:0.766667,
out0.ts
#EXTINF:0.644444,
out1.ts
#EXTINF:1.016667,
out2.ts
#EXTINF:0.416667,
out3.ts
#EXTINF:1.288889,
out4.ts
#EXT-X-ENDLIST

以下是代码
`public static void packetRecord(String inputFile, String outputFile) throws FrameGrabber.Exception, FrameRecorder.Exception {

    FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
    FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, 1280, 720, 2);

    grabber.start();
    
    recorder.setOption("hls_list_size", "0");
    recorder.setOption("hls_time", "5");
    recorder.start(grabber.getFormatContext());

    AVPacket packet;

    while ((packet = grabber.grabPacket()) != null) {
        recorder.recordPacket(packet);

    }

    recorder.stop();
    grabber.stop();
}`

packetRecord("F:\\beixiyan.mp4","out.m3u8");

请问该如何避免该问题,万分感谢

@eguid
Copy link
Owner

eguid commented Aug 30, 2019

这个问题似乎已经在群里解决了?

@eguid eguid added the bug Something isn't working label Aug 30, 2019
@bug-rabbit
Copy link
Author

@eguid 没有,还是有问题,mp4转hls,时长还是不对,1.4.3 1.4.4都有这个问题。hls转hls提示长宽比不对,即便传入源视频的长宽也会报这个问题,但是如果长宽都传0,则不会报这个问题,不过切出来的ts文件只有声音,没有画面

@eguid
Copy link
Owner

eguid commented Aug 30, 2019

ok,那就是现在时间戳问题已经解决了,但是又出现了“长宽”不一致导致报错的问题,是吗?
我会检查一下看是不是类型转换的问题

@bug-rabbit
Copy link
Author

时间戳的问题还存在,mp4转hls,m3u8文件里每片的时长还是有问题,小很多。

@bug-rabbit
Copy link
Author

只有hls转hls才会存在长宽比不一致的问题,mp4转hls 没有长宽比不一致问题,以上问题都是使用recordPacket才出现的问题

@eguid
Copy link
Owner

eguid commented Aug 30, 2019

嗯,也就是说只有再hls转hls才会出现长宽不一致的问题,MP4转hls会出现持续时间不一致的问题,但是并不影响实际播放,对吗?

@bug-rabbit
Copy link
Author

是的,hls转hls会报长宽不一致的错误;
MP4转hls时,转换后的m3u8文件里每片时长要比实际设置的小很多,但是切出来的ts视频文件时长是对的,在播放器里播放也正常,只是播放器显示的总时长不对,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants