Rendering failed while trimming youtube video

I am trying to trim a youtube video as explained here: Trim a video using the editing API — Shotstack
Post Endpoint:

https://api.shotstack.io/stage/render

Body:

{
  "timeline": {
    "tracks": [
      {
        "clips": [
          {
            "asset": {
              "type": "video",
              "src": "https://www.youtube.com/watch?v=xkgMj8V7ffY"
            },
            "start": 0,
            "length": 7
          }
        ]
      }
    ]
  },
  "output": {
    "format": "mp4",
    "resolution": "sd"
  }
}

post API is success with 201 created.

{
    "success": true,
    "message": "Created",
    "response": {
        "message": "Render Successfully Queued",
        "id": "d03bddae-490b-4b32-8b79-975b11b958ae"
    }
}

But after hitting the get asset endpoint with response id in the path the response.status
is coming as failed. Below is the response body

Get Asset Endpoint

https://api.shotstack.io/stage/render/d03bddae-490b-4b32-8b79-975b11b958ae

But response.status is failed

Body:

{
    "success": true,
    "message": "OK",
    "response": {
        "id": "d03bddae-490b-4b32-8b79-975b11b958ae",
        "owner": "f63d04cb2c",
        "plan": "sandbox",
        "status": "failed",
        "error": "Rendering failed: One or more clips is not a valid media file and could not be loaded",
        "duration": 7,
        "billable": 7,
        "renderTime": 434.97,
        "data": {
            "output": {
                "format": "mp4",
                "resolution": "sd"
            },
            "timeline": {
                "tracks": [
                    {
                        "clips": [
                            {
                                "asset": {
                                    "type": "video",
                                    "src": "https://www.youtube.com/watch?v=xkgMj8V7ffY"
                                },
                                "start": 0,
                                "length": 7
                            }
                        ]
                    }
                ]
            }
        },
        "created": "2022-12-31T09:14:11.075Z",
        "updated": "2022-12-31T09:14:12.880Z"
    }
}

The issue is you are using a YouTube web page as the video input. Nitya Satsang Katha || Vakta:-Shashtri Shree Munivatsaldasji Swami || SGVP - Amdavad || 19-11-2022 - YouTube points to a web page which is text/html and not an actual video file, like an mp4 file.

We do not currently support providing a YouTube page URL so you would need to download and serve the YouTube video from a URL on the internet. There are many scripts and tools to download YouTube videos to your own server.

Thanks for the reply within an hour. Ok I got the point.

Let me find the script to download the youtube video from its URL using any script.

1 Like

@lucas.spielberg

For below media url:

https://rr3---sn-npoe7nss.googlevideo.com/videoplayback?expire=1672509889&ei=YCWwY8T0MpeEkgbkrLG4Dw&ip=54.212.247.120&id=o-AFanfMIcKiwqrvbZ4-Mu_1EPeCJ_qEruW6MrnVPtlAim&itag=18&source=youtube&requiressl=yes&vprv=1&mime=video%2Fmp4&ns=oha_tYv76cFy6pu12mcz4lAK&cnr=14&ratebypass=yes&dur=978.465&lmt=1636783010994457&fexp=24001373,24007246&c=WEB&txp=2218224&n=tQ7rAgKyiJ9djB2AI&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgBsfmRPYmeVMhnv4A4stktOQNGBN_6UKMpnu8LiIekq4CIQDXtDgjI54caSdyE0Ys-S4OaQLIyav5lOQbDBfvJTOFRw%3D%3D&cm2rm=sn-nx5ze76&req_id=d978180fbf10a3ee&redirect_counter=2&rm=sn-a5myy7l&cms_redirect=yes&cmsv=e&ipbypass=yes&mh=D1&mip=2405:205:120d:4a08:3022:dfdb:e32:a851&mm=34&mn=sn-npoe7nss&ms=ltu&mt=1672488276&mv=m&mvi=3&pl=41&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRAIgWxrpCcpyC9y05ugMBK5hllDNRwAwVYDhOL_CNC5wEGICIEqH7Pek0y1aLGtwFS87cJPnl6T5T-Ff4YAtUrPDleQM

