Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
79fdbfdb
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,发现更多精彩内容 >>
提交
79fdbfdb
编写于
4月 14, 2016
作者:
L
Luca Barbato
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
img2enc: Refactor the atomic renaming code
And use it for the separate-plane side-feature as well. Bug-Id: 935
上级
f3fdef10
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
27 deletion
+46
-27
libavformat/img2enc.c
libavformat/img2enc.c
+46
-27
未找到文件。
libavformat/img2enc.c
浏览文件 @
79fdbfdb
...
...
@@ -28,12 +28,17 @@
#include "internal.h"
#include "libavutil/opt.h"
typedef
struct
RenameIO
{
AVIOContext
*
pb
;
char
filename
[
1024
];
char
tmp
[
1024
];
}
RenameIO
;
typedef
struct
VideoMuxData
{
const
AVClass
*
class
;
/**< Class for private options. */
int
img_number
;
int
is_pipe
;
char
path
[
1024
];
char
tmp
[
1024
];
int
update
;
}
VideoMuxData
;
...
...
@@ -42,7 +47,6 @@ static int write_header(AVFormatContext *s)
VideoMuxData
*
img
=
s
->
priv_data
;
av_strlcpy
(
img
->
path
,
s
->
filename
,
sizeof
(
img
->
path
));
snprintf
(
img
->
tmp
,
sizeof
(
img
->
tmp
),
"%s.tmp"
,
s
->
filename
);
/* find format */
if
(
s
->
oformat
->
flags
&
AVFMT_NOFILE
)
...
...
@@ -53,10 +57,28 @@ static int write_header(AVFormatContext *s)
return
0
;
}
static
int
open_temporary
(
AVFormatContext
*
s
,
RenameIO
*
out
,
const
char
*
filename
)
{
snprintf
(
out
->
tmp
,
sizeof
(
out
->
tmp
),
"%s.tmp"
,
filename
);
av_strlcpy
(
out
->
filename
,
filename
,
sizeof
(
out
->
filename
));
if
(
s
->
io_open
(
s
,
&
out
->
pb
,
out
->
tmp
,
AVIO_FLAG_WRITE
,
NULL
)
<
0
)
{
av_log
(
s
,
AV_LOG_ERROR
,
"Could not open file : %s
\n
"
,
out
->
tmp
);
return
AVERROR
(
EIO
);
}
return
0
;
}
static
void
close_and_rename
(
AVFormatContext
*
s
,
RenameIO
*
out
)
{
ff_format_io_close
(
s
,
&
out
->
pb
);
ff_rename
(
out
->
tmp
,
out
->
filename
);
}
static
int
write_packet
(
AVFormatContext
*
s
,
AVPacket
*
pkt
)
{
VideoMuxData
*
img
=
s
->
priv_data
;
AVIOContext
*
pb
[
3
];
RenameIO
out
[
3
];
char
filename
[
1024
];
AVCodecParameters
*
par
=
s
->
streams
[
pkt
->
stream_index
]
->
codecpar
;
int
i
;
...
...
@@ -72,26 +94,24 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return
AVERROR
(
EIO
);
}
for
(
i
=
0
;
i
<
3
;
i
++
)
{
if
(
s
->
io_open
(
s
,
&
pb
[
i
],
img
->
tmp
,
AVIO_FLAG_WRITE
,
NULL
)
<
0
)
{
av_log
(
s
,
AV_LOG_ERROR
,
"Could not open file : %s
\n
"
,
img
->
tmp
);
return
AVERROR
(
EIO
);
}
int
ret
=
open_temporary
(
s
,
&
out
[
i
],
filename
);
if
(
ret
<
0
)
return
ret
;
if
(
par
->
codec_id
!=
AV_CODEC_ID_RAWVIDEO
)
break
;
filename
[
strlen
(
filename
)
-
1
]
=
'U'
+
i
;
}
}
else
{
pb
[
0
]
=
s
->
pb
;
out
[
0
].
pb
=
s
->
pb
;
}
if
(
par
->
codec_id
==
AV_CODEC_ID_RAWVIDEO
)
{
int
ysize
=
par
->
width
*
par
->
height
;
avio_write
(
pb
[
0
]
,
pkt
->
data
,
ysize
);
avio_write
(
pb
[
1
]
,
pkt
->
data
+
ysize
,
(
pkt
->
size
-
ysize
)
/
2
);
avio_write
(
pb
[
2
]
,
pkt
->
data
+
ysize
+
(
pkt
->
size
-
ysize
)
/
2
,
(
pkt
->
size
-
ysize
)
/
2
);
ff_format_io_close
(
s
,
&
pb
[
1
]);
ff_format_io_close
(
s
,
&
pb
[
2
]);
avio_write
(
out
[
0
].
pb
,
pkt
->
data
,
ysize
);
avio_write
(
out
[
1
].
pb
,
pkt
->
data
+
ysize
,
(
pkt
->
size
-
ysize
)
/
2
);
avio_write
(
out
[
2
].
pb
,
pkt
->
data
+
ysize
+
(
pkt
->
size
-
ysize
)
/
2
,
(
pkt
->
size
-
ysize
)
/
2
);
close_and_rename
(
s
,
&
out
[
1
]);
close_and_rename
(
s
,
&
out
[
2
]);
}
else
{
if
(
ff_guess_image2_codec
(
s
->
filename
)
==
AV_CODEC_ID_JPEG2000
)
{
AVStream
*
st
=
s
->
streams
[
0
];
...
...
@@ -100,15 +120,15 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
if
(
pkt
->
size
<
8
||
AV_RL32
(
pkt
->
data
+
4
)
!=
MKTAG
(
'j'
,
'p'
,
'2'
,
'c'
))
goto
error
;
avio_wb32
(
pb
[
0
]
,
12
);
ffio_wfourcc
(
pb
[
0
]
,
"jP "
);
avio_wb32
(
pb
[
0
]
,
0x0D0A870A
);
// signature
avio_wb32
(
pb
[
0
]
,
20
);
ffio_wfourcc
(
pb
[
0
]
,
"ftyp"
);
ffio_wfourcc
(
pb
[
0
]
,
"jp2 "
);
avio_wb32
(
pb
[
0
]
,
0
);
ffio_wfourcc
(
pb
[
0
]
,
"jp2 "
);
avio_write
(
pb
[
0
]
,
st
->
codecpar
->
extradata
,
st
->
codecpar
->
extradata_size
);
avio_wb32
(
out
[
0
].
pb
,
12
);
ffio_wfourcc
(
out
[
0
].
pb
,
"jP "
);
avio_wb32
(
out
[
0
].
pb
,
0x0D0A870A
);
// signature
avio_wb32
(
out
[
0
].
pb
,
20
);
ffio_wfourcc
(
out
[
0
].
pb
,
"ftyp"
);
ffio_wfourcc
(
out
[
0
].
pb
,
"jp2 "
);
avio_wb32
(
out
[
0
].
pb
,
0
);
ffio_wfourcc
(
out
[
0
].
pb
,
"jp2 "
);
avio_write
(
out
[
0
].
pb
,
st
->
codecpar
->
extradata
,
st
->
codecpar
->
extradata_size
);
}
else
if
(
pkt
->
size
<
8
||
(
!
st
->
codecpar
->
extradata_size
&&
AV_RL32
(
pkt
->
data
+
4
)
!=
MKTAG
(
'j'
,
'P'
,
' '
,
' '
)))
{
// signature
...
...
@@ -117,12 +137,11 @@ error:
return
-
1
;
}
}
avio_write
(
pb
[
0
]
,
pkt
->
data
,
pkt
->
size
);
avio_write
(
out
[
0
].
pb
,
pkt
->
data
,
pkt
->
size
);
}
avio_flush
(
pb
[
0
]
);
avio_flush
(
out
[
0
].
pb
);
if
(
!
img
->
is_pipe
)
{
ff_format_io_close
(
s
,
&
pb
[
0
]);
ff_rename
(
img
->
tmp
,
filename
);
close_and_rename
(
s
,
&
out
[
0
]);
}
img
->
img_number
++
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录