How do you automatically detect device dimensions when using HTTP Live Streaming? - http-live-streaming

I have an app that delivers video content using HTTP Live Streaming. I want the app to retrieve the appropriate resolution based on the devices screen size (either 4x3 or 16x9). I ran Apple's tool to create the master .m3u8 playlist file (variantplaylistcreator) and got the following:
#EXTM3U
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=248842,BANDWIDTH=394849,CODECS="mp4a.40.2, avc1.4d4028",RESOLUTION=480x360
4x3/lo/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=384278,BANDWIDTH=926092,CODECS="mp4a.40.2, avc1.4d4028",RESOLUTION=480x360
4x3/mid/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=787643,BANDWIDTH=985991,CODECS="mp4a.40.2, avc1.42801e",RESOLUTION=480x360
4x3/hi/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=249335,BANDWIDTH=392133,CODECS="mp4a.40.2, avc1.4d4028",RESOLUTION=640x360
16x9/lo/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=384399,BANDWIDTH=950686,CODECS="mp4a.40.2, avc1.4d4028",RESOLUTION=640x360
16x9/mid/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=780648,BANDWIDTH=987197,CODECS="mp4a.40.2, avc1.42801e",RESOLUTION=640x360
16x9/hi/prog_index.m3u8
This does cause my live stream to switch between video quality correctly, but it seems to randomly pick whether it uses a 4x3 or 16x9 resolution.
Is there a way to have it select the correct dimensions automatically, or do I need to have multiple playlist files and have a device request a specific one? For example, if on an iPad do I need to detect that it's screen has a 4x3 dimension and request a 4x3_playlist.m3u8 that only has the 480x360 resolution option?

Update 2017:
Keeping the same aspect-ratio is only a recommendation in the latest HLS authoring guide:
1.33. All video variants SHOULD have identical aspect ratios.
Original answer:
Audio/Video Stream Considerations:
Video aspect ratio must be exactly
the same, but can be different dimensions.
Apple Technical Note TN2224 - Best Practices for Creating and Deploying HTTP Live Streaming Media for the iPhone and iPad
Select a playlist based on the User-Agent instead.

Related

Sending a webcam input to zoom using a recorded clip

I have an idea that I have been working on, but there are some technical details that I would love to understand before I proceed.
From what I understand, Linux communicates with the underlying hardware through the /dev/. I was messing around with my video cam input to zoom and I found someone explaining that I need to create a virtual device and mount it to the output of another program called v4loop.
My questions are
1- How does Zoom detect the webcams available for input. My /dev directory has 2 "files" called video (/dev/video0 and /dev/video1), yet zoom only detects one webcam. Is the webcam communication done through this video file or not? If yes, why does simply creating one doesn't affect Zoom input choices. If not, how does zoom detect the input and read the webcam feed?
2- can I create a virtual device and write a kernel module for it that feeds the input from a local file. I have written a lot of kernel modules, and I know they have a read, write, release methods. I want to parse the video whenever a read request from zoom is issued. How should the video be encoded? Is it an mp4 or a raw format or something else? How fast should I be sending input (in terms of kilobytes). I think it is a function of my webcam recording specs. If it is 1920x1080, and each pixel is 3 bytes (RGB), and it is recording at 20 fps, I can simply calculate how many bytes are generated per second, but how does Zoom expect the input to be Fed into it. Assuming that it is sending the strean in real time, then it should be reading input every few milliseconds. How do I get access to such information?
Thank you in advance. This is a learning experiment, I am just trying to do something fun that I am motivated to do, while learning more about Linux-hardware communication. I am still a beginner, so please go easy on me.
Apparently, there are two types of /dev/video* files. One for the metadata and the other is for the actual stream from the webcam. Creating a virtual device of the same type as the stream in the /dev directory did result in Zoom recognizing it as an independent webcam, even without creating its metadata file. I did finally achieve what I wanted, but I used OBS Studio virtual camera feature that was added after update 26.0.1, and it is working perfectly so far.

Routing AVPlayer audio output to AVAudioEngine

Due to the richness and complexity of my app's audio content, I am using AVAudioEngine to manage all audio across the app. I am converting every audio source to be represented as a node in my AVAudioEngine graph.
For example, instead using AVAudioPlayer objects to play mp3 files in my app, I create AVAudioPlayerNode objects using buffers of those audio files.
However, I do have a video player in my app that plays video files with audio using the AVPlayer framework (I know of nothing else in iOS that can play video files). Unfortunately, there seems to be no way I can obtain the audio output stream as a node in my AVAudioEngine graph.
Any pointers?
If you have a video file, you can extract audio data and pull it out from the video.
Then you can set the volume of AVPlayer to 0. (If you didn't remove audio data from the video)
and Play AVAudioPlayerNode.
If you receive the video data through network, You should make parser of the packet and divide them.
But AV-sync is very tough thing.

Clip videos using azure media services

I've uploaded & encoded a video as an asset using AMS's AdaptiveStreaming preset to be able to stream the whole video.
I now need to split the video into short clips that will need be streamed as well. How do I go about it?
(The start & end times of the video-clips are known.)
Are your clips going to be at arbitrary in/out points (eg. start at 3 seconds 22 frames into the input video, and stop 18 seconds 12 frames)? If so, you would need to use the original video source, and follow the steps outlined here. As indicated in that article, you would have to start with one of the presets where the bitrates, resolutions etc. are explicitly defined. At this time, we don't support the ability to combine clipping/trimming with the "Adaptive Streaming" preset.

J2ME - Fm recording app - can't buffer and write to a file

Hey every one I was developing a J2ME app that records fm radio,I have tried so many methods but I have failed. The major problem I faced is that in the media api for J2ME once the code for tuning into a specific fm channel is written(and works but only outputs directly to the speaker) I couldn't find a way to buffer the output and write it into a file.Thanks in advance.
I think it is not possible with MMAPI directly. I assume the fm radio streams via RTSP, and you can specify it as data source for MMAPI, but if you want to store the audio data, you need to fetch it in your own buffer instead, and then pass to MMAPI Player via InputStream.
In that way you will need to code your own handling for RTSP (or whatever your fm radio uses), and convert data into format acceptable by MMAPI Player via InputStream, for example audio/x-wav or audio/amr. If header of the format doesn't need to specify length of data, then you probably can 'stream' it via your buffer receiving data from RTSP source.
This is some kind of low level coding, I think it will be hard to implement in J2ME.

How does youtube support starting playback from any part of the video?

Basically I'm trying to replicate YouTube's ability to begin video playback from any part of hosted movie. So if you have a 60 minute video, a user could skip straight to the 30 minute mark without streaming the first 30 minutes of video. Does anyone have an idea how YouTube accomplishes this?
Well the player opens the HTTP resource like normal. When you hit the seek bar, the player requests a different portion of the file.
It passes a header like this:
RANGE: bytes-unit = 10001\n\n
and the server serves the resource from that byte range. Depending on the codec it will need to read until it gets to a sync frame to begin playback
Video is a series of frames, played at a frame rate. That said, there are some rules about the order of what frames can be decoded.
Essentially, you have reference frames (called I-Frames) and you have modification frames (class P-Frames and B-Frames)... It is generally true that a properly configured decoder will be able to join a stream on any I-Frame (that is, start decoding), but not on P and B frames... So, when the user drags the slider, you're going to need to find the closest I frame and decode that...
This may of course be hidden under the hood of Flash for you, but that is what it will be doing...
I don't know how YouTube does it, but if you're looking to replicate the functionality, check out Annodex. It's an open standard that is based on Ogg Theora, but with an extra XML metadata stream.
Annodex allows you to have links to named sections within the video or temporal URIs to specific times in the video. Using libannodex, the server can seek to the relevant part of the video and start serving it from there.
If I were to guess, it would be some sort of selective data retrieval, like the Range header in HTTP. that might even be what they use. You can find more about it here.

Resources