I am getting response.status as “fetching” instead of “done” or “failed” why ?

This is the response body:

{
    "success": true,
    "message": "OK",
    "response": {
        "id": "a89cac9c-9d83-4360-a493-b34d5827541d",
        "owner": "f63d04cb2c",
        "plan": "sandbox",
        "status": "fetching",
        "error": "",
        "data": {
            "output": {
                "format": "mp4",
                "resolution": "sd"
            },
            "timeline": {
                "tracks": [
                    {
                        "clips": [
                            {
                                "asset": {
                                    "type": "video",
                                    "src": "https://rr3---sn-npoe7nss.googlevideo.com/videoplayback?expire=1672509889&ei=YCWwY8T0MpeEkgbkrLG4Dw&ip=54.212.247.120&id=o-AFanfMIcKiwqrvbZ4-Mu_1EPeCJ_qEruW6MrnVPtlAim&itag=18&source=youtube&requiressl=yes&vprv=1&mime=video%2Fmp4&ns=oha_tYv76cFy6pu12mcz4lAK&cnr=14&ratebypass=yes&dur=978.465&lmt=1636783010994457&fexp=24001373,24007246&c=WEB&txp=2218224&n=tQ7rAgKyiJ9djB2AI&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Ccnr%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgBsfmRPYmeVMhnv4A4stktOQNGBN_6UKMpnu8LiIekq4CIQDXtDgjI54caSdyE0Ys-S4OaQLIyav5lOQbDBfvJTOFRw%3D%3D&cm2rm=sn-nx5ze76&req_id=d978180fbf10a3ee&redirect_counter=2&rm=sn-a5myy7l&cms_redirect=yes&cmsv=e&ipbypass=yes&mh=D1&mip=2405:205:120d:4a08:3022:dfdb:e32:a851&mm=34&mn=sn-npoe7nss&ms=ltu&mt=1672488276&mv=m&mvi=3&pl=41&lsparams=ipbypass,mh,mip,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRAIgWxrpCcpyC9y05ugMBK5hllDNRwAwVYDhOL_CNC5wEGICIEqH7Pek0y1aLGtwFS87cJPnl6T5T-Ff4YAtUrPDleQM"
                                },
                                "start": 0,
                                "length": 7
                            }
                        ]
                    }
                ]
            }
        },
        "created": "2022-12-31T12:13:40.280Z",
        "updated": "2022-12-31T12:13:41.624Z"
    }
}

The file you’re looking to download is quite large. It may take a moment to get downloaded.

I just tried it myself and it all works.

@dazzatron

Thanks for the clarification.

Now I only want one thing: A solution/script to convert a youtube URL to a media URL so I can directly pass it to the shotstack API.

I would appreciate you if you can provide me such a script/api.
I tried y2mate-api but it has some issue.

I just used an online service.

On Google and GitHub there are a plethora of scripts and libraries that will be able to help you out:

https://www.google.com/search?q=youtube+download+link+script

@dazzatron

Again render GET request is failing. response.status is “failed”. Why ?

Post endpoint:

https://api.shotstack.io/{{ENV}}/render

Payload:

