-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathav_subtitles.cpp
119 lines (100 loc) · 2.98 KB
/
av_subtitles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "av_subtitles.hpp"
#include "subtitles_impl.hpp"
av_subtitles::av_subtitles(void)
: m_impl(new subtitles_impl())
{
}
av_subtitles::~av_subtitles(void)
{
delete m_impl;
}
bool av_subtitles::open_subtilte(const std::string& filename, int width, int height, int index /*= 0*/)
{
return m_impl->open_subtilte(filename, width, height, index);
}
std::vector<std::string> av_subtitles::subtitle_list()
{
return m_impl->subtitle_list();
}
bool av_subtitles::subtitle_do(void* yuv420_data, long long time_stamp)
{
return m_impl->subtitle_do(yuv420_data, time_stamp);
}
void av_subtitles::close()
{
m_impl->close();
}
void av_subtitles::time_offset(long long offset)
{
}
void av_subtitles::set_font(const std::string& font)
{
m_impl->set_font(font);
}
#include "av_subtitles.h"
#ifdef __cplusplus
extern "C" {
#endif
// C接口导出.
// 分配一个av_subtitle_handle句柄.
// 必须使用free_subtitle来释放.
av_subtitle_handle alloc_subtitle()
{
av_subtitle_handle h = (av_subtitle_handle)new av_subtitles();
return h;
}
// 释放分配的av_subtitle_handle.
// handle 必须是由alloc_subtitle分配的av_subtitle_handle.
void free_subtitle(av_subtitle_handle handle)
{
av_subtitles* h = (av_subtitles*)handle;
delete h;
}
// handle 已经分配好的av_subtitle_handle.
// filename 打开一个字幕(或内含字幕流的视频)文件.
// width 指定将来渲染画面的宽, 必须和视频原宽一至.
// height 指定将来渲染画面的高, 必须和视频原高一至.
// index 字幕流索引, 默认第1个字幕流.
// 打开成功返回0, 失败返回非0.
int open_subtitle(av_subtitle_handle handle,
const char* filename, int width, int height, int index)
{
av_subtitles* h = (av_subtitles*)handle;
return h->open_subtilte(filename, width, height, index) ? 0 : -1;
}
// 渲染一帧字幕到YUV420图片上.
// handle 已经分配好的av_subtitle_handle.
// yuv420_data 指定的yuv420数据, 必须按
// planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)编码.
// 宽和高在open_subtilte被指定.
// time_stamp 时间戳, 单位ms(毫秒).
void subtitle_do(av_subtitle_handle handle,
void* yuv420_data, long long time_stamp)
{
av_subtitles* h = (av_subtitles*)handle;
h->subtitle_do(yuv420_data, time_stamp);
}
// 关闭字幕.
// handle 指定被open_subtitle打开的handle.
void close_subtitle(av_subtitle_handle handle)
{
av_subtitles* h = (av_subtitles*)handle;
h->close();
}
// 指定字体文件, 在调用open_subtilte前设置.
// font 为指定的字体文件完整路径.
void set_font(av_subtitle_handle handle, const char* font)
{
av_subtitles* h = (av_subtitles*)handle;
h->set_font(font);
}
// 修改时间偏移.
// offset 表示时间偏移, +向前, -向后. 单位ms(毫秒).
void time_offset(av_subtitle_handle handle, long long offset)
{
av_subtitles* h = (av_subtitles*)handle;
h->time_offset(offset);
}
#ifdef __cplusplus
}
#endif