Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
f76698e7
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f76698e7
编写于
10月 19, 2016
作者:
A
Anton Khirnov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
examples/encode_audio: use the AVFrame API for allocating the data
It is simpler and more efficient.
上级
c00a11ab
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
16 deletion
+10
-16
doc/examples/encode_audio.c
doc/examples/encode_audio.c
+10
-16
未找到文件。
doc/examples/encode_audio.c
浏览文件 @
f76698e7
...
...
@@ -97,7 +97,6 @@ int main(int argc, char **argv)
AVFrame
*
frame
;
AVPacket
pkt
;
int
i
,
j
,
k
,
ret
,
got_output
;
int
buffer_size
;
FILE
*
f
;
uint16_t
*
samples
;
float
t
,
tincr
;
...
...
@@ -159,21 +158,10 @@ int main(int argc, char **argv)
frame
->
format
=
c
->
sample_fmt
;
frame
->
channel_layout
=
c
->
channel_layout
;
/* the codec gives us the frame size, in samples,
* we calculate the size of the samples buffer in bytes */
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
);
/* allocate the data buffers */
ret
=
av_frame_get_buffer
(
frame
,
0
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"could not
setup audio frame
\n
"
);
fprintf
(
stderr
,
"could not
allocate audio data buffers
\n
"
);
exit
(
1
);
}
...
...
@@ -185,6 +173,13 @@ int main(int argc, char **argv)
pkt
.
data
=
NULL
;
// packet data will be allocated by the encoder
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
++
)
{
samples
[
2
*
j
]
=
(
int
)(
sin
(
t
)
*
10000
);
...
...
@@ -205,7 +200,6 @@ int main(int argc, char **argv)
}
fclose
(
f
);
av_freep
(
&
samples
);
av_frame_free
(
&
frame
);
avcodec_free_context
(
&
c
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录