首页 > 解决方案 > 使用ffmpeg指定绝对hls_fmp4_init_filename时如何修复m3u8中的EXT-X-MAP:URI?

问题描述

今天我发现这篇博文教我关于碎片化的 mp4s (fmp4s)。

使用ffmpeg 文档,我取得了很大的进步。

我运行这个:

'/usr/bin/ffmpeg' '-y' '-i' '/myproject/storage/app/sample_media/2020-02-27/Sample Videos 5.mp4' \
'-c:v' 'libx264' '-s:v' '1920x1080' \
 '-crf' '20' '-sc_threshold' '0' '-g' '48' '-keyint_min' '48' \
'-hls_list_size' '0' '-hls_time' '10' '-hls_allow_cache' '0' '-b:v' '4889k' \
'-maxrate' '5866k' '-hls_segment_type' 'fmp4' \
'-hls_fmp4_init_filename' '/myproject/public/storage/000000002/init.mp4' \
'-hls_segment_filename' '/myproject/public/storage/000000002/list_1080p_%04d.m4s' \
'-hls_key_info_file' '/myproject/hls_hls.keyInfo' '-strict' '-2' '-threads' '12' \
'/myproject/public/storage/000000002/list_1080p.m3u8'

然后我在我的网页上使用hls.js来尝试显示视频。

最初,它不会加载。

但是,如果在对 list_1080p.m3u8 进行此编辑后刷新页面,我可以正确加载视频:

更改自:

#EXT-X-MAP:URI="/myproject/public/storage/000000002/init.mp4"

至:

#EXT-X-MAP:URI="init.mp4"

如何更改我的 ffmpeg 命令,以便它知道保存 init.mp4 的绝对路径,但也知道在 m3u8 中只写入init.mp4没有任何路径的文件名?

(我试过-hls_fmp4_init_filename init.mp4在没有绝对路径的情况下使用,但是它会在根目录下创建 init.mp4,这也不起作用。我需要每个视频的 init.mp4 都在它自己的文件夹中。)

标签: ffmpegmp4http-live-streamingffmpeg-phpfmp4

解决方案


推荐阅读