最新版ffmpeg源码分析三transcodeWord文件下载.docx
- 文档编号:6871943
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:6
- 大小:18.27KB
最新版ffmpeg源码分析三transcodeWord文件下载.docx
《最新版ffmpeg源码分析三transcodeWord文件下载.docx》由会员分享,可在线阅读,更多相关《最新版ffmpeg源码分析三transcodeWord文件下载.docx(6页珍藏版)》请在冰点文库上搜索。
(oc-&
oformat-&
flags&
AVFMT_NOSTREAMS)){av_dump_format(oc,i,oc-&
filename,1);
av_log(NULL,AV_LOG_ERROR,"
Outputfile#%ddoesnotcontainanystream\n"
i);
returnAVERROR(EINVAL);
}}//轮循所有的输出流,跟据对应的输入流,设置其编解码器的参数for(i=0;
nb_output_streams;
i++){//轮循所有的输出流ost=&
output_streams[i];
//输出流对应的FormatContextoc=output_files[ost-&
file_index].ctx;
//取得输出流对应的输入流ist=&
input_streams[ost-&
source_index];
//attachment_filename是不是这样的东西:
一个文件,它单独容纳一个输出流?
此处不懂if(ost-&
attachment_filename)continue;
codec=ost-&
st-&
codec;
//输出流的编解码器结构icodec=ist-&
//输入流的编解码器结构//先把能复制的复制一下ost-&
disposition=ist-&
disposition;
codec-&
bits_per_raw_sample=icodec-&
bits_per_raw_sample;
chroma_sample_location=icodec-&
chroma_sample_location;
//如果只是复制一个流(不用解码后再编码),则把输入流的编码参数直接复制给输出流//此时是不需要解码也不需要编码的,所以不需打开解码器和编码器if(ost-&
stream_copy){//计算输出流的编解码器的extradata的大小,然后分配容纳extradata的缓冲//然后把输入流的编解码器的extradata复制到输出流的编解码器中uint64_textra_size=(uint64_t)icodec-&
extradata_size+FF_INPUT_BUFFER_PADDING_SIZE;
if(extra_size&
INT_MAX){returnAVERROR(EINVAL);
}/*ifstream_copyisselected,noneedtodecodeorencode*/codec-&
codec_id=icodec-&
codec_id;
codec_type=icodec-&
codec_type;
codec-&
codec_tag){if(!
codec_tag||av_codec_get_id(oc-&
codec_tag,icodec-&
codec_tag)==codec-&
codec_id||av_codec_get_tag(oc-&
codec_id)&
=0)codec-&
codec_tag=icodec-&
codec_tag;
}codec-&
bit_rate=icodec-&
bit_rate;
rc_max_rate=icodec-&
rc_max_rate;
rc_buffer_size=icodec-&
rc_buffer_size;
extradata=av_mallocz(extra_size);
extradata){returnAVERROR(ENOMEM);
}memcpy(codec-&
extradata,icodec-&
extradata_size);
extradata_size=icodec-&
extradata_size;
//重新鼓捣一下timebase(这家伙就是帧率)codec-&
time_base=ist-&
time_base;
//如果输出文件是avi,做一点特殊处理if(!
strcmp(oc-&
name,"
avi"
)){if(copy_tb&
0&
av_q2d(icodec-&
time_base)*icodec-&
ticks_per_frame&
2*av_q2d(ist-&
time_base)&
av_q2d(ist-&
1.0/500||copy_tb==0){codec-&
time_base=icodec-&
time_base.num*=icodec-&
ticks_per_frame;
time_base.den*=2;
}}elseif(!
AVFMT_VARIABLE_FPS)){if(copy_tb&
}}//再修正一下帧率av_reduce(&
time_base.num,&
time_base.den,codec-&
time_base.num,codec-&
time_base.den,INT_MAX);
//单独复制各不同媒体自己的编码参数switch(codec-&
codec_type){caseAVMEDIA_TYPE_AUDIO:
//音频的if(audio_volume!
=256){av_log(NULL,AV_LOG_FATAL,"
-acodeccopyand-volareincompatible(framesarenotdecoded)\n"
);
exit_program
(1);
channel_layout=icodec-&
channel_layout;
sample_rate=icodec-&
sample_rate;
channels=icodec-&
channels;
frame_size=icodec-&
frame_size;
audio_service_type=icodec-&
audio_service_type;
block_align=icodec-&
block_align;
break;
caseAVMEDIA_TYPE_VIDEO:
//视频的codec-&
pix_fmt=icodec-&
pix_fmt;
width=icodec-&
width;
height=icodec-&
height;
has_b_frames=icodec-&
has_b_frames;
sample_aspect_ratio.num){codec-&
sample_aspect_ratio=ost-&
sample_aspect_ratio=ist-&
sample_aspect_ratio.num?
ist-&
sample_aspect_ratio:
ist-&
(AVRational){0,1};
}ost-&
avg_frame_rate=ist-&
avg_frame_rate;
caseAVMEDIA_TYPE_SUBTITLE:
//字幕的codec-&
caseAVMEDIA_TYPE_DATA:
caseAVMEDIA_TYPE_ATTACHMENT:
//?
?
的break;
default:
abort();
}}else{//如果不是复制,就麻烦多了//获取编码器if(!
ost-&
enc)ost-&
enc=avcodec_find_encoder(ost-&
codec_id);
//因为需要转换,所以既需解码又需编码ist-&
decoding_needed=1;
ost-&
encoding_needed=1;
switch(codec-&
//鼓捣音频编码器的参数,基本上是把一些不合适的参数替换掉ost-&
fifo=av_fifo_alloc(1024);
//音频数据所在的缓冲if(!
fifo){returnAVERROR(ENOMEM);
}//采样率if(!
sample_rate)codec-&
choose_sample_rate(ost-&
st,ost-&
enc);
time_base=(AVRational){1,codec-&
sample_rate};
//样点格式if(codec-&
sample_fmt==AV_SAMPLE_FMT_NONE)codec-&
sample_fmt=icodec-&
sample_fmt;
choose_sample_fmt(ost-&
//声道if(ost-&
audio_channels_mapped){/*therequestedoutputchannelissettothenumberof*-map_channelonlyifno-acarespecified*/if(!
channels){codec-&
channels=ost-&
audio_channels_mapped;
channel_layout=av_get_default_channel_layout(codec-&
channels);
channel_layout){av_log(NULL,AV_LOG_FATAL,"
Unabletofindanappropriatechannellayoutforrequestednumberofchannel\n);
}}/*fillunusedchannelmappingwith-1(whichmeansamuted*channelincasethenumberofoutputchannelsisbigger*thanthenumberofmappedchannel)*/for(j=ost-&
FF_ARRAY_ELEMS(ost-&
audio_channels_map);
j++)&
span&
&
/span&
audio_channels_map[j]=-1;
}elseif(!
channels){codec-&
}if(av_get_channel_layout_nb_channels(codec-&
channel_layout)!
=codec-&
channels)codec-&
channel_layout=0;
//是否需要重采样ost-&
audio_resample=codec-&
sample_rate!
=icodec-&
sample_rate||audio_sync_method&
1;
audio_resample|=codec-&
sample_fmt!
sample_fmt||codec-&
channel_layout!
icodec-&
request_channels=codec-&
resample_sample_fmt=icodec-&
resample_sample_rate=icodec-&
resample_channels=icodec-&
//鼓捣视频编码器的参数,基本上是把一些不合适的参数替换掉if(codec-&
pix_fmt==PIX_FMT_NONE)codec-&
choose_pixel_fmt(ost-&
if(ost-&
pix_fmt==PIX_FMT_NONE){av_log(NULL,AV_LOG_FATAL,"
Videopixelformatisunknown,streamcannotbeencoded\n"
}//宽高if(!
width||!
height){codec-&
}//视频是否需要重采样ost-&
video_resample=codec-&
width!
width||codec-&
height!
height||codec-&
pix_fmt!
video_resample){codec-&
bits_per_raw_sample=frame_bits_per_raw_sample;
resample_height=icodec-&
resample_width=icodec-&
resample_pix_fmt=icodec-&
//计算帧率if(!
frame_rate.num)ost-&
frame_rate=ist-&
r_frame_rate.num?
r_frame_rate:
(AVRational){25,1};
enc&
enc-&
supported_framerates&
force_fps){intidx=av_find_nearest_q_idx(ost-&
frame_rate,ost-&
supported_framerates);
frame_rate=ost-&
supported_framerates[idx];
time_base=(AVRational){ost-&
frame_rate.den,ost-&
frame_rate.num};
if(av_q2d(codec-&
0.001&
video_sync_method&
(video_sync_method==1||(video_sync_method&
0&
(oc-&
AVFMT_VARIABLE_FPS)))){av_log(oc,AV_LOG_WARNING,"
Framerateveryhighforamuxernoteffcicientlysupportingit.\n"
"
Pleaseconsiderspecifiyingalowerframerate,adifferentmuxeror-vsync2\n"
}&
for(j=0;
forced_kf_count;
j++)ost-&
forced_kf_pts[j]=av_rescale_q(ost-&
forced_kf_pts[j],AV_TIME_BASE_Q,codec-&
time_base);
}/*twopassmode*/if(codec-&
codec_id!
=CODEC_ID_H264&
(codec-&
(CODEC_FLAG_PASS1|CODEC_FLAG_PASS2))){charlogfilename[1024];
FILE*f;
snprintf(logfilename,sizeof(logfilename),"
%s-%d.log"
pass_logfilename_prefix?
pass_logfilename_prefix:
DEFAULT_PASS_LOGFILENAME_PREFIX,i);
if(codec-&
CODEC_FLAG_PASS2){char*logbuffer;
size_tlogbuffer_size;
if(cmdutils_read_file(logfilename,&
logbuffer,&
logbuffer_size)&
0){av_log(NULL,AV_LOG_FATAL,"
Errorreadinglogfile'
%s'
forpass-2encoding\n"
logfilename);
stats_in=logbuffer;
}if(codec-&
CODEC_FLAG_PASS1){f=fopen(logfilenam
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新版 ffmpeg 源码 分析 transcode