没有合适的资源?快使用搜索试试~ 我知道了~
ffmpeg 文件合并的代码跟踪分析
3星 · 超过75%的资源 需积分: 9 16 下载量 84 浏览量
2012-01-13
14:31:47
上传
评论
收藏 101KB DOC 举报
温馨提示
试读
14页
跟踪ffmpeg文件流合并时的工作流程。主要解析了stream_maps结构,opt_input_file函数如何构建input_files流数组;opt_output_file函数从stream_maps结构信息如何构建输出流
资源推荐
资源详情
资源评论
1、跟踪命令
ffmpeg -i 1.asf -i 2.asf -map 0:a:0 -map 1:a:0 -map 0:v:0 -map
1:v:0 -acodec copy -vcodec copy 121.asf
2、跟踪结果
2.1 o->stream_maps 的内容
2.2 opt_input_file 函数入口
2.2.1 函数原型
2.2.2 跟踪结果
1
o->stream_maps[0] = {disabled = 0, file_index = 0, stream_index = 0, sync_file_index = 0, sync_stream_index = 0}
o->stream_maps[1] = {disabled = 0, file_index = 1, stream_index = 0, sync_file_index = 1, sync_stream_index = 0}
o->stream_maps[2] = {disabled = 0, file_index = 0, stream_index = 1, sync_file_index = 0, sync_stream_index = 1}
o->stream_maps[3] = {disabled = 0, file_index = 1, stream_index = 1, sync_file_index = 1, sync_stream_index = 1}
opt_input_file(OptionsContext *o, const char *opt const char *filename)
opt_input_file (o=0xbfffbb48, opt=0xbfffd861 "i", filename=0xbfffd863 "1.asf")
input_files[0].ist_index = nb_input_streams - ic->nb_streams; (3 – 3 = 0)
input_files[0].nb_streams = 3
opt_input_file (o=0xbfffbb48, opt=0xbfffd86a "i", filename=0xbfffd86c "2.asf")
input_files[1].ist_index = nb_input_streams - ic->nb_streams;(6-3 = 3)
input_files[1].nb_streams = 3
2.3 opt_output_file 函数入口
2.3.1 函数原型
2.3.2 跟踪结果
2
void opt_output_file(void *optctx, const char *filename)
opt_output_file (optctx=0xbfffbb48, filename=0xbfffd8b8 "121.asf")
{
avformat_alloc_output_context2(&oc, NULL, o->format, "121.asf");
得到 o->format 的内容为:
{name = 0x863b442 "asf", long_name = 0x863b446 "ASF format",
mime_type = 0x863b451 "video/x-ms-asf",
extensions = 0x863b460 "asf,wmv,wma", priv_data_size = 149804,
audio_codec = CODEC_ID_MP2, video_codec = CODEC_ID_MSMPEG4V3,
write_header = 0x8096793 <asf_write_header>,
write_packet = 0x8097043 <asf_write_packet>,
write_trailer = 0x809750b <asf_write_trailer>, flags = 64, dummy = 0x0,
interleave_packet = 0, codec_tag = 0x87a1430,
subtitle_codec = CODEC_ID_NONE, metadata_conv = 0x0, priv_class = 0x0,
query_codec = 0, get_output_timestamp = 0, next = 0x87a1500}
if (!strcmp(file_oformat->name, "ffm")
{ //写入 server}
else if (!o->nb_stream_maps) // stream_maps 数组为空
{ //选择最佳的媒体流
// 对于音频流最佳准则为信道数最多的音频流
// 对于字幕流为第一个字幕流
// 对于视频流最佳准则为分辨率最大的视频流
}
else{ // stream_maps 数组不为空
for (i = 0; i < o->nb_stream_maps; i++) {
StreamMap *map = &o->stream_maps[i];
ist = &input_streams[input_files[map->file_index].ist_index +
map->stream_index];
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
...
ost->source_index = input_files[map->file_index].ist_index +
map->stream_index;
ost->sync_ist =
&input_streams[input_files[map->sync_file_index].ist_index +
map->sync_stream_index];
ist->discard = 0;
}
3
当 stream_maps 数组不为空时的迭代
第一次迭代: i=0
StreamMap *map = &o->stream_maps[0];
//{disabled = 0, file_index = 0, stream_index = 0, sync_file_index = 0, sync_stream_index = 0}
ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
//由于 map->file_index=0,input_files[0].ist_index=0,map->stream_index=0
//因此 ist = &input_streams[0]
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
//由于 map->file_index 为 0,input_files[0].ist_index 为 0,map->stream_index 同样也为 0,
//因此 ost->source_index 为 0
ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
map->sync_stream_index];
//由于 sync_file_index 为 0,input_files[0].ist_index 为 0,map->sync_stream_index 同样也为 0,
//因此 ost->sync_ist = &input_streams[0]
ist->discard = 0;
第二次迭代
StreamMap *map = &o->stream_maps[1];
//map={disabled = 0, file_index = 1, stream_index = 0, sync_file_index = 1, sync_stream_index = 0}
ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
//由于 map->file_index=1,input_files[1].ist_index=3,map->stream_index=0
//因此 ist = &input_streams[3]
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
//由于 map->file_index=1,input_files[1].ist_index=3,map->stream_index=0
// ost->source_index == 3
ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index
+map->sync_stream_index];
//由于 map->sync_file_index == 1,input_files[1].ist_index == 3,map->sync_stream_index==0
//因此 ost->sync_ist = &input_streams[3]
ist->discard = 0;
剩余13页未读,继续阅读
georg
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页