資源簡介
ffmpeg轉碼為hls的代碼,里面涉及具體的轉碼流程以及參數設置.ffmpeg轉碼為hls的代碼,里面涉及具體的轉碼流程以及參數設置
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?BUF_SIZE_20K?2048000
#define?BUF_SIZE_1K?1024000
static?AVFormatContext?*ifmt_ctx;
static?AVFormatContext?*ofmt_ctx;
static?SwrContext*?pSwrCtx?=?NULL;
AVBitStreamFilterContext*?aacbsfc?=?NULL;
void?initSwr(int?audio_index)??
{??
????if?(ofmt_ctx->streams[0]->codec->channels?!=?ifmt_ctx->streams[audio_index]->codec->channels??
????????||?ofmt_ctx->streams[0]->codec->sample_rate?!=?ifmt_ctx->streams[audio_index]->codec->sample_rate??
????????||?ofmt_ctx->streams[0]->codec->sample_fmt?!=?ifmt_ctx->streams[audio_index]->codec->sample_fmt)??
????{??
????????if?(?NULL?==?pSwrCtx?)???
????????{??
????????????pSwrCtx?=?swr_alloc();??
????????}??
//?#if?LIBSWRESAMPLE_VERSION_MINOR?>=?17????//?根據版本不同,選用適當函數??
????????//?av_opt_set_int(pSwrCtx?“ich“?ifmt_ctx->streams[audio_index]->codec->channels?0);??
????????//?av_opt_set_int(pSwrCtx?“och“?ofmt_ctx->streams[audio_index]->codec->channels?0);??
????????//?av_opt_set_int(pSwrCtx?“in_sample_rate“??ifmt_ctx->streams[audio_index]->codec->sample_rate?0);??
????????//?av_opt_set_int(pSwrCtx?“out_sample_rate“??ofmt_ctx->streams[audio_index]->codec->sample_rate?0);??
????????//?av_opt_set_sample_fmt(pSwrCtx?“in_sample_fmt“?ifmt_ctx->streams[audio_index]->codec->sample_fmt?0);??
????????//?av_opt_set_sample_fmt(pSwrCtx?“out_sample_fmt“?ofmt_ctx->streams[audio_index]->codec->sample_fmt?0);??
??
//?#else??
????????pSwrCtx?=?swr_alloc_set_opts(NULL?????????????
????????????ofmt_ctx->streams[audio_index]->codec->channel_layout???
????????????ofmt_ctx->streams[audio_index]->codec->sample_fmt???
????????????ofmt_ctx->streams[audio_index]->codec->sample_rate??
????????????ifmt_ctx->streams[audio_index]->codec->channel_layout???
????????????ifmt_ctx->streams[audio_index]->codec->sample_fmt???
????????????ifmt_ctx->streams[audio_index]->codec->sample_rate??
????????????0?NULL);??
//?#endif??
????????swr_init(pSwrCtx);??
????}??
}??
??
//setup_array函數摘自ffmpeg例程??
static?void?setup_array(uint8_t*?out[32]?AVframe*?in_frame?int?format?int?samples)??
{??
????if?(av_sample_fmt_is_planar(format))???
????{??
????????int?i;
????????int?plane_size?=?av_get_bytes_per_sample((format?&?0xFF))?*?samples;
????????format?&=?0xFF;??
??????????
????????//從decoder出來的frame中的data數據不是連續分布的,所以不能這樣寫:??
????????in_frame->data[0]+i*plane_size;??
????????for?(i?=?0;?i?ame->channels;?i++)??
????????{??
????????????out[i]?=?in_frame->data[i];??
????????}??
????}???
????else??
????{??
????????out[0]?=?in_frame->data[0];??
????}??
}
int?TransSample(AVframe?*in_frame?AVframe?*out_frame?int?audio_index)??
{??
????int?ret;??
????int?max_dst_nb_samples?=?4096;??
???
評論
共有 條評論