Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
b6c61fb8
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,发现更多精彩内容 >>
提交
b6c61fb8
编写于
3月 03, 2014
作者:
T
Tim Walker
提交者:
Vittorio Giovara
3月 09, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
movenc: enable Annex B to MP4 conversion for HEVC tracks.
上级
20b40a59
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
158 addition
and
0 deletion
+158
-0
libavformat/hevc.c
libavformat/hevc.c
+101
-0
libavformat/hevc.h
libavformat/hevc.h
+48
-0
libavformat/movenc.c
libavformat/movenc.c
+9
-0
未找到文件。
libavformat/hevc.c
浏览文件 @
b6c61fb8
...
...
@@ -1014,6 +1014,107 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc)
return
0
;
}
int
ff_hevc_annexb2mp4
(
AVIOContext
*
pb
,
const
uint8_t
*
buf_in
,
int
size
,
int
filter_ps
,
int
*
ps_count
)
{
int
num_ps
=
0
,
ret
=
0
;
uint8_t
*
buf
,
*
end
,
*
start
=
NULL
;
if
(
!
filter_ps
)
{
ret
=
ff_avc_parse_nal_units
(
pb
,
buf_in
,
size
);
goto
end
;
}
ret
=
ff_avc_parse_nal_units_buf
(
buf_in
,
&
start
,
&
size
);
if
(
ret
<
0
)
goto
end
;
ret
=
0
;
buf
=
start
;
end
=
start
+
size
;
while
(
end
-
buf
>
4
)
{
uint32_t
len
=
FFMIN
(
AV_RB32
(
buf
),
end
-
buf
-
4
);
uint8_t
type
=
(
buf
[
4
]
>>
1
)
&
0x3f
;
buf
+=
4
;
switch
(
type
)
{
case
NAL_VPS
:
case
NAL_SPS
:
case
NAL_PPS
:
num_ps
++
;
break
;
default:
ret
+=
4
+
len
;
avio_wb32
(
pb
,
len
);
avio_write
(
pb
,
buf
,
len
);
break
;
}
buf
+=
len
;
}
end:
free
(
start
);
if
(
ps_count
)
*
ps_count
=
num_ps
;
return
ret
;
}
int
ff_hevc_annexb2mp4_buf
(
const
uint8_t
*
buf_in
,
uint8_t
**
buf_out
,
int
*
size
,
int
filter_ps
,
int
*
ps_count
)
{
AVIOContext
*
pb
;
int
num_ps
=
0
,
ret
=
0
;
uint8_t
*
buf
,
*
end
,
*
start
=
NULL
;
if
(
!
filter_ps
)
{
ret
=
ff_avc_parse_nal_units_buf
(
buf_in
,
buf_out
,
size
);
goto
end
;
}
ret
=
avio_open_dyn_buf
(
&
pb
);
if
(
ret
<
0
)
goto
end
;
ret
=
ff_avc_parse_nal_units_buf
(
buf_in
,
&
start
,
size
);
if
(
ret
<
0
)
goto
end
;
buf
=
start
;
end
=
start
+
*
size
;
while
(
end
-
buf
>
4
)
{
uint32_t
len
=
FFMIN
(
AV_RB32
(
buf
),
end
-
buf
-
4
);
uint8_t
type
=
(
buf
[
4
]
>>
1
)
&
0x3f
;
buf
+=
4
;
switch
(
type
)
{
case
NAL_VPS
:
case
NAL_SPS
:
case
NAL_PPS
:
num_ps
++
;
break
;
default:
avio_wb32
(
pb
,
len
);
avio_write
(
pb
,
buf
,
len
);
break
;
}
buf
+=
len
;
}
*
size
=
avio_close_dyn_buf
(
pb
,
buf_out
);
end:
free
(
start
);
if
(
ps_count
)
*
ps_count
=
num_ps
;
return
ret
;
}
int
ff_isom_write_hvcc
(
AVIOContext
*
pb
,
const
uint8_t
*
data
,
int
size
,
int
ps_array_completeness
)
{
...
...
libavformat/hevc.h
浏览文件 @
b6c61fb8
...
...
@@ -29,6 +29,54 @@
#include <stdint.h>
#include "avio.h"
/**
* Writes Annex B formatted HEVC NAL units to the provided AVIOContext.
*
* The NAL units are converted to an MP4-compatible format (start code prefixes
* are replaced by 4-byte size fields, as per ISO/IEC 14496-15).
*
* If filter_ps is non-zero, any HEVC parameter sets found in the input will be
* discarded, and *ps_count will be set to the number of discarded PS NAL units.
*
* @param pb address of the AVIOContext where the data shall be written
* @param buf_in address of the buffer holding the input data
* @param size size (in bytes) of the input buffer
* @param filter_ps whether to write parameter set NAL units to the output (0)
* or to discard them (non-zero)
* @param ps_count address of the variable where the number of discarded
* parameter set NAL units shall be written, may be NULL
* @return the amount (in bytes) of data written in case of success, a negative
* value corresponding to an AVERROR code in case of failure
*/
int
ff_hevc_annexb2mp4
(
AVIOContext
*
pb
,
const
uint8_t
*
buf_in
,
int
size
,
int
filter_ps
,
int
*
ps_count
);
/**
* Writes Annex B formatted HEVC NAL units to a data buffer.
*
* The NAL units are converted to an MP4-compatible format (start code prefixes
* are replaced by 4-byte size fields, as per ISO/IEC 14496-15).
*
* If filter_ps is non-zero, any HEVC parameter sets found in the input will be
* discarded, and *ps_count will be set to the number of discarded PS NAL units.
*
* On output, *size holds the size (in bytes) of the output data buffer.
*
* @param buf_in address of the buffer holding the input data
* @param size address of the variable holding the size (in bytes) of the input
* buffer (on input) and of the output buffer (on output)
* @param buf_out address of the variable holding the address of the output
* buffer
* @param filter_ps whether to write parameter set NAL units to the output (0)
* or to discard them (non-zero)
* @param ps_count address of the variable where the number of discarded
* parameter set NAL units shall be written, may be NULL
* @return 0 in case of success, a negative value corresponding to an AVERROR
* code in case of failure
*/
int
ff_hevc_annexb2mp4_buf
(
const
uint8_t
*
buf_in
,
uint8_t
**
buf_out
,
int
*
size
,
int
filter_ps
,
int
*
ps_count
);
/**
* Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the
* provided AVIOContext.
...
...
libavformat/movenc.c
浏览文件 @
b6c61fb8
...
...
@@ -2939,6 +2939,15 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
}
else
{
size
=
ff_avc_parse_nal_units
(
pb
,
pkt
->
data
,
pkt
->
size
);
}
}
else
if
(
enc
->
codec_id
==
AV_CODEC_ID_HEVC
&&
trk
->
vos_len
>
6
&&
(
AV_RB24
(
trk
->
vos_data
)
==
1
||
AV_RB32
(
trk
->
vos_data
)
==
1
))
{
/* extradata is Annex B, assume the bitstream is too and convert it */
if
(
trk
->
hint_track
>=
0
&&
trk
->
hint_track
<
mov
->
nb_streams
)
{
ff_hevc_annexb2mp4_buf
(
pkt
->
data
,
&
reformatted_data
,
&
size
,
0
,
NULL
);
avio_write
(
pb
,
reformatted_data
,
size
);
}
else
{
size
=
ff_hevc_annexb2mp4
(
pb
,
pkt
->
data
,
pkt
->
size
,
0
,
NULL
);
}
}
else
{
avio_write
(
pb
,
pkt
->
data
,
size
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录