人像渐变
<p>[TOC]</p>
<h3>描述</h3>
<ul>
<li>输入2-5张人脸照片,生成一段以人脸为焦点的渐变视频或GIF图,支持自定义图片播放速度、视频每秒传输帧数,可用于短视频、表情包、创意H5等应用场景,丰富静态图片的玩法。</li>
</ul>
<h3>1 使用流程</h3>
<h4>1.1 第一步 - 发起任务</h4>
<ul>
<li>根据传入的图片、视频类型等参数创建任务,获取jobId参数。</li>
<li>默认接口请求频率限制:1次/秒。</li>
</ul>
<h4>1.2 第二步 - 查询结果</h4>
<ul>
<li>根据jobId获取任务结果,查询不计费。</li>
</ul>
<hr />
<h3>2 接口调用说明</h3>
<h4>2.1 请求方式</h4>
<p>如接口没有单独说明,均为:<strong>POST</strong></p>
<h4>2.2 请求参数</h4>
<p>请求参数包括公共参数和业务参数(业务参数见具体接口说明)
如果请求格式为application/x-www-form-urlencoded的,需要把<strong>公共参数</strong>和<strong>业务参数</strong>一并放在<strong>请求参数</strong>中提交
如果请求格式为application/json的,需要把<strong>公共参数</strong>放在<strong>请求Header</strong>中提交</p>
<h5>2.2.1 公共参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间戳(毫秒)</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见<a href="#签名算法">签名算法说明</a></td>
</tr>
</tbody>
</table>
<h5>2.2.2 签名算法说明</h5>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳(毫秒) <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h4>2.3 返回说明</h4>
<h5>2.3.1 公共返回字段说明</h5>
<p>所有接口均返回以下公共字段:</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:公共code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,object类型,详见各接口返回说明</td>
</tr>
</tbody>
</table>
<p><a name="code返回码说明"></a></p>
<h5>2.3.2 code返回码说明</h5>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>201</td>
<td>未检测到人脸</td>
</tr>
<tr>
<td>202</td>
<td>人脸出框,无法使用</td>
</tr>
<tr>
<td>203</td>
<td>图片质量问题</td>
</tr>
<tr>
<td>205</td>
<td>任务不存在</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>607</td>
<td>ip不在白名单</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
</tbody>
</table>
<hr />
<h3>3 接口</h3>
<h4>3.1 发起任务</h4>
<ul>
<li>根据传入的图片、视频类型等参数创建任务,获取jobId参数,成功进行计费。</li>
</ul>
<h5>3.1.1 请求地址</h5>
<p><code>https://api.jumdata.com/face/morph/request</code></p>
<h5>3.1.2 请求格式</h5>
<ul>
<li>application/json</li>
</ul>
<h5>3.1.3 请求体参数(RequestBody)</h5>
<ul>
<li>样例</li>
</ul>
<pre><code class="language-json">{
&quot;urls&quot;: [//图片的url。
&quot;https://xxx.jpg&quot;,
&quot;https://xxx.jpg&quot;,
&quot;https://xxx.jpg&quot;
],
&quot;images&quot;: [//图片的base64。
&quot;xxxxxx&quot;,
&quot;xxxxxx&quot;,
&quot;xxxxx&quot;
],
&quot;gradientInfos&quot;: [//可调整每张图片的展示时长、人像渐变的最长时间
{
&quot;tempo&quot;: &quot;0.9F&quot;,//图片的展示时长,即单张图片静止不变的时间。GIF默认每张图片0.7s,视频默认每张图片0.5s。最大取值1s。
&quot;morphTime&quot;: &quot;0.9F&quot; //人像渐变的最长时间,即单张图片使用渐变特效的时间。 GIF默认值为0.5s,视频默值认为1s。最大取值1s。
}
],
&quot;fps&quot;: &quot;12&quot;,//视频帧率,取值[1,25]。默认10
&quot;outputWidth&quot;: &quot;1280&quot;,//视频宽度,取值[128,1280]。默认值720
&quot;outputHeight&quot;: &quot;1280&quot; //视频高度,取值[128,1280]。默认值1280
}</code></pre>
<ul>
<li>图片base64编码后大小不可超过5M。</li>
<li>urls、images必须提供一个,优先url。</li>
<li>jpg格式长边像素不可超过4000,其他格式图片长边像素不可超2000。</li>
<li>人员人脸总数量至少2张,不可超过5张。</li>
<li>若图片中包含多张人脸,只选取其中人脸面积最大的人脸。</li>
<li>支持PNG、JPG、JPEG、BMP,不支持GIF图片。</li>
</ul>
<h5>3.1.4 正确返回样例</h5>
<pre><code class="language-json">{
&quot;code&quot;: 200,//返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;,//返回码对应描述
&quot;taskNo&quot;: &quot;340419447206566228602625&quot;,//本次请求号
&quot;charge&quot;: true,//计费标志,true 计费,false 不计费
&quot;data&quot;: {
&quot;jobId&quot;: &quot;1220203056839442432&quot;,//任务的jobId
&quot;estimatedProcessTime&quot;: 30 //预估处理时间,单位秒
}
}</code></pre>
<h5>3.1.5 错误返回样例</h5>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;音频url不能为空&quot;
}</code></pre>
<h4>3.2 查询结果</h4>
<ul>
<li>根据jobId获取任务结果,查询不计费</li>
</ul>
<h5>3.2.1 请求地址</h5>
<p><code>https://api.jumdata.com/face/morph/result</code></p>
<h5>3.2.2 请求格式</h5>
<ul>
<li>application/x-www-form-urlencoded</li>
</ul>
<h5>3.2.3 业务参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>jobId</td>
<td>String</td>
<td>是</td>
<td>任务id,任务发起接口返回</td>
</tr>
</tbody>
</table>
<h5>3.2.4 正确返回样例</h5>
<pre><code class="language-json">{
&quot;charge&quot;: true,//计费标志,true 计费,false 不计费
&quot;code&quot;: 200,//返回code
&quot;msg&quot;: &quot;成功&quot;,//code对应的说明描述
&quot;taskNo&quot;: &quot;291798783211648226804924&quot;, //本次请求号
&quot;data&quot;: {
&quot;imgUrl&quot;: &quot;https://xxx.mp4&quot;,//结果url,有效期10天。建议自行下载保存,避免丢失
&quot;jobStatus&quot;: &quot;处理完成&quot;,//当前任务状态:排队中、处理中、处理失败或者处理完成
&quot;coverImage&quot;: &quot;&quot;,//封面图base64字符串
&quot;jobStatusCode&quot;: &quot;7&quot;,//当前任务状态码:1:排队中、3: 处理中、5: 处理失败、7:处理完成。
&quot;md5&quot;: &quot;05ADF41E9162CA13DD239C5F2595BDAB&quot; //人像渐变输出的结果MD5,用于校验
}
}
</code></pre>
<h5>3.2.5 错误返回样例</h5>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;jobId不能为空&quot;
}</code></pre>