How to get the multiple Youtube thumbnails in the same resolution?. In YouTube JS API, I get the default, HQ, medium, low-quality images. But, I need multiple thumbnails of the same size. Multiple high-quality thumbnails are much better.
Here are video frames thumbnails with the same resolution (120x90)
WebP:
frame1: https://i.ytimg.com/vi_webp/<YouTube_Video_ID_HERE>/1.webp
frame2: https://i.ytimg.com/vi_webp/<YouTube_Video_ID_HERE>/2.webp
frame3: https://i.ytimg.com/vi_webp/<YouTube_Video_ID_HERE>/3.webp
JPG:
frame1: https://i.ytimg.com/vi/<YouTube_Video_ID_HERE>/1.jpg
frame2: https://i.ytimg.com/vi/<YouTube_Video_ID_HERE>/2.jpg
frame3: https://i.ytimg.com/vi/<YouTube_Video_ID_HERE>/3.jpg
Related
Example 1:
Video MP4
Size is 118mb
Loops 3 times
Large Video on Autoplay loop muted
Example 2:
Video MP4
Size is 6.4mb
Loops indefinitely
Small Video on Autoplay Loop Muted
Changing Video from MP4 to some other more compressed option doesn't seem user friendly, so I'd rather that not be a solution.
I've adjusted Cache-Control: max-age=86400, public, but that didn't seem to do anything. I've read about disabling HTTP 200 responses, but haven't found a good way to do that with NGINX or RoR.
Had to employ several different cache based solutions. I recommend reading the following article A Caching Journey.
Added to Show action on controller to:
expires_in 24.hours
fresh_when(:etag => #board, :last_modified => #board.created_at.utc)
In Config/environment/production.rb added
ActiveStorage::Service.url_expires_in = 3.hours
In Config/Storage.yml added
upload:
cache_control: 'max-age=86400, private'
To set video quality for ios.
I have tried to load m3u8 video url from server and i downloaded the m3u8 file & i segregate all RESOLUTION from video quality & AFTER SEGMENTS get the bandwidth of url in array.
When i load base url sample.m3u8 it has video & audio after that i set the base url of before segments and i have append the bandwidth url from array it was loading video as per quality selected but no audio came.
To achieve this i have made some solutions will work
I make separate to run original url which contains both video & audio and i run separately low bandwidth url which contains no audio to make sync
ex: RESOLUTION=1280x720,SAMPLE_720p_v4.m3u8
SAMPLE.m3u8
#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-0",NAME="Default",AUTOSELECT=YES,DEFAULT=YES,URI="segments/SAMPLE_audio_v4.m3u8"
#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=30681000,CODECS="avc1.640028",URI="segments/SAMPLE_1080p_iframe.m3u8"
#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=30140000,CODECS="avc1.4d001f",URI="segments/SAMPLE_720p_iframe.m3u8"
#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=15431000,CODECS="avc1.42001f",URI="segments/SAMPLE_480p_iframe.m3u8"
#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=11009000,CODECS="avc1.42001e",URI="segments/SAMPLE_360p_iframe.m3u8"
#EXT-X-I-FRAME-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7850000,CODECS="avc1.420015",URI="segments/SAMPLE_270p_iframe.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=4080000,RESOLUTION=1280x720,CODECS="avc1.640028,mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_1080p_v4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=3471000,RESOLUTION=1280x720,CODECS="avc1.4d001f,mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_720p_v4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1934000,RESOLUTION=854x480,CODECS="avc1.42001f,mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_480p_v4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1106000,RESOLUTION=640x360,CODECS="avc1.42001e,mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_360p_v4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=837000,RESOLUTION=480x270,CODECS="avc1.420015,mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_270p_v4.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=185000,CODECS="mp4a.40.2",AUDIO="audio-0"
segments/SAMPLE_audio_v4.m3u8
Use the preferredPeakBitRate property on your playeritem https://developer.apple.com/documentation/avfoundation/avplayeritem/1388541-preferredpeakbitrate you need to pass a valid bandwidth value.
Not sure why you are downloading the m3u8 file AVFoundation manage this for you.
I'm working on a video app, we are changing form regular mp4 files to HLS, one of the many reasons we have to do the change is that we hace much more control over the bandwidth usage of videos (we load lots of other stuff in our player, so we need to optimize the experience the best way).
So, AVFoundation introduced in iOS10 the ability to control the bandwidth using:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:self.urlAsset];
playerItem.preferredForwardBufferDuration = 30.0;
playerItem.preferredPeakBitRate = 200000.0; // Remember this line
There's also a configuration introduced on iOS11 to set the maximum resolution of the item with preferredMaximumResolution, So we're using it, but we still need a solution for iOS10 devices.
Well, now we have control over the preferredPeakBitRate that's nice, but we have a problem, not all the HLS sources are generated by us, so, let's say we want to set a maximum resolution of 480p when you're not connected to a wifi network, today I don't have way to achieve that, not always I'm going to be able to know how much bandwidth needs the 480p source for the selected HLS playlist.
One thing I was thinking about is to read the information inside the m3u8 file, to at least know which are the different quality sources that my player can show and how much bandwidth needs everyone.
One way to do this, would download the m3u8 playlist as a plain text, use a regex to read the file and process this data, well, I'm trying to avoid that, I think that this should far less difficult.
I cannot read this information from the tracks, because a) I can't find the information, b) the tracks are replaced dynamically when changing the quality, yeah 1 track for every quality level.
So, I don't know how I can get this information, I've searched google, stackoverflow and I can't find this information, does any one can help me?
Here's an example for what I want to do, I have this example playlist:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=314000,RESOLUTION=228x128,CODECS="mp4a.40.2"
test-hls-1-16a709300abeb08713a5cada91ab864e_hls_duplex_192k.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=478000,RESOLUTION=400x224,CODECS="avc1.42001e,mp4a.40.2"
test-hls-1-16a709300abeb08713a5cada91ab864e_hls_duplex_400k.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=691000,RESOLUTION=480x270,CODECS="avc1.42001e,mp4a.40.2"
test-hls-1-16a709300abeb08713a5cada91ab864e_hls_duplex_600k.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1120000,RESOLUTION=640x360,CODECS="avc1.4d001f,mp4a.40.2"
test-hls-1-16a709300abeb08713a5cada91ab864e_hls_duplex_1000k.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1661000,RESOLUTION=960x540,CODECS="avc1.4d001f,mp4a.40.2"
test-hls-1-16a709300abeb08713a5cada91ab864e_hls_duplex_1500k.m3u8
And I just want to have that information available on an array inside my code, something like this:
NSArray<ZZMetadata *> *metadataArray = self.urlAsset.bandwidthMetadata;
NSLog(#"Metadata info: %#", metadataArray);
And print something like this:
<__NSArrayM 0x123456789> (
<ZZMetadata 0x234567890> {
trackId: 1
neededBandwidth: 314000
resolution: 228x128
codecs: ...
...
}
<ZZMetadata 0x345678901> {
trackId: 2
neededBandwidth: 478000
resolution: 400x224
}
...
}
I downloaded a jpg file from my ip cam.
but the file seems broken or something about its format.
I couldn't open it using safari or preview.app(macOS),
but it shows in chrome.
What I really trying to do is download it programmatically and show in UIImageView, but the image data is always nil.
I don't know much about image format and the question is strange,
so if you're willing to help me and see whats going on with that picture,
the image: broken jpg
and thanks for your time!
UPDATE 2017/03/30 :
Still haven't found the answer for how to decode motion jpeg frame.
From what I googled, the difference is DHT, but don't know how to add it to a frame.
As far as I know, there are few third-party libs like libjpeg-turbo, ffmpeg but haven't found an example.
If you have done this before and wrote in C or Objective-C, hope you can help me out!
Really want and need to know how!
Thanks!
Your file is an Motion JPEG file, not a JPEG image...
This does explain why browsers are able to open it and you can check this in vlc by looking at the codecs information :
Motion JPEG Video (MJPG)
or even through ffmpeg -i MeQ6p.jpg:
Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 25 tbr, 25 tbn, 25 tbc
So your problem lies in your files only, and this can probably be fixed by setting your ip-cam to save still JPEG images instead of MJPEG streams.
I just tried and can see the data gets fetched from your posted URL and got some 17750 bytes.
let imageURL = NSURL(string : "https://i.stack.imgur.com/MeQ6p.jpg")
let imageData = NSData(contentsOfURL: imageURLFromParse! as NSURL)
I'm doing a project which requires converting SWF movies to H.264 video on server-side, to be able to play them both in Flash player and on iPhone/iPad. And I really got stuck.
I'm using Melt from http://www.mltframework.org/ and this is my command-line:
melt movie.swf -consumer avformat:video.mp4 r=30 s=640x360 f=mp4 acodec=aac ab=128k ar=48000 vcodec=libx264 b=1000k an=1
It does play in Flash player, but fails to play on iDevices. I googled for iPhone video requirements and it seems my video files do satisfy them(frame size, framerate and bitrate). What settings should I change to make it play?
I've spent a lot of time in google but managed to gather all the pieces, so these are parameters that work for iPhone:
r=30 s=640x360 f=mp4 acodec=aac ab=128k ar=48000 vcodec=libx264 level=30 b=1024k flags=+loop+mv4 cmp=256 partitions=+parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 me_method=hex subq=7 trellis=1 refs=1 bf=0 flags2=+mixed_refs-wpred-dct8x8 coder=0 wpredp=0 me_range=16 g=250 keyint_min=25 sc_threshold=40 i_qfactor=0.71 qmin=10 qmax=51 qdiff=4 maxrate=10M bufsize=10M an=1 threads=0
Also, I use faac -w to convert audio to appropriate format and MP4Box to join video and sound.