{
  "timeline": {
    "tracks": [
      {
        "clips": [
          {
            "asset": {
              "type": "video",
              "src": "https://rr5---sn-gwpa-w5pe7.googlevideo.com/videoplayback?expire=1672920930&ei=Amu2Y8z9LYmivwSSip-gAQ&ip=2405%3A205%3A120d%3A4a08%3A311f%3Aa880%3A2a02%3A4d6d&id=o-AFJWiBKpz4lQG0p0YnoxM0mjM9dcu60npG2R7p_MtART&itag=22&source=youtube&requiressl=yes&mh=yc&mm=31%2C29&mn=sn-gwpa-w5pe7%2Csn-gwpa-qxay&ms=au%2Crdu&mv=m&mvi=5&pl=41&initcwndbps=252500&vprv=1&mime=video%2Fmp4&ratebypass=yes&dur=336.735&lmt=1647934416054398&mt=1672898966&fvip=3&fexp=24007246&c=ANDROID&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhALi5zmn0vFx1d6kZuflCIa8qHEvzxxpqpMoGFjxKGUvzAiBgWh_m8wl8sCWX-v1C-KahZk2-2s4yQBGU2Vta6GODoA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgacF-KJ3UVQ3VOSFtecOSRTvw5EsoSZEe1ibUklT4qHQCIQCNy7_RSqaL2hK1XgWxGf1IpNlCZCC9qiq--Y5M3_mPOg%3D%3D"
            },
            "start": 0,
            "length": 7
          }
        ]
      }
    ]
  },
  "output": {
    "format": "mp4",
    "resolution": "sd"
  }
}

Response:

{
    "success": true,
    "message": "Created",
    "response": {
        "message": "Render Successfully Queued",
        "id": "b8339da1-69c0-4a8d-a861-6451f0746aa8"
    }
}

Get Endpoint:

https://api.shotstack.io/{{ENV}}/render/b8339da1-69c0-4a8d-a861-6451f0746aa8

Response:

{
    "success": true,
    "message": "OK",
    "response": {
        "id": "b8339da1-69c0-4a8d-a861-6451f0746aa8",
        "owner": "f63d04cb2c",
        "plan": "sandbox",
        "status": "failed",
        "error": "An error occurred downloading file https://rr5---sn-gwpa-w5pe7.googlevideo.com/videoplayback?expire=1672920930&ei=Amu2Y8z9LYmivwSSip-gAQ&ip=2405%3A205%3A120d%3A4a08%3A311f%3Aa880%3A2a02%3A4d6d&id=o-AFJWiBKpz4lQG0p0YnoxM0mjM9dcu60npG2R7p_MtART&itag=22&source=youtube&requiressl=yes&mh=yc&mm=31%2C29&mn=sn-gwpa-w5pe7%2Csn-gwpa-qxay&ms=au%2Crdu&mv=m&mvi=5&pl=41&initcwndbps=252500&vprv=1&mime=video%2Fmp4&ratebypass=yes&dur=336.735&lmt=1647934416054398&mt=1672898966&fvip=3&fexp=24007246&c=ANDROID&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhALi5zmn0vFx1d6kZuflCIa8qHEvzxxpqpMoGFjxKGUvzAiBgWh_m8wl8sCWX-v1C-KahZk2-2s4yQBGU2Vta6GODoA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgacF-KJ3UVQ3VOSFtecOSRTvw5EsoSZEe1ibUklT4qHQCIQCNy7_RSqaL2hK1XgWxGf1IpNlCZCC9qiq--Y5M3_mPOg%3D%3D. Server responded with getaddrinfo ENOTFOUND rr5---sn-gwpa-w5pe7.googlevideo.com",
        "data": {
            "output": {
                "format": "mp4",
                "resolution": "sd"
            },
            "timeline": {
                "tracks": [
                    {
                        "clips": [
                            {
                                "asset": {
                                    "type": "video",
                                    "src": "https://rr5---sn-gwpa-w5pe7.googlevideo.com/videoplayback?expire=1672920930&ei=Amu2Y8z9LYmivwSSip-gAQ&ip=2405%3A205%3A120d%3A4a08%3A311f%3Aa880%3A2a02%3A4d6d&id=o-AFJWiBKpz4lQG0p0YnoxM0mjM9dcu60npG2R7p_MtART&itag=22&source=youtube&requiressl=yes&mh=yc&mm=31%2C29&mn=sn-gwpa-w5pe7%2Csn-gwpa-qxay&ms=au%2Crdu&mv=m&mvi=5&pl=41&initcwndbps=252500&vprv=1&mime=video%2Fmp4&ratebypass=yes&dur=336.735&lmt=1647934416054398&mt=1672898966&fvip=3&fexp=24007246&c=ANDROID&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhALi5zmn0vFx1d6kZuflCIa8qHEvzxxpqpMoGFjxKGUvzAiBgWh_m8wl8sCWX-v1C-KahZk2-2s4yQBGU2Vta6GODoA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgacF-KJ3UVQ3VOSFtecOSRTvw5EsoSZEe1ibUklT4qHQCIQCNy7_RSqaL2hK1XgWxGf1IpNlCZCC9qiq--Y5M3_mPOg%3D%3D"
                                },
                                "start": 0,
                                "length": 7
                            }
                        ]
                    }
                ]
            }
        },
        "created": "2023-01-05T08:23:57.174Z",
        "updated": "2023-01-05T08:24:00.071Z"
    }
}

