您当前的位置: 首页 > 

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ffmpeg如何存储hls文件

qianbo_insist 发布时间:2022-01-25 15:23:02 ,浏览量:0

目标 生成mp4文件和hls文件

除了生成mp4,我们平台的目标还要能生成hls文件 在生成context的时候,看是否要生成hls文件,里面比较重要的是,要控制hls_time参数,以便于按照时间间隔生成ts文件

show me the code
int Mp4WrapperLocal::Create(const char *fileName, TFileFormat *param)
{
	Close();
	//video_st.dlen = 0;
	//audio_st.dlen = 0;
	_pts = 0;
	_firstRecordPts = 0;
	_sample_count = 1024; //1024 是默认值,注意后面会自动修改//param->sample_count;
	//audio_st.samples_count = 0;
	videofps = param->fps;

	if (param->m3u8 == 1) {
		//ffmpeg - re - i source.mp4 - codec:v libx264 - codec : a libfaac - map 0 - f hls - hls_list_size 6 - hls_wrap 10 - hls_time 10 playlist.m3u8
		avformat_alloc_output_context2(&oc, NULL, "hls", fileName);

		av_opt_set(oc->priv_data, "hls_time", "5", AV_OPT_SEARCH_CHILDREN);
		//av_opt_set(oc->priv_data, "hls_list_size" ,"0" , AV_OPT_SEARCH_CHILDREN);
		av_opt_set(oc->priv_data, "hls_wrap", "5", AV_OPT_SEARCH_CHILDREN);

	}
	else {
		avformat_alloc_output_context2(&oc, NULL, NULL, fileName);
	}


	if (!oc)
		return 1;



	/* Add the audio and video streams using the default format codecs
	* and initialize the codecs. */
	_have_video = param->haveVideo;
	if (_have_video == 1)
		add_video_stream( oc->oformat->video_codec, param);
	_have_audio = param->haveAudio;
	if (_have_audio == 1)
	{
		add_audio_stream(oc->oformat->audio_codec, NULL);
	}
	else
		oc->oformat->audio_codec = AV_CODEC_ID_NONE;
	int ret = -1;
	/* open the output file, if needed */
	if (!(oc->oformat->flags & AVFMT_NOFILE)) {
		ret = avio_open(&oc->pb, fileName,  AVIO_FLAG_WRITE);
		if (ret             
关注
打赏
1663161521
查看更多评论
0.0381s