- 改造ffmpeg/doc/examples/remuxing.c,支持将输入流转封装为hls协议
- 对应的github地址:GitHub - yagerfgcs/FFmpeg at examples/remuxing_support_hls
- 修改点:增加设置hls头
c
// example:https://www.ffmpeg.org/ffmpeg-all.html#hls-2
// ffmpeg -i rtmp://xx/livestream -c copy -hls_time 5 -hls_list_size 0 -start_number 1
// -hls_segment_filename /xxdir/test_%Y-%m-%d-%H-%M-%S_%%08t_%%04d.ts /xxdir/test.m3u8
static int write_hls_header(const char* out_filename, AVFormatContext* context) {
AVDictionary *options = NULL;
av_dict_set(&options, "hls_time", "5", 0);
av_dict_set(&options, "hls_list_size", "0", 0);
av_dict_set(&options, "start_number", "1", 0);
av_dict_set(&options, "strftime", "1", 0);
av_dict_set(&options, "hls_flags",
"second_level_segment_duration+second_level_segment_index", 0);
char hls_segment_filename[1024];
memset(hls_segment_filename, 0, 1024);
sprintf(hls_segment_filename, "%s/%s", av_dirname(out_filename), "%Y-%m-%d-%H-%M-%S_%%08t_%%04d.ts");
av_dict_set(&options, "hls_segment_filename", hls_segment_filename, 0);
return avformat_write_header(context, options != NULL ? &options : NULL);
}