src/main/java/com/safestream/sdk/api/watermarking/WatermarkAPI.java
/**
     * Creates a watermarked version of an existing video from an encoding configuration. Using the encoding configuration allows for changes to saturation and resolution as well as adding watermarks to a video.
     *
     * This function allows you to specify the timeout for watermarking completion. Specifying -1 will result in no wait.
     *
     * @param encodingConfiguration {@link EncodingConfiguration}
     * @return A watermark result {@link WatermarkResult}
     * @throws WatermarkAPIException
     */
Creates a watermarked version of an existing video from an encoding configuration. Using the encoding configuration allows for changes to saturation and resolution as well as adding watermarks to a video.
This function allows you to specify the timeout for watermarking completion. Specifying -1 will result in no wait.

@param encodingConfiguration  EncodingConfiguration
@return A watermark result  WatermarkResult
@throws WatermarkAPIException
Creates a watermarked version of an existing video from an encoding configuration . Using the encoding configuration allows for changes to saturation and resolution as well as adding watermarks to a video . This function allows you to specify the timeout for watermarking completion . Specifying - 1 will result in no wait . @param encodingConfiguration EncodingConfiguration @return A watermark result WatermarkResult @throws WatermarkAPIException
public WatermarkResult create(String key, EncodingConfiguration encodingConfiguration, long timeout) throws WatermarkAPIException {
        try {
            Map<String, Object> payload = new HashMap<String, Object>();
            payload.put("key", key);
            payload.put("settings", encodingConfiguration);
            WatermarkResult watermarkResult = safeStreamHttpClient.post(apiResourcePath, payload).getEntity(WatermarkResult.class);
            if(timeout > -1 && !"READY".equals(watermarkResult.getStatus())) {
                long startTime = System.currentTimeMillis();
                boolean ready = false;
                while(!ready && (System.currentTimeMillis() - startTime) < timeout) {
                    WatermarkResult test = safeStreamHttpClient.getEndpoint(watermarkResult.getHref()).getEntity(WatermarkResult.class);
                    if("READY".equals(test.getStatus())) {
                        return test;
                    }
                    try {
                        Thread.sleep(1500);
                    } catch(InterruptedException e) {
                        throw new WatermarkAPIException("Thread interrupted while waiting for watermarking", e);
                    }
                }
                throw new WatermarkAPIException("Timeout reached waiting for video to be watermarked");
            } else {
                return watermarkResult;
            }
        } catch (SafeStreamHttpClientException e) {
            throw new WatermarkAPIException(e);
        }
    }
public WatermarkResult create ( String key , EncodingConfiguration encodingConfiguration , long timeout ) throws WatermarkAPIException { try { Map < String , Object > payload = new HashMap < String , Object > ( ) ; payload . put ( "key" , key ) ; payload . put ( "settings" , encodingConfiguration ) ; WatermarkResult watermarkResult = safeStreamHttpClient . post ( apiResourcePath , payload ) . getEntity ( WatermarkResult . class ) ; if ( timeout > - 1 && ! "READY" . equals ( watermarkResult . getStatus ( ) ) ) { long startTime = System . currentTimeMillis ( ) ; boolean ready = false ; while ( ! ready && ( System . currentTimeMillis ( ) - startTime ) < timeout ) { WatermarkResult test = safeStreamHttpClient . getEndpoint ( watermarkResult . getHref ( ) ) . getEntity ( WatermarkResult . class ) ; if ( "READY" . equals ( test . getStatus ( ) ) ) { return test ; } try { Thread . sleep ( 1500 ) ; } catch ( InterruptedException e ) { throw new WatermarkAPIException ( "Thread interrupted while waiting for watermarking" , e ) ; } } throw new WatermarkAPIException ( "Timeout reached waiting for video to be watermarked" ) ; } else { return watermarkResult ; } } catch ( SafeStreamHttpClientException e ) { throw new WatermarkAPIException ( e ) ; } }
Creates a watermarked version of an existing video from an encoding configuration.
Creates a watermarked version of an existing video from an encoding configuration .
// Make request to SafeStream REST API // TODO: Handle this on a separate thread so that it's not blocking