Skip to content

Commit aaeed1a

Browse files
author
agrandiere
committed
Merge branch 'video-sync'
2 parents c4e2900 + 5172f78 commit aaeed1a

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

README.MD

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,40 @@ sightengine.check(['nudity', 'type', 'properties','wad','faces', 'celebrities'])
108108
```
109109

110110
# Video and Stream Moderation
111-
The first step to detect nudity in a video stream is to submit the video stream to the API.
111+
112+
You can perform either _synchronous_ or _asynchronous_ Video Moderation.
113+
114+
* Synchronous Moderation is simple and easy: the Moderation result is provided directly in the reponse to your API request. Synchronous Moderation is only available for videos that are less than 1 minute long.
115+
* Asynchronous Moderation is available for any video or stream. Moderation results are provided through a so-called callback mechanism. You define a callback URL and the Moderation Engine will send back moderation events to that URL in realtime.
116+
117+
## Synchronous Video Moderation
118+
119+
Beware: this is only for videos that have a duration below 1 minute.
112120

113121
```javascript
114-
sightengine.check(['nudity', 'wad']).video('http://www.quirksmode.org/html5/videos/big_buck_bunny.webm', 'https://example.com/yourcallback').then(function(result) {
122+
sightengine.check(['nudity', 'wad']).video_sync('https://sightengine.com/assets/stream/examples/funfair.mp4').then(function(result) {
115123
// The result of the API
116124
}).catch(function(err) {
117125
// Error
118126
});
119127
```
120128

129+
## Asynchronous Video Moderation
130+
131+
The first step to moderate a video stream is to submit the video stream to the API, along with a callback URL.
132+
133+
```javascript
134+
sightengine.check(['nudity', 'wad']).video('https://sightengine.com/assets/stream/examples/funfair.mp4', 'https://example.com/yourcallback').then(function(result) {
135+
// The result of the API
136+
}).catch(function(err) {
137+
// Error
138+
});
139+
```
140+
141+
Once you have submitted the video, the API will start POSTing moderation updates to your callback URL.
142+
143+
Please see our [Documentation](https://sightengine.com/docs) for more details.
144+
121145
# Feedback
122146
In order to report a misclassification, you need to report the image that was misclassified, the model that was run on this image (models are nudity, face, type, wad), and the correct class of the image.
123147

example.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ sightengine.check(['nudity', 'type', 'properties','wad','faces']).set_bytes(imag
3232

3333
// moderation video
3434

35-
sightengine.check(['nudity', 'type', 'properties','wad','faces']).video('http://www.quirksmode.org/html5/videos/big_buck_bunny.webm', 'http://requestb.in/1d097l71').then(function(result) {
35+
sightengine.check(['nudity', 'type', 'properties','wad','faces']).video('https://sightengine.com/assets/stream/examples/funfair.mp4', 'http://requestb.in/1d097l71').then(function(result) {
36+
console.log(result)
37+
}).catch(function(error) {
38+
console.log(error)
39+
});
40+
41+
sightengine.check(['nudity', 'type', 'properties','wad','faces']).video_sync('https://sightengine.com/assets/stream/examples/funfair.mp4').then(function(result) {
3642
console.log(result)
3743
}).catch(function(error) {
3844
console.log(error)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sightengine",
3-
"version": "1.2.1",
3+
"version": "1.3.1",
44
"description": "",
55
"main": "sightengine.js",
66
"scripts": {

sightengine.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ function makeClient(api_user, api_secret) {
7171
});
7272
};
7373

74+
client.video_sync = (video) => {
75+
var url = endpoint + '/1.0/video/check-sync.json';
76+
const data = { 'stream_url': video, 'models': _models.join(), 'api_user': apiUser, 'api_secret': apiSecret };
77+
const querystring = encodeQueryData(data);
78+
79+
return fetch(url + '?' + querystring, { headers: { 'user-agent': 'SE-SDK-NODEJS' + version} }).then((res) => {
80+
return res.json();
81+
}).catch((error) => {
82+
return error;
83+
});
84+
};
85+
7486
client.feedback = (model, modelClass, image) => {
7587
var url = endpoint + '1.0/feedback.json'
7688

tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,16 @@ describe('video moderation', () => {
9292
})
9393
})
9494

95+
describe('video sync moderation', () => {
96+
it('should return success', () => {
97+
return sightengine
98+
.check(['nudity', 'wad', 'properties', 'type', 'face', 'celebrities'])
99+
.video_sync('https://sightengine.com/assets/stream/examples/funfair.mp4')
100+
.then(result => {
101+
assert.equal('success', result.status)
102+
})
103+
})
104+
})
105+
95106

96107

0 commit comments

Comments
 (0)