Why it is failing to trim ?

Sometime your apis fail and sometimes work? Please tell me the exact reason before I go for the actual implementation.

Your video file does not appear to exist:

https://rr5---sn-gwpa-w5pe7.googlevideo.com/videoplayback?expire=1672920930&ei=Amu2Y8z9LYmivwSSip-gAQ&ip=2405%3A205%3A120d%3A4a08%3A311f%3Aa880%3A2a02%3A4d6d&id=o-AFJWiBKpz4lQG0p0YnoxM0mjM9dcu60npG2R7p_MtART&itag=22&source=youtube&requiressl=yes&mh=yc&mm=31%2C29&mn=sn-gwpa-w5pe7%2Csn-gwpa-qxay&ms=au%2Crdu&mv=m&mvi=5&pl=41&initcwndbps=252500&vprv=1&mime=video%2Fmp4&ratebypass=yes&dur=336.735&lmt=1647934416054398&mt=1672898966&fvip=3&fexp=24007246&c=ANDROID&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIhALi5zmn0vFx1d6kZuflCIa8qHEvzxxpqpMoGFjxKGUvzAiBgWh_m8wl8sCWX-v1C-KahZk2-2s4yQBGU2Vta6GODoA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIgacF-KJ3UVQ3VOSFtecOSRTvw5EsoSZEe1ibUklT4qHQCIQCNy7_RSqaL2hK1XgWxGf1IpNlCZCC9qiq--Y5M3_mPOg%3D%3D

@dazzatron

I am able to play the video with this URL in the browser.

Are you sure we are talking about the same URL?

When checking the url provided in the JSON payload in your previous post I was not able to access it.

Yes. It is the same. Please check this video.

It appears the link you are using has geographical restrictions. I can see references to an Indian IP address in the URL.

Please try again by using a link that does not have these geographical restrictions. The file needs to be able to be downloaded via the endpoint which is located in Sydney, Australia.

@dazzatron

Try this:

Please find the GIF file instead.

Rendering failed while trimming youtube video - Shotstack API - Shotstack Community - Google Chrome 2023-01-05 14-23-46

Yes I understand it works for you. The problem is that the URL is not pointing to the MP4 file directly.

The URL provided has a range of redirects that don’t appear to be working everywhere. You can check this redirect service.

The final link works, but there appear to be some restrictions in place in following those. This is likely the case because YouTube videos are often licensed, and should only be used when you have the approval of the copyright holder.

As mentioned earlier please make sure wherever possible you are using (direct) links that can be opened in Sydney, Australia.

The rendering of the video failed because the provided YouTube URL (https://www.youtube.com/watch?v=xkgMj8V7ffY) is not a valid media file. You need to provide a direct link to the video file itself, rather than a YouTube page URL. Obtain the direct link to the video file and update the src field in the asset object with that URL. Then, retry rendering the trimmed video using the Shotstack API.

1 Like