searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

ffmpeg.autogen下载码流浅析

2024-09-04 09:42:22
9
0

完整的核心函数示例如下:

public int AddStream(AVStream* in_stream, bool isAudioDemuxer = false)
{
	int ret = -1;
	if (in_stream == null || (in_stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO && in_stream->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)) return ret;
	AVStream *out_stream;
	var in_codecpar = in_stream->codecpar;
	out_stream = avformat_new_stream(fmtCtx, null);
	if (out_stream == null) return -1;
	ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar);
	if (ret < 0) return ret;
	AVDictionaryEntry* b = null;
	while (true)
	{
		b = av_dict_get(in_stream->metadata, "", b, AV_DICT_IGNORE_SUFFIX);
		if (b == null) break;
		if (Utils.BytePtrToStringUTF8(b->key).ToLower() == "language" || Utils.BytePtrToStringUTF8(b->key).ToLower() == "lang")
			av_dict_set(&out_stream->metadata, Utils.BytePtrToStringUTF8(b->key), Utils.BytePtrToStringUTF8(b->value), 0);
	}
	out_stream->codecpar->codec_tag = 0;	
	if (isAudioDemuxer)
	{
		mapInOutStreams2.Add((IntPtr)in_stream, (IntPtr)out_stream);
		mapInInStream2.Add(in_stream->index, (IntPtr)in_stream);
	}
	else
	{
		mapInOutStreams.Add((IntPtr)in_stream, (IntPtr)out_stream);
		mapInInStream.Add(in_stream->index, (IntPtr)in_stream);
	}
	return 0;
}

avformat_new_stream:Add a new stream to a media file.

avcodec_parameters_copy:ccopy the contents of src to dst any allocated fields in dst are freed and replaced with newly allocated duplicates of the corresponding fields in src.

av_dict_get:Get a dictionary entry with matching key.

av_dict_set:Set the given entry in *pm, overwriting an existing entry.

0条评论
0 / 1000
潇洒的柚子
4文章数
0粉丝数
潇洒的柚子
4 文章 | 0 粉丝
原创

ffmpeg.autogen下载码流浅析

2024-09-04 09:42:22
9
0

完整的核心函数示例如下:

public int AddStream(AVStream* in_stream, bool isAudioDemuxer = false)
{
	int ret = -1;
	if (in_stream == null || (in_stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO && in_stream->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)) return ret;
	AVStream *out_stream;
	var in_codecpar = in_stream->codecpar;
	out_stream = avformat_new_stream(fmtCtx, null);
	if (out_stream == null) return -1;
	ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar);
	if (ret < 0) return ret;
	AVDictionaryEntry* b = null;
	while (true)
	{
		b = av_dict_get(in_stream->metadata, "", b, AV_DICT_IGNORE_SUFFIX);
		if (b == null) break;
		if (Utils.BytePtrToStringUTF8(b->key).ToLower() == "language" || Utils.BytePtrToStringUTF8(b->key).ToLower() == "lang")
			av_dict_set(&out_stream->metadata, Utils.BytePtrToStringUTF8(b->key), Utils.BytePtrToStringUTF8(b->value), 0);
	}
	out_stream->codecpar->codec_tag = 0;	
	if (isAudioDemuxer)
	{
		mapInOutStreams2.Add((IntPtr)in_stream, (IntPtr)out_stream);
		mapInInStream2.Add(in_stream->index, (IntPtr)in_stream);
	}
	else
	{
		mapInOutStreams.Add((IntPtr)in_stream, (IntPtr)out_stream);
		mapInInStream.Add(in_stream->index, (IntPtr)in_stream);
	}
	return 0;
}

avformat_new_stream:Add a new stream to a media file.

avcodec_parameters_copy:ccopy the contents of src to dst any allocated fields in dst are freed and replaced with newly allocated duplicates of the corresponding fields in src.

av_dict_get:Get a dictionary entry with matching key.

av_dict_set:Set the given entry in *pm, overwriting an existing entry.

文章来自个人专栏
流媒体技术
4 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0