#include "combine.h"
AVBitStreamFilterContext *aacbsfc = NULL;
AVBitStreamFilterContext* h264bsfc = NULL;
//multiple input
static AVFormatContext **ifmt_ctx;
//single output
static AVFormatContext *ofmt_ctx;
static FilteringContext *filter_ctx;
InputFile* inputfiles;
GlobalContext* global_ctx;
AVFrame **frame = NULL;
int global_ctx_config()
{
int i;
if (global_ctx->grid_num < global_ctx->video_num)
{
av_log(NULL, AV_LOG_ERROR, "Setting a wrong grid_num %d \t The grid_num is smaller than video_num!! \n", global_ctx->grid_num);
global_ctx->grid_num = global_ctx->video_num;
//global_ctx->stride = sqrt((double)global_ctx->grid_num);
av_log(NULL, AV_LOG_ERROR, "Automatically change the grid_num to be same as video_num!! \n");
}
//global_ctx->stride = sqrt((double)global_ctx->grid_num);
for (i = 0; i < global_ctx->video_num; i++)
{
if (global_ctx->input_file[i].video_idx >= global_ctx->grid_num)
{
av_log(NULL, AV_LOG_ERROR, "Invalid video_inx value in the No.%d input\n", global_ctx->input_file[i].video_idx);
return -1;
}
}
return 0;
}
int open_input_file(InputFile *input_file)
{
int ret;
unsigned int i;
unsigned int j;
ifmt_ctx = (AVFormatContext**)av_malloc((global_ctx->video_num)*sizeof(AVFormatContext*));
for (i = 0; i < global_ctx->video_num; i++)
{
*(ifmt_ctx + i) = NULL;
if ((ret = avformat_open_input((ifmt_ctx + i), input_file[i].filenames, NULL, NULL)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
return ret;
}
if ((ret = avformat_find_stream_info(ifmt_ctx[i], NULL)) < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
return ret;
}
for (j = 0; j < ifmt_ctx[i]->nb_streams; j++) {
AVStream *stream;
AVCodecContext *codec_ctx;
stream = ifmt_ctx[i]->streams[j];
codec_ctx = stream->codec;
if (codec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
|| codec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
/* Open decoder */
ret = avcodec_open2(codec_ctx,
avcodec_find_decoder(codec_ctx->codec_id), NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to open decoder for stream #%u\n", i);
return ret;
}
}
}
av_dump_format(ifmt_ctx[i], 0, input_file[i].filenames, 0);
}
return 0;
}
int open_output_file(const char *filename)
{
AVStream *out_stream;
AVStream *in_stream;
AVCodecContext *dec_ctx, *enc_ctx;
AVCodec *encoder;
int ret;
unsigned int i;
ofmt_ctx = NULL;
avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", filename);
if (!ofmt_ctx) {
av_log(NULL, AV_LOG_ERROR, "Could not create output context\n");
return AVERROR_UNKNOWN;
}
for (i = 0; i < ifmt_ctx[0]->nb_streams; i++) {
out_stream = avformat_new_stream(ofmt_ctx, NULL);
if (!out_stream) {
av_log(NULL, AV_LOG_ERROR, "Failed allocating output stream\n");
return AVERROR_UNKNOWN;
}
in_stream = ifmt_ctx[0]->streams[i];
out_stream->time_base = in_stream->time_base;
dec_ctx = in_stream->codec;
enc_ctx = out_stream->codec;
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO
|| dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) {
/* In this example, we transcode to same properties (picture size,
* sample rate etc.). These properties can be changed for output
* streams easily using filters */
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
/* in this example, we choose transcoding to same codec */
encoder = avcodec_find_encoder(AV_CODEC_ID_H264);
enc_ctx->height = global_ctx->enc_height;
enc_ctx->width = global_ctx->enc_width;
enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
/* take first format from list of supported formats */
enc_ctx->pix_fmt = encoder->pix_fmts[0];
enc_ctx->me_range = 16;
enc_ctx->max_qdiff = 4;
enc_ctx->bit_rate = global_ctx->enc_bit_rate;
enc_ctx->qcompress = 0.6;
/* video time_base can be set to whatever is handy and supported by encoder */
enc_ctx->time_base.num = 1;
enc_ctx->time_base.den = 25;
enc_ctx->gop_size = 250;
enc_ctx->max_b_frames = 3;
AVDictionary * d = NULL;
char *k = av_strdup("preset"); // if your strings are already allocated,
char *v = av_strdup("ultrafast"); // you can avoid copying them like this
av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
ret = avcodec_open2(enc_ctx, encoder, &d);
}
else {
encoder = avcodec_find_encoder(AV_CODEC_ID_AAC);
enc_ctx->sample_rate = dec_ctx->sample_rate;
enc_ctx->channel_layout = dec_ctx->channel_layout;
enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout);
/* take first format from list of supported formats */
enc_ctx->sample_fmt = encoder->sample_fmts[0];
AVRational time_base = { 1, enc_ctx->sample_rate };
enc_ctx->time_base = time_base;
ret = avcodec_open2(enc_ctx, encoder, NULL);
}
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Cannot open video encoder for stream #%u\n", i);
return ret;
}
}
else if (dec_ctx->codec_type == AVMEDIA_TYPE_UNKNOWN) {
av_log(NULL, AV_LOG_FATAL, "Elementary stream #%d is of unknown type, cannot proceed\n", i);
return AVERROR_INVALIDDATA;
}
else {
/* if this stream must be remuxed */
ret = avcodec_copy_context(ofmt_ctx->streams[i]->codec,
ifmt_ctx[0]->streams[i]->codec);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Copying stream context failed\n");
return ret;
}
}
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
av_dump_format(ofmt_ctx, 0, filename, 1);
if (!(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
ret = avio_open(&ofmt_ctx->pb, filename, AVIO_FLAG_WRITE);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Could not open output file '%s'", filename);
return ret;
}
}
/* init muxer, write output file header */
ret = avformat_write_header(ofmt_ctx, NULL);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Error occurred when opening output file\n");
return ret;
}
#if USE_H264BSF
h264bsfc = av_bitstream_filter_init("h264_mp4toannexb");
#endif
#if USE_AACBSF
aacbsfc = av_bitstream_filter_init("aac_adtstoasc");
#endif
return 0;
}
//
int init_filter(FilteringContext* fctx, AVCodecContext **dec_ctx,
AVCodecContext *enc_ctx, const char *filter_spec)
{
char args[512];
char pad_name[10];
int ret = 0;
int i;
AVFilter **buffersrc = (AVFilter**)av_malloc(global_ctx->video_num*sizeof(AVFilter*));
AVFilter *buffersink = NULL;
AVFilterContext **buffersrc_ctx = (AVFilterContext**)av_malloc(global_ctx->video_num*sizeof(AVFilterContext*));
没有合适的资源?快使用搜索试试~ 我知道了~
QT+FFmpeg多路视频合成
共131个文件
h:92个
dll:8个
lib:8个
需积分: 50 93 下载量 168 浏览量
2017-07-28
09:49:20
上传
评论 4
收藏 11.2MB RAR 举报
温馨提示
本程序实现了在QT平台上用ffmpeg将多路视频合成一起播放 注意:本代码运行后需将ffmpeg文件夹内bin文件夹里的.dll文件都复制在.exe文件的文件夹中程序才能正确运行
资源推荐
资源详情
资源评论
收起资源包目录
QT+FFmpeg多路视频合成 (131个子文件)
libavutil.dll.a 275KB
libavcodec.dll.a 142KB
libavformat.dll.a 103KB
libavfilter.dll.a 54KB
libswscale.dll.a 23KB
libswresample.dll.a 14KB
libavdevice.dll.a 11KB
libpostproc.dll.a 7KB
combine.cpp 27KB
main.cpp 2KB
avutil-54.def 10KB
avcodec-56.def 6KB
avformat-56.def 4KB
avfilter-5.def 2KB
swscale-3.def 781B
avdevice-56.def 491B
swresample-1.def 433B
postproc-53.def 233B
avcodec-56.dll 18.74MB
avformat-56.dll 5.57MB
avfilter-5.dll 2.21MB
avdevice-56.dll 1.3MB
avutil-54.dll 442KB
swscale-3.dll 437KB
swresample-1.dll 264KB
postproc-53.dll 119KB
ffplay.exe 464KB
ffmpeg.exe 317KB
ffprobe.exe 149KB
avcodec.h 176KB
avformat.h 100KB
avfilter.h 56KB
opt.h 37KB
pixfmt.h 32KB
frame.h 23KB
swresample.h 19KB
avio.h 18KB
intreadwrite.h 18KB
avdevice.h 16KB
mem.h 14KB
old_pix_fmts.h 14KB
pixdesc.h 14KB
common.h 14KB
avstring.h 13KB
swscale.h 12KB
old_codec_ids.h 10KB
log.h 10KB
samplefmt.h 10KB
buffer.h 10KB
channel_layout.h 9KB
avutil.h 8KB
imgutils.h 8KB
dict.h 8KB
bprint.h 8KB
buffersink.h 7KB
parseutils.h 7KB
vdpau.h 7KB
version.h 6KB
xvmc.h 6KB
error.h 5KB
vda.h 5KB
timecode.h 5KB
eval.h 5KB
mathematics.h 5KB
fifo.h 5KB
buffersrc.h 5KB
cpu.h 5KB
audio_fifo.h 4KB
attributes.h 4KB
rational.h 4KB
vaapi.h 4KB
version.h 4KB
dv_profile.h 4KB
stereo3d.h 4KB
hash.h 4KB
asrc_abuffer.h 3KB
downmix_info.h 3KB
display.h 3KB
threadmessage.h 3KB
avfft.h 3KB
postprocess.h 3KB
version.h 3KB
hmac.h 3KB
bswap.h 3KB
crc.h 3KB
timestamp.h 3KB
file.h 2KB
version.h 2KB
avcodec.h 2KB
dxva2.h 2KB
vorbis_parser.h 2KB
blowfish.h 2KB
combine.h 2KB
avassert.h 2KB
base64.h 2KB
pixelutils.h 2KB
lzo.h 2KB
sha512.h 2KB
ripemd.h 2KB
version.h 2KB
共 131 条
- 1
- 2
资源评论
weiwen12138
- 粉丝: 32
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功