Search in sources :

Example 1 with Overlay

use of com.google.cloud.video.transcoder.v1.Overlay in project java-docs-samples by GoogleCloudPlatform.

the class CreateJobWithStaticOverlay method createJobWithStaticOverlay.

// Creates a job from an ad-hoc configuration and adds a static overlay to it.
public static void createJobWithStaticOverlay(String projectId, String location, String inputUri, String overlayImageUri, String outputUri) throws IOException {
    // once, and can be reused for multiple requests.
    try (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
        VideoStream videoStream0 = VideoStream.newBuilder().setH264(VideoStream.H264CodecSettings.newBuilder().setBitrateBps(550000).setFrameRate(60).setHeightPixels(360).setWidthPixels(640)).build();
        AudioStream audioStream0 = AudioStream.newBuilder().setCodec("aac").setBitrateBps(64000).build();
        // Create the overlay image. Only JPEG is supported. Image resolution is based on output
        // video resolution. To respect the original image aspect ratio, set either x or y to 0.0.
        // This example stretches the overlay image the full width and half of the height of the
        // output video.
        Overlay.Image overlayImage = Overlay.Image.newBuilder().setUri(overlayImageUri).setResolution(NormalizedCoordinate.newBuilder().setX(1).setY(0.5).build()).setAlpha(1).build();
        // Create the starting animation (when the overlay appears). Use the values x: 0 and y: 0 to
        // position the top-left corner of the overlay in the top-left corner of the output video.
        Overlay.Animation animationStart = Overlay.Animation.newBuilder().setAnimationStatic(AnimationStatic.newBuilder().setXy(NormalizedCoordinate.newBuilder().setX(0).setY(0).build()).setStartTimeOffset(Duration.newBuilder().setSeconds(0).build()).build()).build();
        // Create the ending animation (when the overlay disappears). In this example, the overlay
        // disappears at the 10-second mark in the output video.
        Overlay.Animation animationEnd = Overlay.Animation.newBuilder().setAnimationEnd(AnimationEnd.newBuilder().setStartTimeOffset(Duration.newBuilder().setSeconds(10).build()).build()).build();
        // Create the overlay and add the image and animations to it.
        Overlay overlay = Overlay.newBuilder().setImage(overlayImage).addAnimations(animationStart).addAnimations(animationEnd).build();
        JobConfig config = JobConfig.newBuilder().addInputs(Input.newBuilder().setKey("input0").setUri(inputUri)).setOutput(Output.newBuilder().setUri(outputUri)).addElementaryStreams(ElementaryStream.newBuilder().setKey("video_stream0").setVideoStream(videoStream0)).addElementaryStreams(ElementaryStream.newBuilder().setKey("audio_stream0").setAudioStream(audioStream0)).addMuxStreams(MuxStream.newBuilder().setKey("sd").setContainer("mp4").addElementaryStreams("video_stream0").addElementaryStreams("audio_stream0").build()).addOverlays(// Add the overlay to the job config
        overlay).build();
        var createJobRequest = CreateJobRequest.newBuilder().setJob(Job.newBuilder().setInputUri(inputUri).setOutputUri(outputUri).setConfig(config).build()).setParent(LocationName.of(projectId, location).toString()).build();
        // Send the job creation request and process the response.
        Job job = transcoderServiceClient.createJob(createJobRequest);
        System.out.println("Job: " + job.getName());
    }
}
Also used : TranscoderServiceClient(com.google.cloud.video.transcoder.v1.TranscoderServiceClient) AudioStream(com.google.cloud.video.transcoder.v1.AudioStream) VideoStream(com.google.cloud.video.transcoder.v1.VideoStream) Overlay(com.google.cloud.video.transcoder.v1.Overlay) Job(com.google.cloud.video.transcoder.v1.Job) JobConfig(com.google.cloud.video.transcoder.v1.JobConfig)

Example 2 with Overlay

use of com.google.cloud.video.transcoder.v1.Overlay in project java-docs-samples by GoogleCloudPlatform.

the class CreateJobWithAnimatedOverlay method createJobWithAnimatedOverlay.

