Generating Annotation Code/ Watermark
This is used to enter the annotation code. Please refer to the blog for details on writing the annotation code.
The annotation code below would show a dynamic watermark (moving text) displaying the name of the logged-in user.
{
"annotate":"[{'type':'rtext', 'text':' {name}', 'alpha':'0.60', 'color':'0xFF0000','size':'15','interval':'5000', 'skip': '5000'}]"
}
possible mistake
Notice that the annotate parameter needs extra serialisation. This is apart from the general POST body serialisation. This is the JSON.stringify() function in javascript, or the json_encode() function in PHP. Read the sample code below to see examples. Contact us at support@vdocipher.com if your watermark is not showing for you.
Get OTP Sample Codeβ
The sample videoID is 1234567890 and the API Secret Key is a1b2c3d4e5. This sample code only passes the annotation code as parameter.
- CURL
- NODE
- PHP
- C#
- Python
- Ruby
curl -X POST \
https://dev.vdocipher.com/api/videos/1234567890/otp \
-H 'Accept: application/json' \
-H 'Authorization: Apisecret a1b2c3d4e5' \
-H 'Content-Type: application/json' \
-d '{
"annotate":"[{'\''type'\'':'\''rtext'\'', '\''text'\'':'\'' {name}'\'', '\''alpha'\'':'\''0.60'\'', '\''color'\'':'\''0xFF0000'\'','\''size'\'':'\''15'\'','\''interval'\'':'\''5000'\''}]"
}'
var request = require('request');
var options = {
method: 'POST',
url: 'https://dev.vdocipher.com/api/videos/1234567890/otp',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Apisecret a1b2c3d4e5',
},
body: {
annotate: JSON.stringify([
{
type: 'rtext',
text: '{name}',
alpha: '0.60',
color: '0xFF0000',
size: '15',
interval: '5000',
},
]),
},
json: true,
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://dev.vdocipher.com/api/videos/1234567890/otp",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'annotate' => json_encode([[
'type'=>'rtext',
'text'=>'{name}',
'alpha'=>'0.60',
'color'=>'0xFF0000',
'size'=>'15',
'interval'=>'5000'
]]),
]),
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Authorization: Apisecret a1b2c3d4e5",
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
var client = new RestClient("https://dev.vdocipher.com") {
// using user secrets to keep api key
Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(_config["VdoApiKey"], "Apisecret")
};
var otpParameters = new
{
// 5 minutes until OTP is used
// only used when setting up offline, not again
ttl = 300,
// watermark specified below. there can be more
// than one object in this array
annotate= JsonSerializer.Serialize(new [] {new {
type= "rtext",
text= "I am a moving text on video",
alpha= "0.60",
color= "0xFF0000",
size= "15",
interval= "5000",
}})
};
Debug.Assert(videoId?.Length == 32, "videoId is not valid");
var url = $"/api/videos/{videoId}/otp";
var request = new RestRequest(url).AddJsonBody(otpParameters);
var cancellationToken = CancellationToken.None;
var response = await client.ExecutePostAsync(request, cancellationToken);
if (response.Content == null) return Json(new {message= "Invalid API response"});
var otpObject = JsonSerializer.Deserialize<Dictionary<string, string>>(response.Content);
// otpObject contain {otp: string, playbackInfo: string}
return Json(otpObject);
import requests
import json
url = "https://dev.vdocipher.com/api/videos/1234567890/otp"
payload = json.dumps({
"annotate": json.dumps([
{'type':'rtext', 'text':'name', 'alpha':'0.60', 'color':'0xFF0000', 'size':'15','interval':'5000'}
])
})
headers = {
'Authorization': "Apisecret a1b2c3d4e5",
'Content-Type': "application/json",
'Accept': "application/json"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
require 'uri'
require 'json'
require 'net/http'
url = URI("https://dev.vdocipher.com/api/videos/1234567890/otp")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Apisecret a1b2c3d4e5'
request["Content-Type"] = 'application/json'
request["Accept"] = 'application/json'
request.body = {
:annotate => [{
:type=>'rtext',
:text=>'{name}',
:alpha=>'0.60',
:color=>'0xFF0000',
:size=>'15',
:interval=>'5000'
}].to_json
}.to_json
response = http.request(request)
puts response.read_body