转码端API使用
该API包括部分转码端数据处理,生成截图、获取试看m3u8、实时生成mp4、远程创建转码任务等。
以下API
使用中所提到的path
参数不仅可用于服务器上的视频文件,亦可用于任何远程链接形式存在的视频文件,支持格式有以下几种:
/path/2.m3u8
./public/videos/3.mp4
public/videos/4.m3u8
http://127.0.0.1:3000/videos/202006/12/5ed37e23d6334d5540c43b00/d1052c/index.m3u8
http://127.0.0.1:3000/videos/6.mp4
所用到的apikey
和apisecret
参数均在转码设置中设置,且需打开api
。
生成单张截图
post: /apifluent/screenshot
body: {
apikey,
apisecret,
path, // 支持服务器视频文件绝对路径,服务器视频相对路径,服务器源码目录相对路径,远程m3u8连接,远程视频文件链接等。
duration, // 需要截图视频什么时间的画面,单位是秒。
}
response: {
success: 0|1, // 成功或者失败
error, // 如果失败会返回错误信息。
screenshot, // 截图的链接。
}
批量生成截图
post: /apifluent/screenshots
body: {
apikey,
apisecret,
path,
counts //截图数量,会根据视频时间轴,均分截取,比如10秒视频,设置counts为3,则可能截图3,6,9秒的画面。
}
response: {
success: 0|1,
error, //如果有错误信息会返回错误信息。
screenshots, //数组,包含所有截图链接。
}
生成动态图
post: /apifluent/togif
data: {
apikey,
apisecret,
path, //必填,下面的参数选填。
duration, // 生成多少秒动态图,默认1秒
width, //动态图宽度,高度自适应, 默认400宽度
gifstart, // 从视频多少秒开始生成, 默认10秒
auto //是否自动截取视频最中间位置,接收1或0,设置了auto,则gifstart是否设置都无效,默认是0。
}
response: {
success: 0|1,
error,
gif //动态图链接
}
获取视频元信息,即metadata信息
post: /apifluent/metadata
body: {
apikey,
apisecret,
path
}
response: {
success: 1|0,
error,
data // 视频的各种信息,包括音频流,视频流等。
}
data
返回样式样式:
{
"success": 1,
"data": {
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "1/48",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 854,
"height": 480,
"coded_width": 864,
"coded_height": 480,
"has_b_frames": 2,
"sample_aspect_ratio": "N/A",
"display_aspect_ratio": "N/A",
"pix_fmt": "yuv420p",
"level": 30,
"color_range": "unknown",
"color_space": "unknown",
"color_transfer": "unknown",
"color_primaries": "unknown",
"chroma_location": "left",
"field_order": "unknown",
"timecode": "N/A",
"refs": 1,
"is_avc": "true",
"nal_length_size": 4,
"id": "N/A",
"r_frame_rate": "24/1",
"avg_frame_rate": "24/1",
"time_base": "1/24",
"start_pts": 0,
"start_time": 0,
"duration_ts": 1253,
"duration": 52.208333,
"bit_rate": 537875,
"max_bit_rate": "N/A",
"bits_per_raw_sample": 8,
"nb_frames": 1253,
"nb_read_frames": "N/A",
"nb_read_packets": "N/A",
"tags": {
"creation_time": "1970-01-01T00:00:00.000000Z",
"language": "und",
"handler_name": "VideoHandler"
},
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "LC",
"codec_type": "audio",
"codec_time_base": "1/48000",
"codec_tag_string": "mp4a",
"codec_tag": "0x6134706d",
"sample_fmt": "fltp",
"sample_rate": 48000,
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"id": "N/A",
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/48000",
"start_pts": 0,
"start_time": 0,
"duration_ts": 2493440,
"duration": 51.946667,
"bit_rate": 126694,
"max_bit_rate": 128000,
"bits_per_raw_sample": "N/A",
"nb_frames": 2435,
"nb_read_frames": "N/A",
"nb_read_packets": "N/A",
"tags": {
"creation_time": "1970-01-01T00:00:00.000000Z",
"language": "und",
"handler_name": "SoundHandler"
},
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
}
],
"format": {
"filename": "https://media.w3.org/2010/05/sintel/trailer.mp4",
"nb_streams": 2,
"nb_programs": 0,
"format_name": "mov,mp4,m4a,3gp,3g2,mj2",
"format_long_name": "QuickTime / MOV",
"start_time": 0,
"duration": 52.209,
"size": 4372373,
"bit_rate": 669979,
"probe_score": 100,
"tags": {
"major_brand": "isom",
"minor_version": "512",
"compatible_brands": "isomiso2avc1mp41",
"creation_time": "1970-01-01T00:00:00.000000Z",
"title": "Sintel Trailer",
"artist": "Durian Open Movie Team",
"encoder": "Lavf52.62.0",
"copyright": "(c) copyright Blender Foundation | durian.blender.org",
"description": "Trailer for the Sintel open movie project"
}
},
"chapters": []
}
}
获取试看m3u8格式文本
GET /apifluent/try
headers: {
apikey,
apisecret,
}
query: {
id:视频ID,
duration:试看时长,
hd:指定分辨率,
}
response: m3u8文本 //获取到文本可自行组装自己的m3u8路由。
hd
参数值,320
为240P
、480
为360P
、640
为480P
、1138
为640P
、1280
为720P
、1920
为1080P
、2560
为2K
、20000
为原画。
且hd
和duration
参数可选,默认60
秒试看和最大分辨率,该接口会返回试看m3u8
的文本内容,请自行构建自己的m3u8
路由,勿直接前端使用本接口。
根据视频id和分辨率实时生成mp4
post: /apifluent/savestream
data: {
apikey,
apisecret,
id, //视频库中存在的转码完成的id,
hd //指定生成某分辨率,支持240,360,480,640,720,1080,1440,20000
}
response: {
success: 1|0,
host, // 服务端域名
path, // mp4链接
message // 显示信息
}
此API
可用于提供下载功能时,无需保存mp4
,完全实时根据m3u8
生成mp4
文件,并且返回,秒级反馈。
远程检测转码服务器运行/连接状态
post: /apifluent/ping
data: {
apikey,
apisecret,
}
response: {
success: 1, //1为运行并连接正常,
}
此API
可检测转码程序运行状态,或者和远程转码程序连接情况是否正常。
远程创建转码任务
post: /apifluent/createjob
data: {
apikey,
apisecret,
clientId, //传递一个数据库id,即客户端辨识视频id,返回信息的时候会返回该id,让你对应并进行数据填充。
remotePath, //远程视频地址,即可访问的视频地址
notifyUrl //通知域名,转码完成的clientId、视频名称、m3u8链接、海报截图会自动回传到这个地址。
}
{
"success": 1|0 //1为创建成功
}
此API
可远程创建任务,并调用远程连接转码,建议配合队列转码一起使用,这样创建任务后后,会自动转码,自动返回数据,无需后台操作。
回传数据参考:
{
success: 1,
movie: {
count: 0,
retry: false,
director: [],
writer: [],
stars: [],
country: [],
tags: [],
screenshots: [],
_id: '5fe19c79cb8b853f256a458f',
status: '转码完成',
originalname: '远程测试.avi',
path: './download/远程测试.avi',
size: '112406774',
notifyUrl: 'https://www.beefun.cc/api/payback',
clientId: '5fe19c7888f5be253328806a',
m3u8paths: [ [Object], [Object], [Object] ],
thirdm3u8: [],
createAt: '2020-12-22T07:15:47.300Z',
__v: 0,
duration: '3分钟',
moviepath: '/videos/202012/22/5fe19c79cb8b853f256a458f',
previewvideo: '/videos/202012/22/5fe19c79cb8b853f256a458f/preview.mp4',
poster: '/videos/202012/22/5fe19c79cb8b853f256a458f/cover.jpg'
},
apikey: '5c20cEga22FgG7f7B1c1',
apisecret: 'cd5c5ffd476f93602135'
}
[
[Object: null prototype] {
id: '5fc7242b0446292f13401fe2',
domain: 'https://demo.efvcms.com'
}
]
{
title: '远程测试.avi',
url: '240P$https://demo.efvcms.com/videos/202012/22/5fe19c79cb8b853f256a458f/3413b2/index.m3u8#480P$https://demo.efvcms.com/videos/202012/22/5fe19c79cb8b853f256a458f/927817/index.m3u8#',
server: { connect: { id: '5fc7242b0446292f13401fe2' } }
}
远程创建转码任务并对视频进行裁剪截取
//注意如果远程视频够大,可能需要耐心等待片刻
post: /apifluent/cut
data: {
apikey,
apisecret,
start, //裁剪起始时间,规范为时:分:秒,如 00:00:12
end, //裁剪结束时间,规范为时:分:秒,如 00:00:22
video, //远程视频地址,即可访问的视频地址
notifyUrl //通知域名,转码完成的id、视频名称、m3u8链接、海报截图会自动回传到这个地址。
}
{
"success": 1|0 //1为创建成功
}
此API
可远程创建任务,并调用远程连接转码,建议配合队列转码一起使用,这样创建任务后后,会自动转码,自动返回数据,无需后台操作。
回传数据参考:
#返回数据仅供参考,实际情况可能会有不一样
{
success: 1,
movie: {
count: 0,
retry: false,
director: [],
writer: [],
stars: [],
country: [],
tags: [],
screenshots: [],
_id: '5fe19c79cb8b853f256a458f',
status: '转码完成',
originalname: '远程测试.avi',
path: './download/远程测试.avi',
size: '112406774',
notifyUrl: 'https://www.beefun.cc/api/payback',
clientId: '5fe19c7888f5be253328806a',
m3u8paths: [ [Object], [Object], [Object] ],
thirdm3u8: [],
createAt: '2020-12-22T07:15:47.300Z',
__v: 0,
duration: '3分钟',
moviepath: '/videos/202012/22/5fe19c79cb8b853f256a458f',
previewvideo: '/videos/202012/22/5fe19c79cb8b853f256a458f/preview.mp4',
poster: '/videos/202012/22/5fe19c79cb8b853f256a458f/cover.jpg'
},
apikey: '5c20cEga22FgG7f7B1c1',
apisecret: 'cd5c5ffd476f93602135'
}
[
[Object: null prototype] {
domain: 'https://demo.efvcms.com'
}
]
{
title: '远程测试.avi',
url: '240P$https://demo.efvcms.com/videos/202012/22/5fe19c79cb8b853f256a458f/3413b2/index.m3u8#480P$https://demo.efvcms.com/videos/202012/22/5fe19c79cb8b853f256a458f/927817/index.m3u8#',
server: { connect: { id: '5fc7242b0446292f13401fe2' } }
}
远程删除视频库视频
delete: /apifluent/delete?id=5fcf24ed3fd3764f5b40f95f
data: {
apikey,
apisecret
}
{
"success": 1|0 //1为删除成功
}
注意id=5fcf24ed3fd3764f5b40f95f
,此id
是EFV
中视频的id
,在远程创建任务,并转码服务完成时会带上efv
中的id
传递到notifyUrl
上,对接的系统接收到此id
储存到自己的数据库中,在删除时就请求delete
删除efv
中的视频数据和切片图片等一切内容。