Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
4a4ce2e7
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,发现更多精彩内容 >>
提交
4a4ce2e7
编写于
8月 18, 2011
作者:
A
Anton Khirnov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avconv: factor flushing encoders out of output_packet().
上级
630902a1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
88 addition
and
81 deletion
+88
-81
avconv.c
avconv.c
+88
-81
未找到文件。
avconv.c
浏览文件 @
4a4ce2e7
...
...
@@ -1396,6 +1396,93 @@ static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_
memset
(
buf
,
fill_char
,
size
);
}
static
void
flush_encoders
(
int
ist_index
,
OutputStream
*
ost_table
,
int
nb_ostreams
)
{
int
i
,
ret
;
for
(
i
=
0
;
i
<
nb_ostreams
;
i
++
)
{
OutputStream
*
ost
=
&
ost_table
[
i
];
if
(
ost
->
source_index
==
ist_index
)
{
AVCodecContext
*
enc
=
ost
->
st
->
codec
;
AVFormatContext
*
os
=
output_files
[
ost
->
file_index
].
ctx
;
if
(
ost
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_AUDIO
&&
enc
->
frame_size
<=
1
)
continue
;
if
(
ost
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
&&
(
os
->
oformat
->
flags
&
AVFMT_RAWPICTURE
))
continue
;
if
(
ost
->
encoding_needed
)
{
for
(;;)
{
AVPacket
pkt
;
int
fifo_bytes
;
av_init_packet
(
&
pkt
);
pkt
.
stream_index
=
ost
->
index
;
switch
(
ost
->
st
->
codec
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:
fifo_bytes
=
av_fifo_size
(
ost
->
fifo
);
ret
=
0
;
/* encode any samples remaining in fifo */
if
(
fifo_bytes
>
0
)
{
int
osize
=
av_get_bytes_per_sample
(
enc
->
sample_fmt
);
int
fs_tmp
=
enc
->
frame_size
;
av_fifo_generic_read
(
ost
->
fifo
,
audio_buf
,
fifo_bytes
,
NULL
);
if
(
enc
->
codec
->
capabilities
&
CODEC_CAP_SMALL_LAST_FRAME
)
{
enc
->
frame_size
=
fifo_bytes
/
(
osize
*
enc
->
channels
);
}
else
{
/* pad */
int
frame_bytes
=
enc
->
frame_size
*
osize
*
enc
->
channels
;
if
(
allocated_audio_buf_size
<
frame_bytes
)
exit_program
(
1
);
generate_silence
(
audio_buf
+
fifo_bytes
,
enc
->
sample_fmt
,
frame_bytes
-
fifo_bytes
);
}
ret
=
avcodec_encode_audio
(
enc
,
bit_buffer
,
bit_buffer_size
,
(
short
*
)
audio_buf
);
pkt
.
duration
=
av_rescale
((
int64_t
)
enc
->
frame_size
*
ost
->
st
->
time_base
.
den
,
ost
->
st
->
time_base
.
num
,
enc
->
sample_rate
);
enc
->
frame_size
=
fs_tmp
;
}
if
(
ret
<=
0
)
{
ret
=
avcodec_encode_audio
(
enc
,
bit_buffer
,
bit_buffer_size
,
NULL
);
}
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Audio encoding failed
\n
"
);
exit_program
(
1
);
}
audio_size
+=
ret
;
pkt
.
flags
|=
AV_PKT_FLAG_KEY
;
break
;
case
AVMEDIA_TYPE_VIDEO
:
ret
=
avcodec_encode_video
(
enc
,
bit_buffer
,
bit_buffer_size
,
NULL
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Video encoding failed
\n
"
);
exit_program
(
1
);
}
video_size
+=
ret
;
if
(
enc
->
coded_frame
&&
enc
->
coded_frame
->
key_frame
)
pkt
.
flags
|=
AV_PKT_FLAG_KEY
;
if
(
ost
->
logfile
&&
enc
->
stats_out
)
{
fprintf
(
ost
->
logfile
,
"%s"
,
enc
->
stats_out
);
}
break
;
default:
ret
=-
1
;
}
if
(
ret
<=
0
)
break
;
pkt
.
data
=
bit_buffer
;
pkt
.
size
=
ret
;
if
(
enc
->
coded_frame
&&
enc
->
coded_frame
->
pts
!=
AV_NOPTS_VALUE
)
pkt
.
pts
=
av_rescale_q
(
enc
->
coded_frame
->
pts
,
enc
->
time_base
,
ost
->
st
->
time_base
);
write_frame
(
os
,
&
pkt
,
ost
->
st
->
codec
,
ost
->
bitstream_filters
);
}
}
}
}
}
/* pkt = NULL means EOF (needed to flush decoder buffers) */
static
int
output_packet
(
InputStream
*
ist
,
int
ist_index
,
OutputStream
*
ost_table
,
int
nb_ostreams
,
...
...
@@ -1713,87 +1800,7 @@ static int output_packet(InputStream *ist, int ist_index,
discard_packet:
if
(
pkt
==
NULL
)
{
/* EOF handling */
for
(
i
=
0
;
i
<
nb_ostreams
;
i
++
)
{
ost
=
&
ost_table
[
i
];
if
(
ost
->
source_index
==
ist_index
)
{
AVCodecContext
*
enc
=
ost
->
st
->
codec
;
os
=
output_files
[
ost
->
file_index
].
ctx
;
if
(
ost
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_AUDIO
&&
enc
->
frame_size
<=
1
)
continue
;
if
(
ost
->
st
->
codec
->
codec_type
==
AVMEDIA_TYPE_VIDEO
&&
(
os
->
oformat
->
flags
&
AVFMT_RAWPICTURE
))
continue
;
if
(
ost
->
encoding_needed
)
{
for
(;;)
{
AVPacket
pkt
;
int
fifo_bytes
;
av_init_packet
(
&
pkt
);
pkt
.
stream_index
=
ost
->
index
;
switch
(
ost
->
st
->
codec
->
codec_type
)
{
case
AVMEDIA_TYPE_AUDIO
:
fifo_bytes
=
av_fifo_size
(
ost
->
fifo
);
ret
=
0
;
/* encode any samples remaining in fifo */
if
(
fifo_bytes
>
0
)
{
int
osize
=
av_get_bytes_per_sample
(
enc
->
sample_fmt
);
int
fs_tmp
=
enc
->
frame_size
;
av_fifo_generic_read
(
ost
->
fifo
,
audio_buf
,
fifo_bytes
,
NULL
);
if
(
enc
->
codec
->
capabilities
&
CODEC_CAP_SMALL_LAST_FRAME
)
{
enc
->
frame_size
=
fifo_bytes
/
(
osize
*
enc
->
channels
);
}
else
{
/* pad */
int
frame_bytes
=
enc
->
frame_size
*
osize
*
enc
->
channels
;
if
(
allocated_audio_buf_size
<
frame_bytes
)
exit_program
(
1
);
generate_silence
(
audio_buf
+
fifo_bytes
,
enc
->
sample_fmt
,
frame_bytes
-
fifo_bytes
);
}
ret
=
avcodec_encode_audio
(
enc
,
bit_buffer
,
bit_buffer_size
,
(
short
*
)
audio_buf
);
pkt
.
duration
=
av_rescale
((
int64_t
)
enc
->
frame_size
*
ost
->
st
->
time_base
.
den
,
ost
->
st
->
time_base
.
num
,
enc
->
sample_rate
);
enc
->
frame_size
=
fs_tmp
;
}
if
(
ret
<=
0
)
{
ret
=
avcodec_encode_audio
(
enc
,
bit_buffer
,
bit_buffer_size
,
NULL
);
}
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Audio encoding failed
\n
"
);
exit_program
(
1
);
}
audio_size
+=
ret
;
pkt
.
flags
|=
AV_PKT_FLAG_KEY
;
break
;
case
AVMEDIA_TYPE_VIDEO
:
ret
=
avcodec_encode_video
(
enc
,
bit_buffer
,
bit_buffer_size
,
NULL
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"Video encoding failed
\n
"
);
exit_program
(
1
);
}
video_size
+=
ret
;
if
(
enc
->
coded_frame
&&
enc
->
coded_frame
->
key_frame
)
pkt
.
flags
|=
AV_PKT_FLAG_KEY
;
if
(
ost
->
logfile
&&
enc
->
stats_out
)
{
fprintf
(
ost
->
logfile
,
"%s"
,
enc
->
stats_out
);
}
break
;
default:
ret
=-
1
;
}
if
(
ret
<=
0
)
break
;
pkt
.
data
=
bit_buffer
;
pkt
.
size
=
ret
;
if
(
enc
->
coded_frame
&&
enc
->
coded_frame
->
pts
!=
AV_NOPTS_VALUE
)
pkt
.
pts
=
av_rescale_q
(
enc
->
coded_frame
->
pts
,
enc
->
time_base
,
ost
->
st
->
time_base
);
write_frame
(
os
,
&
pkt
,
ost
->
st
->
codec
,
ost
->
bitstream_filters
);
}
}
}
}
flush_encoders
(
ist_index
,
ost_table
,
nb_ostreams
);
}
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录