YouTube videos have different resolution default thumbnails to use. We use the "default" version (ie: http://img.youtube.com/vi/UNIQUECODE/default.jpg) to preview youtube videos before showing them.
The problem is that Google PageSpeed then dings the page as having a non-compressed image. (ie: Compressing http://img.youtube.com/vi/UNIQUECODE/default.jpg could save 1.1KiB (23% reduction). ).
Is there anyway to call their API and get a compressed image to show?
There are only the default options offered, they don't have a processing option. One possiblity is a 3rd-party compression service like TinyPNG. Their developer API lets you remotely compress an image:
Features: "You can either upload images directly or specify a URL to the image you want to compress."
A POST request using JSON will compress the Youtube image on TinyPNG's server:
POST /shrink HTTP/1.1
Host: api.tinify.com
Authorization: Basic YXBpOmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1
Content-Type: application/json
{
"source": {
"url": " http://img.youtube.com/vi/UNIQUECODE/default.jpg)"
}
}
The (JSON) response would give you a new compressed image link to use instead of the one from Youtube.
Related
I don't want to use libraries for this, I just want to send REST request to the API. Here is API reference for uploading videos. I don't see anywhere in the documentation where to put a video file. Should it be in the header or request body? Does anyone know how this HTTP request should look like?
Here is the official documentation of the Resumable Upload Protocol, which is used by all of Google's public (open source) libraries.
I personally would not recommend you to implement resumable video uploading using bare HTTP request methods. That's quite tricky to done it right. But, if you don't want to use Google's libraries, you have to absorb this doc and implement its specifications the way you need it.
There's also the possibility to upload videos on one go (thus not using the above mentioned protocol). That would entail calling a POST method on the URL:
https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet,status,
where you'll have to compose a multipart/related content-type as exemplified below:
POST /upload/youtube/v3/videos?uploadType=multipart&part=snippet,status HTTP/1.1
Host: www.googleapis.com
Content-length: 453
Content-type: multipart/related; boundary="===============8268018375852491166=="
Authorization: Bearer [YOUR_VALID_ACCESS_TOKEN]
--===============8268018375852491166==
Content-Type: application/json
MIME-Version: 1.0
{
"snippet": {
"title": "test video",
"description": "just some test video",
"categoryId": "22"
},
"status": {
"privacyStatus": "private",
"embeddable": false,
"license": "youtube"
}
}
--===============8268018375852491166==
Content-Type: video/mp4
MIME-Version: 1.0
Content-Transfer-Encoding: binary
TEST
--===============8268018375852491166==--
You could use as spring of inspiration for your own code this Python3 script I implemented a while ago. The script takes as input an JSON object specifying the metadata of the video to be uploaded and the video file itself and generates the multipart/related file and the associated Content-Type HTTP header that could well be used by an immendiate curl command. (Issue my script with --help for brief helping info.)
Note that my script is based on Google's own open source code, specifically on discovery.py. This latter script is part of Google's APIs Client Library for Python.
I hope that I am posting using the right tags.
I added the dash.js player to a page in my website
I did create some mpd files from mp4 ones.
I wanted to know how can I generate URL for these files so that my app can access them.
In case it will help I am using Apache2 to serve my application.
The mpd file provides an index with pointers to the individual steams for your video - e.g. the different bitrate video files, the Audi stream, and subtitles etc.
The pointers in the mpd file are relative or absolute URL's which the client, e.g. the browser can access.
To allow the browser access the mpd itself you just have to put it someplace in your server file structure that clients can access, or that the server will redirect client requests for video to.
The online apache documentation provides an overview of how you can match URL requests to file locations:
https://httpd.apache.org/docs/trunk/urlmapping.html
I'm trying to make an app where I take pictures from users add them to a canvas, draw stuff in them, then convert them to a base64 string and upload them.
For this purpose I'm considering the possibility to use a cdn but can't find information on what I can upload to them and how the client side uploading works. I'd like to be able to send the image as base64 and the name to be given to the file, so that when it arrives to the origin cdn, the base64 image is decoded and saved under the specified name (which I will add to the database on the server).Is this possible?Can I have some kind of save.php file on the origin cdn where I write my logic to save the file and to which I'll send XHR requests? Or how this whole thing work?I know this question may sound trivial but I'm looking for it for hours and still didn't find anything which explains in detail how the client side uploading work for CDNs.
CDNs usually do not provide such uploading service for client side, so you can not do it in this way.
I'm setting up the back end for an Android/iOS app that, among other things, allows users to share an image via Twitter. It's hosted on Heroku, which has no local image hosting, so the images are hosted elsewhere.
It looks like if you want to tweet an image you're supposed to POST to /statuses/update_with_media and send the image as multi-part data. But I don't have the images stored locally, so I would have to copy the image over to temp storage on Heroku, POST it to Twitter, and then delete it, which seems... inefficient.
Is there any way I can use Twitter's API to tweet an image and only supply the URL for the image?
It does not look like it's possible to send Twitter a link via their API, presumably because they would then have to download the image themselves. You could upload the image to a third party and link to that, but you have the same problem in that case.
You shouldn't need to copy the file over as such though, you could read the file into memory and serialize it to multi-part form data in order to send to Twitter.
Do you have any code to show?
I want to understand all the parameters of a YouTube video as YouTube is now not using the HTTP range element but using its own range parameters inside its URL and thus I am not able to make a session using the Wireshark as i see so many HTTP 200 ok with video/x-flv and thus my player is not able to associate them as it reads the HTTP responses and its ranges. Here are the sample URLs what YouTube is sending for a single video. Is there any documetation available for this as well?
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713452&mv=m&newshard=yes&range=13-1781759&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s HTTP/1.1
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713563&mv=m&newshard=yes&range=10690560-12472319&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s&redirect_counter=1&cms_redirect=yes HTTP/1.1
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713452&mv=m&newshard=yes&range=12472320-14254079&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s HTTP/1.1
There is no documentation for this sort of thing, and video streams are generally considered a "black box" from a developer's perspective.
For your question, see this thread.
Youtube streaming works providing 1.7MB chunk pieces controlled by range param, which indicate [start byte]-[end byte].
I'am also questioning similar issue here.