Commit 32cc2d6d authored by NzSN's avatar NzSN

Add files

parent 26509173
......@@ -32,7 +32,8 @@ typedef struct FilteringContext {
int prepare_audio_encoder(AudioStreamingContext *encoder, AudioStreamingContext *decoder);
int prepare_audio_decoder(AudioStreamingContext *decoder);
int add_to_src(AudioStreamingContext *decoder, AVFilterContext *src, AVPacket *input_packet);
int add_to_src(AudioStreamingContext *decoder, AVFilterContext *src,
AVPacket *input_packet, AVFrame *input_frame);
int process_filtered_frames(AudioStreamingContext *encoder, AVFrame *frame);
static int init_filter_graph(AVFilterGraph **graph, AVFilterContext **src,
......@@ -120,7 +121,7 @@ static int init_filter_graph(AVFilterGraph **graph, AVFilterContext **src,
/* Create amix filter */
amix = avfilter_get_by_name("amix");
if (!amix_ctx) {
if (!amix) {
printf("Unable to find the amix filter\n");
return 1;
}
......@@ -175,9 +176,6 @@ static int init_filter_graph(AVFilterGraph **graph, AVFilterContext **src,
return 1;
}
char* dump =avfilter_graph_dump(filter_graph, NULL);
av_log(NULL, AV_LOG_ERROR, "Graph :\n%s\n", dump);
*graph = filter_graph;
*src = abuffer_first_ctx;
*src_ = abuffer_second_ctx;
......@@ -294,10 +292,11 @@ int audioMix(char *argv[]) {
}
if (fin[i] == 1) {
add_to_src(audioContexts[i], srcs[i], NULL);
add_to_src(audioContexts[i], srcs[i], NULL, NULL);
}
add_to_src(audioContexts[i], srcs[i], packet);
add_to_src(audioContexts[i], srcs[i], packet, frame);
av_packet_unref(packet);
}
}
......@@ -313,6 +312,9 @@ int audioMix(char *argv[]) {
}
}
av_frame_free(&frame);
av_packet_free(&packet);
av_write_trailer(o_encoder.fmt);
avfilter_graph_free(&filter_ctx.graph);
......@@ -324,13 +326,20 @@ int audioMix(char *argv[]) {
s1_decoder.fmt = NULL;
avformat_free_context(s2_decoder.fmt);
s2_decoder.fmt = NULL;
avio_close(o_encoder.fmt->pb);
avformat_free_context(o_encoder.fmt);
o_encoder.fmt = NULL;
avcodec_close(s1_decoder.cc);
avcodec_free_context(&s1_decoder.cc);
s1_decoder.cc = NULL;
avcodec_close(s2_decoder.cc);
avcodec_free_context(&s2_decoder.cc);
s2_decoder.cc = NULL;
avcodec_close(o_encoder.cc);
avcodec_free_context(&o_encoder.cc);
return 0;
}
......@@ -367,28 +376,22 @@ int process_filtered_frames(AudioStreamingContext *encoder, AVFrame *frame) {
return 0;
}
int add_to_src(AudioStreamingContext *decoder, AVFilterContext *src, AVPacket *input_packet) {
int add_to_src(AudioStreamingContext *decoder, AVFilterContext *src,
AVPacket *input_packet, AVFrame *input_frame) {
int err = 0;
AVFrame *input_frame = av_frame_alloc();
if (input_packet == NULL) {
err = av_buffersrc_add_frame(src, NULL);
if (err < 0) {
printf("Failed to write NULL frame\n");
return 1;
}
return 0;
}
if (!input_frame) {
printf(" Failed to allocaated memory for AVFrame\n");
return 1;
goto CLEANUP;
}
int response = avcodec_send_packet(decoder->cc, input_packet);
if (response < 0) {
printf("Failed to decode packet\n");
return 1;
goto CLEANUP;
}
while (response >= 0) {
......@@ -398,21 +401,21 @@ int add_to_src(AudioStreamingContext *decoder, AVFilterContext *src, AVPacket *i
} else if (response < 0) {
printf("Error while receiving frame from decoder: %s",
av_err2str(response));
return 1;
goto CLEANUP;
}
err = av_buffersrc_add_frame(src, input_frame);
if (err < 0) {
av_frame_unref(input_frame);
printf("Failed to submitting the frame to the filtergraph: %s\n",
av_err2str(err));
return 1;
goto CLEANUP;
}
}
CLEANUP:
av_frame_unref(input_frame);
return 0;
return err;
}
int prepare_audio_encoder(AudioStreamingContext *encoder, AudioStreamingContext *decoder) {
......@@ -644,7 +647,11 @@ char *do_mergeAV(char *videoPath, char *audioPath, char *outputPath) {
av_write_trailer(outputCtx);
avformat_close_input(&vFmtCtx);
avformat_free_context(vFmtCtx);
avformat_close_input(&aFmtCtx);
avformat_free_context(aFmtCtx);
avio_closep(&outputCtx->pb);
avformat_free_context(outputCtx);
......
all:
gcc -g -o remuxing fps-edit.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil
gcc -g -o mergeAV mergeAV.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil
gcc -g -o info info.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil -lm
gcc -g -o AudioTrackMerge AudioTrackMerge.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil
gcc -g -o filter_audio filter_audio.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil -lm
gcc -g -o filtering_audio filtering_audio.c -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil -lm
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment