Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
ded28ba3
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,发现更多精彩内容 >>
提交
ded28ba3
编写于
11月 21, 2011
作者:
A
Anton Khirnov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avconv: split audio transcoding out of output_packet().
上级
78162b4e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
112 addition
and
93 deletion
+112
-93
avconv.c
avconv.c
+112
-93
未找到文件。
avconv.c
浏览文件 @
ded28ba3
...
...
@@ -1615,6 +1615,109 @@ static void rate_emu_sleep(InputStream *ist)
}
}
static
int
transcode_audio
(
InputStream
*
ist
,
AVPacket
*
pkt
,
int
*
got_output
)
{
static
unsigned
int
samples_size
=
0
;
int
bps
=
av_get_bytes_per_sample
(
ist
->
st
->
codec
->
sample_fmt
);
uint8_t
*
decoded_data_buf
=
NULL
;
int
decoded_data_size
=
0
;
int
i
,
ret
;
if
(
pkt
&&
samples_size
<
FFMAX
(
pkt
->
size
*
bps
,
AVCODEC_MAX_AUDIO_FRAME_SIZE
))
{
av_free
(
samples
);
samples_size
=
FFMAX
(
pkt
->
size
*
bps
,
AVCODEC_MAX_AUDIO_FRAME_SIZE
);
samples
=
av_malloc
(
samples_size
);
}
decoded_data_size
=
samples_size
;
ret
=
avcodec_decode_audio3
(
ist
->
st
->
codec
,
samples
,
&
decoded_data_size
,
pkt
);
if
(
ret
<
0
)
return
ret
;
pkt
->
data
+=
ret
;
pkt
->
size
-=
ret
;
*
got_output
=
decoded_data_size
>
0
;
/* Some bug in mpeg audio decoder gives */
/* decoded_data_size < 0, it seems they are overflows */
if
(
!*
got_output
)
{
/* no audio frame */
return
0
;
}
decoded_data_buf
=
(
uint8_t
*
)
samples
;
ist
->
next_pts
+=
((
int64_t
)
AV_TIME_BASE
/
bps
*
decoded_data_size
)
/
(
ist
->
st
->
codec
->
sample_rate
*
ist
->
st
->
codec
->
channels
);
// preprocess audio (volume)
if
(
audio_volume
!=
256
)
{
switch
(
ist
->
st
->
codec
->
sample_fmt
)
{
case
AV_SAMPLE_FMT_U8
:
{
uint8_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int
v
=
(((
*
volp
-
128
)
*
audio_volume
+
128
)
>>
8
)
+
128
;
*
volp
++
=
av_clip_uint8
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_S16
:
{
int16_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int
v
=
((
*
volp
)
*
audio_volume
+
128
)
>>
8
;
*
volp
++
=
av_clip_int16
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_S32
:
{
int32_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int64_t
v
=
(((
int64_t
)
*
volp
*
audio_volume
+
128
)
>>
8
);
*
volp
++
=
av_clipl_int32
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_FLT
:
{
float
*
volp
=
samples
;
float
scale
=
audio_volume
/
256
.
f
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
*
volp
++
*=
scale
;
}
break
;
}
case
AV_SAMPLE_FMT_DBL
:
{
double
*
volp
=
samples
;
double
scale
=
audio_volume
/
256
.;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
*
volp
++
*=
scale
;
}
break
;
}
default:
av_log
(
NULL
,
AV_LOG_FATAL
,
"Audio volume adjustment on sample format %s is not supported.
\n
"
,
av_get_sample_fmt_name
(
ist
->
st
->
codec
->
sample_fmt
));
exit_program
(
1
);
}
}
rate_emu_sleep
(
ist
);
for
(
i
=
0
;
i
<
nb_output_streams
;
i
++
)
{
OutputStream
*
ost
=
&
output_streams
[
i
];
if
(
!
check_output_constraints
(
ist
,
ost
)
||
!
ost
->
encoding_needed
)
continue
;
do_audio_out
(
output_files
[
ost
->
file_index
].
ctx
,
ost
,
ist
,
decoded_data_buf
,
decoded_data_size
);
}
return
0
;
}
/* pkt = NULL means EOF (needed to flush decoder buffers) */
static
int
output_packet
(
InputStream
*
ist
,
int
ist_index
,
OutputStream
*
ost_table
,
int
nb_ostreams
,
...
...
@@ -1625,7 +1728,6 @@ static int output_packet(InputStream *ist, int ist_index,
int
ret
=
0
,
i
;
int
got_output
;
void
*
buffer_to_free
=
NULL
;
static
unsigned
int
samples_size
=
0
;
AVSubtitle
subtitle
,
*
subtitle_to_free
;
int64_t
pkt_pts
=
AV_NOPTS_VALUE
;
#if CONFIG_AVFILTER
...
...
@@ -1634,7 +1736,6 @@ static int output_packet(InputStream *ist, int ist_index,
float
quality
;
AVPacket
avpkt
;
int
bps
=
av_get_bytes_per_sample
(
ist
->
st
->
codec
->
sample_fmt
);
if
(
ist
->
next_pts
==
AV_NOPTS_VALUE
)
ist
->
next_pts
=
ist
->
pts
;
...
...
@@ -1656,8 +1757,6 @@ static int output_packet(InputStream *ist, int ist_index,
//while we have more to decode or while the decoder did output something on EOF
while
(
ist
->
decoding_needed
&&
(
avpkt
.
size
>
0
||
(
!
pkt
&&
got_output
)))
{
uint8_t
*
decoded_data_buf
;
int
decoded_data_size
;
AVFrame
*
decoded_frame
,
*
filtered_frame
;
handle_eof:
ist
->
pts
=
ist
->
next_pts
;
...
...
@@ -1667,38 +1766,19 @@ static int output_packet(InputStream *ist, int ist_index,
"Multiple frames in a packet from stream %d
\n
"
,
pkt
->
stream_index
);
ist
->
showed_multi_packet_warning
=
1
;
// XXX temporary hack, will be turned to a switch() once all codec
// types are split out
if
(
ist
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_AUDIO
)
{
ret
=
transcode_audio
(
ist
,
&
avpkt
,
&
got_output
);
if
(
ret
<
0
)
return
ret
;
continue
;
}
/* decode the packet if needed */
decoded_frame
=
filtered_frame
=
NULL
;
decoded_data_buf
=
NULL
;
/* fail safe */
decoded_data_size
=
0
;
subtitle_to_free
=
NULL
;
switch
(
ist
->
st
->
codec
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:{
if
(
pkt
&&
samples_size
<
FFMAX
(
pkt
->
size
*
bps
,
AVCODEC_MAX_AUDIO_FRAME_SIZE
))
{
samples_size
=
FFMAX
(
pkt
->
size
*
bps
,
AVCODEC_MAX_AUDIO_FRAME_SIZE
);
av_free
(
samples
);
samples
=
av_malloc
(
samples_size
);
}
decoded_data_size
=
samples_size
;
/* XXX: could avoid copy if PCM 16 bits with same
endianness as CPU */
ret
=
avcodec_decode_audio3
(
ist
->
st
->
codec
,
samples
,
&
decoded_data_size
,
&
avpkt
);
if
(
ret
<
0
)
return
ret
;
avpkt
.
data
+=
ret
;
avpkt
.
size
-=
ret
;
got_output
=
decoded_data_size
>
0
;
/* Some bug in mpeg audio decoder gives */
/* decoded_data_size < 0, it seems they are overflows */
if
(
!
got_output
)
{
/* no audio frame */
continue
;
}
decoded_data_buf
=
(
uint8_t
*
)
samples
;
ist
->
next_pts
+=
((
int64_t
)
AV_TIME_BASE
/
bps
*
decoded_data_size
)
/
(
ist
->
st
->
codec
->
sample_rate
*
ist
->
st
->
codec
->
channels
);
break
;}
case
AVMEDIA_TYPE_VIDEO
:
if
(
!
(
decoded_frame
=
avcodec_alloc_frame
()))
return
AVERROR
(
ENOMEM
);
...
...
@@ -1743,64 +1823,6 @@ static int output_packet(InputStream *ist, int ist_index,
return
-
1
;
}
// preprocess audio (volume)
if
(
ist
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_AUDIO
)
{
if
(
audio_volume
!=
256
)
{
switch
(
ist
->
st
->
codec
->
sample_fmt
)
{
case
AV_SAMPLE_FMT_U8
:
{
uint8_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int
v
=
(((
*
volp
-
128
)
*
audio_volume
+
128
)
>>
8
)
+
128
;
*
volp
++
=
av_clip_uint8
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_S16
:
{
int16_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int
v
=
((
*
volp
)
*
audio_volume
+
128
)
>>
8
;
*
volp
++
=
av_clip_int16
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_S32
:
{
int32_t
*
volp
=
samples
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
int64_t
v
=
(((
int64_t
)
*
volp
*
audio_volume
+
128
)
>>
8
);
*
volp
++
=
av_clipl_int32
(
v
);
}
break
;
}
case
AV_SAMPLE_FMT_FLT
:
{
float
*
volp
=
samples
;
float
scale
=
audio_volume
/
256
.
f
;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
*
volp
++
*=
scale
;
}
break
;
}
case
AV_SAMPLE_FMT_DBL
:
{
double
*
volp
=
samples
;
double
scale
=
audio_volume
/
256
.;
for
(
i
=
0
;
i
<
(
decoded_data_size
/
sizeof
(
*
volp
));
i
++
)
{
*
volp
++
*=
scale
;
}
break
;
}
default:
av_log
(
NULL
,
AV_LOG_FATAL
,
"Audio volume adjustment on sample format %s is not supported.
\n
"
,
av_get_sample_fmt_name
(
ist
->
st
->
codec
->
sample_fmt
));
exit_program
(
1
);
}
}
}
/* frame rate emulation */
rate_emu_sleep
(
ist
);
...
...
@@ -1846,9 +1868,6 @@ static int output_packet(InputStream *ist, int ist_index,
av_assert0
(
ist
->
decoding_needed
);
switch
(
ost
->
st
->
codec
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:
do_audio_out
(
os
,
ost
,
ist
,
decoded_data_buf
,
decoded_data_size
);
break
;
case
AVMEDIA_TYPE_VIDEO
:
#if CONFIG_AVFILTER
if
(
ost
->
picref
->
video
&&
!
ost
->
frame_aspect_ratio
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录