Live streaming video bitrate hls - http-live-streaming

I have a live stream video using hls js. Using MANIFEST_PARSED event I can get video size (width and height) and bitrate.
For example:
bitrate 258157 width 422 height 180
bitrate 520929 width 638 height 272
bitrate 831270 width 638 height 408
... etc
I want oo create a menu of quality levels from this (like youtube has for example) 480p, 720p etc...
Does this mean I only need to use height information and add "p" so I get from the example above:
180p, 272p, 408p
Or there is more to this formula?

Related

How do I adjust the video resolution?

I'm trying to adjust the resolution of the incoming H.264 RTSP stream. I am running on Windows 10 for now, but will eventually move this to Linux. I am creating the LibVLC object passing in several command line args, but nothing I have tried affects the resulting screen resolution.
When I open the same RTSP steam in the VLC media player app, the resolution is 2560x1980, which is the native resolution I want in my app. But, when my app runs, it's only 640x480. FYI - this is not a Windows UI app. It's a service that is just taking screenshots. So, there is not media control on a form to adjust.
Here is what I have right now:
Core.Initialize();
LibVLC libVLC = new LibVLC("--no-audio", "--no-spu", "--sout-transcode-venc=x264", "--sout-x264-preset=ultrafast", "--sout-x264-profile=high", "--sout-x264-tune=film", "--video-filter=scene", "--scene-format=jpeg", "--scene-prefix=MyVision", "--scene-path=C:\\temp\\", "--scene-ratio=100", $"--rtsp-user={rtspUser}", $"--rtsp-pwd={rtspPassword}");
player = new MediaPlayer(libVLC);
var media = new Media(libVLC, _rtspEndpoint, FromType.FromLocation);
player.Play(media);
Some of the x264 options are just ones that I tested that I saw in the VLC App. They did not adjust the resolution.
Here is the log file:
VLC media player - 3.0.7.1 Vetinari
Copyright © 1996-2019 the VideoLAN team
revision 3.0.7.1-0-gf3940db4af
configured with ../extras/package/win32/../../../configure '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=x86_64-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' 'host_alias=x86_64-w64-mingw32' 'PKG_CONFIG_LIBDIR=/home/jenkins/workspace/vlc-release/windows/vlc-release-win32-x64/contrib/x86_64-w64-mingw32/lib/pkgconfig'
creating audio output
looking for audio output module matching "any": 6 candidates
using default device
display name changed: VLC media player (LibVLC 3.0.7.1)
version 2 session control unavailable
volume from -65.250000 dB to +0.000000 dB with 0.031250 dB increments
using audio output module "mmdevice"
keeping audio output
Creating an input for 'rtsp://192.168.1.108:554/h264Preview_01_sub'
using timeshift granularity of 50 MiB
using timeshift path: C:\Users\dwjen\AppData\Local\Temp
`rtsp://192.168.1.108:554/h264Preview_01_sub' gives access `rtsp' demux `any' path `192.168.1.108:554/h264Preview_01_sub'
creating demux: access='rtsp' demux='any' location='192.168.1.108:554/h264Preview_01_sub' file='\\192.168.1.108:554\h264Preview_01_sub'
looking for access_demux module matching "rtsp": 15 candidates
version 2016.11.28
RTP subsession 'video/H264'
selecting program id=0
RTP subsession 'audio/MPEG4-GENERIC'
setup start: 0.000000 stop:0.000000
We have a timeout of 60 seconds
play start: 0.000000 stop:0.000000
using access_demux module "live555"
looking for packetizer module matching "any": 25 candidates
found NAL_SPS (sps_id=0)
found NAL_PPS (pps_id=0 sps_id=0)
using packetizer module "h264"
looking for video decoder module matching "any": 19 candidates
using ffmpeg Lavc58.6.103
CPU flags: 0x0007d3db
allowing 6 thread(s) for decoding
codec (h264) started
using frame thread mode with 6 threads
using video decoder module "avcodec"
audio is disabled, not selecting ES 0x1
looking for meta reader module matching "any": 2 candidates
Trying Lua scripts in C:\Users\dwjen\AppData\Roaming\vlc\lua\meta\reader
Trying Lua scripts in C:\Source\BlueMetal\Internal\VideoTest\RtspSnapshots\bin\Debug\netcoreapp2.2\libvlc\win-x64\lua\meta\reader
Trying Lua playlist script C:\Source\BlueMetal\Internal\VideoTest\RtspSnapshots\bin\Debug\netcoreapp2.2\libvlc\win-x64\lua\meta\reader\filename.luac
no meta reader modules matched
`rtsp://192.168.1.108:554/h264Preview_01_sub' successfully opened
Buffering 0%
Buffering 3%
Buffering 7%
restarting module due to input format change
removing module "avcodec"
looking for video decoder module matching "any": 19 candidates
using ffmpeg Lavc58.6.103
CPU flags: 0x0007d3db
allowing 6 thread(s) for decoding
codec (h264) started
using frame thread mode with 6 threads
using video decoder module "avcodec"
available hardware decoder output format 119 (cuda)
available hardware decoder output format 53 (dxva2_vld)
available hardware decoder output format 118 (d3d11va_vld)
available hardware decoder output format 174 (d3d11)
available software decoder output format 0 (yuv420p)
tk->rtpSource->hasBeenSynchronizedUsingRTCP()
trying format d3d11va_vld
looking for text renderer module matching "any": 3 candidates
Using DWrite backend
DWrite_GetFamily(): family name: Arial
DWrite_ParseFamily(): using font at index 0 with weight 400 for bold: 0, italic: 0
DWrite_ParseFamily(): using font at index 1 with weight 700 for bold: 1, italic: 0
DWrite_ParseFamily(): using font at index 2 with weight 400 for bold: 0, italic: 1
DWrite_ParseFamily(): using font at index 3 with weight 700 for bold: 1, italic: 1
using text renderer module "freetype"
looking for video converter module matching "any": 24 candidates
32x32 (32x32) chroma: YUVA -> 16x16 (16x16) chroma: RGBA with scaling using Bicubic (good quality)
using video converter module "swscale"
looking for video converter module matching "any": 24 candidates
YUVP to YUVA converter
using video converter module "yuvp"
Deinterlacing available
deinterlace -1, mode auto, is_needed 0
looking for vout window module matching "any": 3 candidates
no vout window modules matched
Opening vout display wrapper
looking for vout display module matching "any": 12 candidates
creating Vout EventThread
Win32VoutCreateWindow
inclinometer not found. (hr=0x80070490)
created video sub-window
Vout EventThread running
Created the D3D11 device type 1 level b100.
different 0 device p vs P
different 1 device p vs P
failed to read the 2 Display Adapter registry key (2)
can't find adapter in registry
supports colorspace RGB Rec.709 gamma:22 range:FULL
supports colorspace RGB Rec.709 gamma:22 range:STUDIO
supports colorspace RGB Rec.2020 gamma:22 range:STUDIO
supports colorspace RGB Rec.2020 gamma:22 range:FULL
supports colorspace RGB Rec.2020 gamma:2084 range:FULL
supports colorspace RGB Rec.2020 gamma:2084 range:STUDIO
Output max luminance: 270.0, colorspace RGB Rec.709 gamma:22 range:FULL, bits per pixel 8
using colorspace RGB Rec.709 gamma:22 range:FULL
Using pixel format VA_NV12 for chroma DX11
Direct3D11 resources created
Direct3D11 device adapter successfully initialized
Direct3D11 Open Succeeded
using vout display module "direct3d11"
D3D11 pool succeed with 40 surfaces (640x512) context 0x00000209797c34e0
original format sz 640x480, of (0,0), vsz 640x480, 4cc DX11, sar 1:1, msk r0x0 g0x0 b0x0
VoutDisplayEvent 'window state' 0
VoutDisplayEvent 'window state' 0
Adding 'scene' as interactive
looking for video filter module matching "scene,chain": 46 candidates
Trying to use chroma I420 as middle man
looking for video converter module matching "any": 24 candidates
using video converter module "d3d11_filters"
Filter 'd3d11_filters' (0000020978091e80) appended to chain
looking for video filter module matching "scene,chain": 46 candidates
using video filter module "scene"
Filter 'scene' (00000209780917a0) appended to chain
using video filter module "chain"
Filter 'scene' (0000020978091b10) appended to chain
Adding a filter to compensate for format changes
looking for video converter module matching "any": 24 candidates
different 0 device p vs P
different 1 device p vs P
failed to read the 2 Display Adapter registry key (2)
can't find adapter in registry
looking for video converter module matching "any": 24 candidates
using video converter module "i420_nv12"
using video converter module "d3d11_filters"
Filter 'd3d11_filters' (00000209780921f0) appended to chain
removing module "chain"
removing module "d3d11_filters"
Filter 0000020978091e80 removed from chain
removing module "scene"
Filter 00000209780917a0 removed from chain
Filter 0000020978091b10 removed from chain
removing module "d3d11_filters"
removing module "i420_nv12"
Filter 00000209780921f0 removed from chain
Adding 'scene' as interactive
looking for video filter module matching "scene,chain": 46 candidates
Trying to use chroma I420 as middle man
looking for video converter module matching "any": 24 candidates
using video converter module "d3d11_filters"
Filter 'd3d11_filters' (0000020978091e80) appended to chain
looking for video filter module matching "scene,chain": 46 candidates
using video filter module "scene"
Filter 'scene' (0000020978092560) appended to chain
using video filter module "chain"
Filter 'scene' (00000209780921f0) appended to chain
Adding a filter to compensate for format changes
looking for video converter module matching "any": 24 candidates
different 0 device p vs P
different 1 device p vs P
failed to read the 2 Display Adapter registry key (2)
can't find adapter in registry
looking for video converter module matching "any": 24 candidates
using video converter module "i420_nv12"
using video converter module "d3d11_filters"
Filter 'd3d11_filters' (0000020978090d50) appended to chain
removing module "freetype"
looking for text renderer module matching "any": 3 candidates
VoutDisplayEvent 'resize' 640x480
Using DWrite backend
DWrite_GetFamily(): family name: Arial
DWrite_ParseFamily(): using font at index 0 with weight 400 for bold: 0, italic: 0
DWrite_ParseFamily(): using font at index 1 with weight 700 for bold: 1, italic: 0
DWrite_ParseFamily(): using font at index 2 with weight 400 for bold: 0, italic: 1
DWrite_ParseFamily(): using font at index 3 with weight 700 for bold: 1, italic: 1
using text renderer module "freetype"
looking for hw decoder module matching "any": 2 candidates
different 0 device p vs P
different 1 device p vs P
failed to read the 2 Display Adapter registry key (2)
can't find adapter in registry
Reusing Direct3D11 device
CreateDevice succeed
- 'MPEG-2 variable-length decoder' is supported
- 'MPEG-2 inverse discrete cosine transform' is supported
- 'VC-1 variable-length decoder' is supported
- 'VC-1 variable-length decoder 2 (Intel)' is supported
- 'VC-1 variable-length decoder (Intel)' is supported
- 'Windows Media Video 9 IDCT' is supported
- 'VC-1 inverse discrete cosine transform' is supported
- 'H.264 variable-length decoder, no film grain technology' is supported
- 'H.264 stereo high profile, mbs flag set' is supported
- 'H.264 stereo high profile' is supported
- 'H.264 multiview high profile' is supported
- 'Unknown decoder 0xc528916c-0xc0af-0x4645-0x8cb2372b6d4adc2a' is supported
- 'Unknown decoder 0x91cd2d6e-0x897b-0x4fa1-0xb0d751dc88010e0a' is supported
- 'VP8' is supported
- 'Unknown decoder 0x442b942a-0xb4d9-0x4940-0xbc45a882e5f919f3' is supported
- 'Unknown decoder 0x97688186-0x56a8-0x4094-0xb543fc9daaa49f4b' is supported
- 'Unknown decoder 0x1424d4dc-0x7cf5-0x4bb1-0x9cd7b63717a72a6b' is supported
- 'Unknown decoder 0xc346e8a3-0xcbed-0x4d27-0x87cca70eb4dc8c27' is supported
- 'Unknown decoder 0xffc79924-0x5eaf-0x4666-0xa73606190f281443' is supported
- 'Unknown decoder 0xf416f7bd-0x098a-0x4cf1-0xa11bce54959ca03d' is supported
- 'Unknown decoder 0xbf44dacd-0x217f-0x4370-0xa383d573bc56707e' is supported
- 'Unknown decoder 0x2364d06a-0xf67f-0x4186-0xaed062b99e1784f1' is supported
- 'Unknown decoder 0x464bdb3c-0x91c4-0x4e9b-0x896f225496ac4ed6' is supported
- 'Unknown decoder 0x28566328-0xf041-0x4466-0x8b148f5831e78f8b' is supported
- 'Unknown decoder 0x6b4a94db-0x54fe-0x4ae1-0x9be47a7dad004600' is supported
- 'Unknown decoder 0x8c56eb1e-0x2b47-0x466f-0x8d337dbcd63f3df2' is supported
- 'HEVC Main profile' is supported
- 'Unknown decoder 0x75fc75f7-0xc589-0x4a07-0xa25b72e03b0383b3' is supported
- 'HEVC Main 10 profile' is supported
- 'Unknown decoder 0x07cfaffb-0x5a2e-0x4b99-0xb62ae4ca53b6d5aa' is supported
- 'VP9 profile 0' is supported
- 'VP9 profile 2' is supported
- 'VP9 profile Intel' is supported
- 'Unknown decoder 0x80a3a7bd-0x89d8-0x4497-0xa2b82126af7e6eb8' is supported
- 'Unknown decoder 0x8de911c4-0xc898-0x4364-0x97151de6b3fe773d' is supported
- 'Unknown decoder 0x50925b7b-0xe931-0x4978-0xa12a586630f095f9' is supported
- 'Unknown decoder 0xb69c20e0-0x2508-0x8790-0x0305875499e0a2d0' is supported
- 'Unknown decoder 0x49761bec-0x4b63-0x4349-0xa5ff87ffdf088466' is supported
Trying to use 'H.264 variable-length decoder, no film grain technology' as input
NV12 output is supported for decoder H.264 variable-length decoder, no film grain technology.
Using output format NV12 for decoder H.264 variable-length decoder, no film grain technology
va_pool_SetupDecoder id 27 640x480 count: 24
using external surface pool
ID3D11VideoDecoderOutputView succeed with 24 surfaces (640x480)
we got 9 decoder configurations
configuration[0] ConfigBitstreamRaw 2
configuration[1] ConfigBitstreamRaw 1
configuration[2] ConfigBitstreamRaw 2
configuration[3] ConfigBitstreamRaw 2
configuration[4] ConfigBitstreamRaw 2
configuration[5] ConfigBitstreamRaw 2
configuration[6] ConfigBitstreamRaw 2
configuration[7] ConfigBitstreamRaw 1
configuration[8] ConfigBitstreamRaw 1
DxCreateDecoderSurfaces succeed
using hw decoder module "d3d11va"
Using D3D11VA (Intel(R) UHD Graphics P630, vendor 8086(Intel), device 3e94, revision 0) for hardware decoding
Buffering 19%
auto hiding mouse cursor
Buffering 32%
Buffering 46%
Buffering 59%
Buffering 75%
Buffering 89%
tk->rtpSource->hasBeenSynchronizedUsingRTCP()
Stream buffering done (1026 ms in 2238 ms)
buffer deadlock prevented
Decoder wait done in 0 ms
looking for encoder module matching "any": 24 candidates
using encoder module "jpeg"
looking for video converter module matching "any": 24 candidates
640x480 (640x480) chroma: I420 -> 640x480 (640x480) chroma: J420 with scaling using Bicubic (good quality)
using video converter module "swscale"
So, all of the resulting screen shots from the stream are 640x480 and I need them to be based on the size of the incoming video stream if possible.
Try this method on the MediaPlayer
bool TakeSnapshot(uint num, string filePath, uint width, uint height)
I just figured out what the issue was. The RTSP stream has a preview and a main feed. I was consuming the preview feed in my code, which is 640x480. Once I switched to the correct (main) feed, everything is working as expected.

