本篇文章的视频复用器是不带编码的。程序输入两个文件,从其中一个文件挑出视频流,从另一个文件挑出音频流,然后合成为某种视频格式(如mp4/ts/flv等),输出成文件。
其中视频流所在的文件,可以是mp4/ts/flv等格式的视频文件,也可以是h264等纯视频编码文件。音频流所在文件可以是mp4/ts/flv等格式的视频文件,也可以是aac等纯音频编码的文件。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <libavutil/avassert.h>
#include <libavutil/channel_layout.h>
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
static int in_videoindex = -1, in_audioindex = -1, out_videoindex = -1, out_audioindex = -1;
static AVFormatContext *ifmt_ctx_v = NULL, *ifmt_ctx_a = NULL, *ofmt_ctx = NULL;
static int frame_index = 0;
static void mux_without_encode()
{
const char *in_filename_v = "/Users/zhw/Desktop/resource/sintel_h264_aac.ts";
const char *in_filename_a = "/Users/zhw/Desktop/resource/sintel_h264_aac.ts";
const char *out_filename = "/Users/zhw/Desktop/result.mp4";
int ret;
AVOutputFormat *ofmt;
ret = avformat_open_input(&ifmt_ctx_v, in_filename_v, NULL, NULL);
if (ret < 0) {
printf("avformat_open_input %s fail\n", in_filename_v);
exit(1);
}
ret = avforma