At Clarifai we've been offering our video solution for a while, but until now it was a bit limited since we required analysis on every second of footage (e.g. 60-second video = 60 operations).
Fortunately, those days are over!
With our new sampling parameter you'll have the option to get predictions for every 2 seconds, or every 3 seconds, etc. depending on what your use case requires.
Note that the sampling parameter must be greater than or equal to 1,000. Or in other words, you have to get tags every X seconds where X is at least 1.
Here's how to do it in all our API clients! Just change that sample parameter (set to the default 1,000 here) where applicable. Also note that these examples feature URLs but you can tweak them a bit to account for local files as well.
cURL
curl -X POST \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"inputs": [
{
"data": {
"video": {
"url": "https://samples.clarifai.com/beer.mp4"
}
}
}
],
"model": {
"output_info": {
"output_config": {
"sample_ms": 1000
}
}
}
}'\
https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs
Python
app = ClarifaiApp(api_key='YOUR_API_KEY')
m = app.public_models.general_model
response = m.predict_by_url('https://samples.clarifai.com/beer.mp4',
is_video=True,
sample_ms=1000)
JavaScript
const app = new Clarifai.App({apiKey: 'YOUR_API_KEY'});
app.models.predict(
Clarifai.GENERAL_MODEL,
'https://samples.clarifai.com/beer.mp4',
{video: true, sampleMs: 1000})
.then(response => {
// Do something with the output
})
});
Java
ClarifaiClient client = new ClarifaiBuilder("YOUR_API_KEY")
.buildSync();
VideoModel model = client .getDefaultModels().generalVideoModel();
ClarifaiResponse<List<ClarifaiOutput<Frame>>> response = model.predict()
.withInputs(ClarifaiInput.forVideo("https://samples.clarifai.com/beer.mp4"))
.withSampleMs(1000)
.executeSync();
C#
var client = new ClarifaiClient("YOUR_API_KEY");
VideoModel model = client.PublicModels.GeneralVideoModel;
ClarifaiResponse<ClarifaiOutput<Frame>> response = await model
.Predict(
input: new ClarifaiURLVideo("https://samples.clarifai.com/beer.mp4"),
sampleMs: 1000
)
.ExecuteAsync();
PHP
$client = new ClarifaiClient('YOUR_API_KEY');
/** @var VideoModel $model */
$model = $client->publicModels()->generalVideoModel();
$response = $model->predict(
new ClarifaiURLVideo('https://samples.clarifai.com/beer.mp4'))
->withSampleMs(1000)
->executeSync();