Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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.wasm-core
Commits
9abe4a10
Commit
9abe4a10
authored
Jan 08, 2014
by
Stefano Sabatini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/muxing: reuse global audio frame
Simplify logic, avoid multiple unnecessary alloc/free operations.
parent
80bca6ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
muxing.c
doc/examples/muxing.c
+13
-7
No files found.
doc/examples/muxing.c
View file @
9abe4a10
...
...
@@ -123,6 +123,7 @@ static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec,
static
float
t
,
tincr
,
tincr2
;
AVFrame
*
audio_frame
;
static
uint8_t
**
src_samples_data
;
static
int
src_samples_linesize
;
static
int
src_nb_samples
;
...
...
@@ -141,6 +142,13 @@ static void open_audio(AVFormatContext *oc, AVCodec *codec, AVStream *st)
c
=
st
->
codec
;
/* allocate and init a re-usable frame */
audio_frame
=
av_frame_alloc
();
if
(
!
audio_frame
)
{
fprintf
(
stderr
,
"Could not allocate audio frame
\n
"
);
exit
(
1
);
}
/* open it */
ret
=
avcodec_open2
(
c
,
codec
,
NULL
);
if
(
ret
<
0
)
{
...
...
@@ -225,7 +233,6 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
{
AVCodecContext
*
c
;
AVPacket
pkt
=
{
0
};
// data and size must be 0;
AVFrame
*
frame
=
av_frame_alloc
();
int
got_packet
,
ret
,
dst_nb_samples
;
av_init_packet
(
&
pkt
);
...
...
@@ -261,18 +268,18 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
dst_nb_samples
=
src_nb_samples
;
}
frame
->
nb_samples
=
dst_nb_samples
;
avcodec_fill_audio_frame
(
frame
,
c
->
channels
,
c
->
sample_fmt
,
audio_
frame
->
nb_samples
=
dst_nb_samples
;
avcodec_fill_audio_frame
(
audio_
frame
,
c
->
channels
,
c
->
sample_fmt
,
dst_samples_data
[
0
],
dst_samples_size
,
0
);
ret
=
avcodec_encode_audio2
(
c
,
&
pkt
,
frame
,
&
got_packet
);
ret
=
avcodec_encode_audio2
(
c
,
&
pkt
,
audio_
frame
,
&
got_packet
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Error encoding audio frame: %s
\n
"
,
av_err2str
(
ret
));
exit
(
1
);
}
if
(
!
got_packet
)
goto
freeframe
;
return
;
pkt
.
stream_index
=
st
->
index
;
...
...
@@ -283,8 +290,6 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st)
av_err2str
(
ret
));
exit
(
1
);
}
freeframe:
av_frame_free
(
&
frame
);
}
static
void
close_audio
(
AVFormatContext
*
oc
,
AVStream
*
st
)
...
...
@@ -296,6 +301,7 @@ static void close_audio(AVFormatContext *oc, AVStream *st)
}
av_free
(
src_samples_data
[
0
]);
av_free
(
src_samples_data
);
av_frame_free
(
&
audio_frame
);
}
/**************************************************************/
...
...
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