Youtube Red audio stops for downloaded videos

I am uploading videos to Youtube, and on my Android phone I am downloading them using Youtube Red. I am playing these downloaded videos in the background, when the screen is off.
This works with the wast majority of the videos, except the ones that I am uploading.
I did read the recommended upload formats, I tried several codecs, but no luck. My audios stop the second I am shutting off the screen.
What I finally found using youtube-dl -F is that my videos do not have audio-only tracks with webm extension, only as m4a (after Youtube processed them).
So my question is: what makes Youtube create webm audio files for some videos, but not for the others? Is there a way to force this (I suppose not). Is there a way to suggest it? As I mentioned, I tried a wide variety of codecs - video and audio, and the combinations - when generating my files to be uplaoded.
A sample output for a file which works:
format code extension resolution note
249 webm audio only DASH audio 52k , opus # 50k, 73.58KiB
250 webm audio only DASH audio 66k , opus # 70k, 92.62KiB
251 webm audio only DASH audio 114k , opus #160k, 161.14KiB
171 webm audio only DASH audio 115k , vorbis#128k, 161.27KiB
140 m4a audio only DASH audio 127k , m4a_dash container, mp4a.40.2#128k, 180.79KiB
and the output for one file which does not:
format code extension resolution note
139 m4a audio only DASH audio 49k , m4a_dash container, mp4a.40.5# 48k (22050Hz), 1.20MiB
140 m4a audio only DASH audio 129k , m4a_dash container, mp4a.40.2#128k (44100Hz), 3.20MiB

What do fragment and width mean in audioop.rms(fragment, width)

I am trying to analyze a wav file in python and get the rms value from the wav. I am using audioop.rms to get the value from the wav. I went to do this and I did not know what fragment and width stood for. I am new to audioop and hope somebody can explain this. I am also wondering if there is any better way to do this in python.
Update: I have done some research and I found out fragment stood for the wav file. I still need to figure out what width means.
A fragment is just a chunk of data. Width is the size in bytes that the data is organized. ex 8bits data has width 1, 16bits has 2 and so on.
```
import alsaaudio, audioop
self.input = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK)
self.input.setchannels(1)
self.input.setrate(8000)
self.input.setformat(alsaaudio.PCM_FORMAT_S16_LE)
self.input.setperiodsize(300)
length, data = self.input.read()
avg_i = audioop.avg(data,2)
```
In the example i am setting alsa capture card to use a S16_LE signed 16bits Little Endian, so I have to set width to be 2. For the fragment is just the data captured by alsa. In your case the wav file is your data.

How to create 10bit YUY2 packed YUV Renderer?

I have created 8 bit yuv player for format YUY2 packed using SDL lib,some part of code:
handle->texture = SDL_CreateTexture(handle->renderer, SDL_PIXELFORMAT_YUY2, SDL_TEXTUREACCESS_STREAMING, width, height);
SDL_UpdateTexture(handle->texture, NULL,pDisplay->Ydata,(handle->width*2));
in that while creating texture,pixel format is given SDL_PIXELFORMAT_YUY2 and update texture pitch in twice of width. So it is playing fine.
But when it comes to 10 bit YUV, it plays disturbed and greenish video.
What I have tried is changed pitch to (handle->width*2 * 2) but no success
also someone suggested to convert 10bit value to 8bit but I don't want to do that.
Please help me to play 10bit YUY2 packed format YUV.
Is SDL support more than 8 bit depth pixel rendering ?

Beaglebone Black Video Capture: Error "select timeout"

Hey I'm following Derek Molloy's tutorial:
http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/#comment-30209
Using a Logitech c310 webcam, that is supported by the Linux UVC drivers.
root#beaglebone:/boneCV# v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : UVC Camera (046d:081b)
Bus info : usb-musb-hdrc.1.auto-1
Driver version: 3.8.13
Capabilities : 0x84000001
Video Capture
Streaming
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 614400
Colorspace : SRGB
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
Priority: 2
So we can see it is read by the Beagleboard no problem.
When I try to capture the video, I simply get this error:
root#beaglebone:/boneCV# ./capture -f -c 600 -o > output.raw
Force Format 1
select timeout
Looking at other threads, people don't seem to know how to answer this question, can anyone with experience on this project help me out?
If you compare the image size of YUYV and that of MJPEG you will notice that the former is much larger than the latter. BBB has limited bandwidth on its USB port so thats why you cannot operate your camera in YUYV format. MJPEG outputs compressed video stream. Different opencv versions tend to change the resolution that you set with v4l2-ctl command so you have to change the resolution in the boneCV code. I'm not sure how its done in c++ but in python, check Changing camera resolution in opencv code. According to Matthew, Bandwidth limitations he tested and found out the bandwidth to be 13.2MB/s.
Well I can say the issue is resolved. After rebooting and trying the camera again after several hours, it magically seems to work.
The only thing I changed is the capture call to be simpler it is now:
./capture -o > output.raw
I haven't converted the raw file to mpeg4 yet, since I'm installing ffmpeg as I type this, however I can confirm that grabbing still images is working. The filesize of the output.raw is confirmation that it is indeed capturing video as well. If anyone finds this and is stuck, I will be glad to give assistance as much as I can.
Strangely, it only seems to capture video after using the picture grabber program first. So there must be something the grabber is initializing that isn't happening in the capture.
UPDATE: Ok it turns out that the YUYV video mode is not working but the mjpeg does, putting it into grabber mode initialized mjpeg mode and that's why it worked. Not sure why YUYV doesn't work yet.

Resources