// Creates a job from an ad-hoc configuration and adds an animated overlay to it.
public static void createJobWithAnimatedOverlay(String projectId, String location, String inputUri, String overlayImageUri, String outputUri) throws IOException {
    // once, and can be reused for multiple requests.
    try (TranscoderServiceClient transcoderServiceClient = TranscoderServiceClient.create()) {
        VideoStream videoStream0 = VideoStream.newBuilder().setH264(VideoStream.H264CodecSettings.newBuilder().setBitrateBps(550000).setFrameRate(60).setHeightPixels(360).setWidthPixels(640)).build();
        AudioStream audioStream0 = AudioStream.newBuilder().setCodec("aac").setBitrateBps(64000).build();
        // Create the overlay image. Only JPEG is supported. Image resolution is based on output
        // video resolution. This example uses the values x: 0 and y: 0 to maintain the original
        // resolution of the overlay image.
        Overlay.Image overlayImage = Overlay.Image.newBuilder().setUri(overlayImageUri).setResolution(NormalizedCoordinate.newBuilder().setX(0).setY(0).build()).setAlpha(1).build();
        // Create the starting animation (when the overlay starts to fade in). Use the values x: 0.5
        // and y: 0.5 to position the top-left corner of the overlay in the top-left corner of the
        // output video.
        Overlay.Animation animationFadeIn = Animation.newBuilder().setAnimationFade(AnimationFade.newBuilder().setFadeType(FadeType.FADE_IN).setXy(NormalizedCoordinate.newBuilder().setX(0.5).setY(0.5).build()).setStartTimeOffset(Duration.newBuilder().setSeconds(5).build()).setEndTimeOffset(Duration.newBuilder().setSeconds(10).build()).build()).build();
        // Create the ending animation (when the overlay starts to fade out). The overlay will start
        // to fade out at the 12-second mark in the output video.
        Overlay.Animation animationFadeOut = Animation.newBuilder().setAnimationFade(AnimationFade.newBuilder().setFadeType(FadeType.FADE_OUT).setXy(NormalizedCoordinate.newBuilder().setX(0.5).setY(0.5).build()).setStartTimeOffset(Duration.newBuilder().setSeconds(12).build()).setEndTimeOffset(Duration.newBuilder().setSeconds(15).build()).build()).build();
        // Create the overlay and add the image and animations to it.
        Overlay overlay = Overlay.newBuilder().setImage(overlayImage).addAnimations(animationFadeIn).addAnimations(animationFadeOut).build();
        JobConfig config = JobConfig.newBuilder().addInputs(Input.newBuilder().setKey("input0").setUri(inputUri)).setOutput(Output.newBuilder().setUri(outputUri)).addElementaryStreams(ElementaryStream.newBuilder().setKey("video_stream0").setVideoStream(videoStream0)).addElementaryStreams(ElementaryStream.newBuilder().setKey("audio_stream0").setAudioStream(audioStream0)).addMuxStreams(MuxStream.newBuilder().setKey("sd").setContainer("mp4").addElementaryStreams("video_stream0").addElementaryStreams("audio_stream0").build()).addOverlays(// Add the overlay to the job config
        overlay).build();
        var createJobRequest = CreateJobRequest.newBuilder().setJob(Job.newBuilder().setInputUri(inputUri).setOutputUri(outputUri).setConfig(config).build()).setParent(LocationName.of(projectId, location).toString()).build();
        // Send the job creation request and process the response.
        Job job = transcoderServiceClient.createJob(createJobRequest);
        System.out.println("Job: " + job.getName());
    }
}
Also used : TranscoderServiceClient(com.google.cloud.video.transcoder.v1.TranscoderServiceClient) AudioStream(com.google.cloud.video.transcoder.v1.AudioStream) VideoStream(com.google.cloud.video.transcoder.v1.VideoStream) Overlay(com.google.cloud.video.transcoder.v1.Overlay) Animation(com.google.cloud.video.transcoder.v1.Overlay.Animation) Job(com.google.cloud.video.transcoder.v1.Job) JobConfig(com.google.cloud.video.transcoder.v1.JobConfig)

Aggregations

AudioStream (com.google.cloud.video.transcoder.v1.AudioStream)2 Job (com.google.cloud.video.transcoder.v1.Job)2 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)2 Overlay (com.google.cloud.video.transcoder.v1.Overlay)2 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)2 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)2 Animation (com.google.cloud.video.transcoder.v1.Overlay.Animation)1