Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
FFmpeg-Examples
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
FFmpeg-Examples
Commits
32cc2d6d
Commit
32cc2d6d
authored
Mar 14, 2022
by
NzSN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files
parent
26509173
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
23 deletions
+38
-23
AudioTrackMerge.c
AudioTrackMerge.c
+30
-23
makefile
makefile
+8
-0
No files found.
AudioTrackMerge.c
View file @
32cc2d6d
...
...
@@ -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
);
...
...
makefile
0 → 100644
View file @
32cc2d6d
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment