Can I set the duration of an image overlay to be the same as the underlying video?

I want to overlay a watermark on top of a video but I don’t know the length of the video ahead of rendering it. Is it possible to make the watermark only appear for the length of the underlying video?

Hi Jack,

Yes you can use the media inspector API for this. This API provides you with metadata on how properties like the duration of your video.

In the following example I want to add a watermark to a video, but am unaware how long the video duration is.

Assets

Watermark (scaled)

Video

Get video metadata

GET request to Media Inspector API

Make sure to encode your URL.

curl --location --request GET 'https://api.shotstack.io/stage/probe/https%3A%2F%2Fshotstack-assets.s3.amazonaws.com%2Ffootage%2Ftrees.mp4'

Response

The below is truncated to only show the relevant bits.

{
    "success": true,
    "message": "ok",
    "response": {
        "metadata": {
            "streams": [
                {
                    ...,
                    "width": 1920,
                    "height": 1080,
                    ...,
                    "duration_ts": 480450,
                    "duration": "16.015000",
                    ...
                }
            ],
            "chapters": [],
            "format": {
                ...,
                "duration": "16.020000",
                "size": "9543594",
                "bit_rate": "4765839",
                ...
            }
        }
    }
}

Use Media Inspector data to inform render

{
    "timeline": {
        "soundtrack": {
            "src": "https://shotstack-assets.s3-ap-southeast-2.amazonaws.com/music/unminus/berlin.mp3",
            "effect": "fadeOut"
        },
        "background": "#000000",
        "tracks": [
            {
                "clips": [
                    {
                        "asset": {
                            "type": "image",
                            "src": "https://shotstack-assets.s3.amazonaws.com/logos/yellow-square.png"
                        },
                        "start": 0,
                        "length": 16.02,
                        "fit": "none",
                        "position": "topRight",
                        "offset": {
                            "x": -0.03,
                            "y": -0.03
                        },
                        "scale": 0.4
                    }
                ]
            },
            {
                "clips": [
                    {
                        "asset": {
                            "type": "video",
                            "src": "https://shotstack-assets.s3.amazonaws.com/footage/trees.mp4",
                            "trim": 5
                        },
                        "start": 0,
                        "length": 16.02
                    }
                ]
            }
        ]
    },
    "output": {
        "format": "mp4",
        "resolution": "hd"
    }
}