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
f76698e7
Commit
f76698e7
authored
Oct 19, 2016
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/encode_audio: use the AVFrame API for allocating the data
It is simpler and more efficient.
parent
c00a11ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
encode_audio.c
doc/examples/encode_audio.c
+10
-16
No files found.
doc/examples/encode_audio.c
View file @
f76698e7
...
@@ -97,7 +97,6 @@ int main(int argc, char **argv)
...
@@ -97,7 +97,6 @@ int main(int argc, char **argv)
AVFrame
*
frame
;
AVFrame
*
frame
;
AVPacket
pkt
;
AVPacket
pkt
;
int
i
,
j
,
k
,
ret
,
got_output
;
int
i
,
j
,
k
,
ret
,
got_output
;
int
buffer_size
;
FILE
*
f
;
FILE
*
f
;
uint16_t
*
samples
;
uint16_t
*
samples
;
float
t
,
tincr
;
float
t
,
tincr
;
...
@@ -159,21 +158,10 @@ int main(int argc, char **argv)
...
@@ -159,21 +158,10 @@ int main(int argc, char **argv)
frame
->
format
=
c
->
sample_fmt
;
frame
->
format
=
c
->
sample_fmt
;
frame
->
channel_layout
=
c
->
channel_layout
;
frame
->
channel_layout
=
c
->
channel_layout
;
/* the codec gives us the frame size, in samples,
/* allocate the data buffers */
* we calculate the size of the samples buffer in bytes */
ret
=
av_frame_get_buffer
(
frame
,
0
);
buffer_size
=
av_samples_get_buffer_size
(
NULL
,
c
->
channels
,
c
->
frame_size
,
c
->
sample_fmt
,
0
);
samples
=
av_malloc
(
buffer_size
);
if
(
!
samples
)
{
fprintf
(
stderr
,
"could not allocate %d bytes for samples buffer
\n
"
,
buffer_size
);
exit
(
1
);
}
/* setup the data pointers in the AVFrame */
ret
=
avcodec_fill_audio_frame
(
frame
,
c
->
channels
,
c
->
sample_fmt
,
(
const
uint8_t
*
)
samples
,
buffer_size
,
0
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"could not
setup audio frame
\n
"
);
fprintf
(
stderr
,
"could not
allocate audio data buffers
\n
"
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -185,6 +173,13 @@ int main(int argc, char **argv)
...
@@ -185,6 +173,13 @@ int main(int argc, char **argv)
pkt
.
data
=
NULL
;
// packet data will be allocated by the encoder
pkt
.
data
=
NULL
;
// packet data will be allocated by the encoder
pkt
.
size
=
0
;
pkt
.
size
=
0
;
/* make sure the frame is writable -- makes a copy if the encoder
* kept a reference internally */
ret
=
av_frame_make_writable
(
frame
);
if
(
ret
<
0
)
exit
(
1
);
samples
=
(
uint16_t
*
)
frame
->
data
[
0
];
for
(
j
=
0
;
j
<
c
->
frame_size
;
j
++
)
{
for
(
j
=
0
;
j
<
c
->
frame_size
;
j
++
)
{
samples
[
2
*
j
]
=
(
int
)(
sin
(
t
)
*
10000
);
samples
[
2
*
j
]
=
(
int
)(
sin
(
t
)
*
10000
);
...
@@ -205,7 +200,6 @@ int main(int argc, char **argv)
...
@@ -205,7 +200,6 @@ int main(int argc, char **argv)
}
}
fclose
(
f
);
fclose
(
f
);
av_freep
(
&
samples
);
av_frame_free
(
&
frame
);
av_frame_free
(
&
frame
);
avcodec_free_context
(
&
c
);
avcodec_free_context
(
&
c
);
}
}
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