Adaptive Bitrate HLS Generation


MaxxSports has two variant streams for each camera, high and low resolution, generated by ffmpeg. Player can switch between the two resolutions based on bandwidth.

There are three playlists in this sample setup; master.m3u8 has two variant playlists:
var_0.m3u8: 426×240, with original resolution from input mp4 file
var_1.m3u8: 128×86, transcoded with parameter -s:v:1 128×86

Command used to generate the three playlists:
set FF=2018\bin\ffmpeg.exe
set MEDIA=Gym2017bshort.mp4    : to be replaced by rtsp://… for live camera feed.
%FF% -i %MEDIA% -s:v:1 128×86 -map 0:v -map 0:a -map 0:v -map 0:a -f hls -master_pl_name master.m3u8 -var_stream_map “v:0,a:0 v:1,a:1” var_%v.m3u8

Play URL: http://riowing.net/ABR/master.m3u8 or http://riowing.net/ABR/var_0.m3u8 or var_1.m3u8

This feature, var_stream_map, was added to ffmpeg in November 2017.
ffmpeg version is ffmpeg-20180925-a7429d8-win64-static 4.02, downloaded from ffmpeg.zeranoe.com

Advertisements

Sample Bayer Video Posted


I am posting this Bayer video file, because, unlike other raw video such as YUV, I found no Bayer video on google.

The hardware is in the picture attached:

  1. Camera: Smartek UCC2461C, Optical Format 2/3
  2. Lens: Theia ML410M 4-10mm
  3. The C-mount connects the camera, left half, and  the lens, the right half.

The data:

  1. Bayer RGGB 8 bit per pixel, width 520, hight 512, 10 FPS, 100 frames, 26MB.
  2. Download video here: http://riowing.net/media/Inside100frames.bay

How to watch:

  1. ffmpeg converts Bayer to YUV, and the .yuv can be played by “YUV File Player”.
  2. The output yuv420 file, Inside100frames.yuv, has to be exact 1.5 times the size of the input bayer_rggb8 Inside100frames.bay.
  3. Here is the command: $ffmpeg -f rawvideo -vcodec rawvideo -s 520×512 -pix_fmt bayer_rggb8 -i Inside100frames.bay -vcodec rawvideo -pix_fmt yuv420p Inside100frames.yuv

This camera only records one color component for each pixel, which explains Bayer file is smaller than YUV.BayerPost

A functor from scratch that works with std bind2nd


For a functor to work with bind2nd, it usually derives from binary_function.
However, making one from scratch is not much work as illustrated in the following.

struct FunctorAdd //takes two parameters, operator() returns the sum of the two.
{
int operator()(const int & i, const int & j) const
{ return i+j;
}
typedef int result_type;
typedef int first_argument_type;
typedef int second_argument_type;
};
void Test_bind2nd()
{
int a[] = {0, 2, 3 };
int c = count_if ( a, a + 3, bind2nd(FunctorAdd(), 0) ); //bind2nd is a system adapter in std
//count the ones that are not 0
_ASSERT(c == 2); //this proves FunctorAdd works well with bind2nd
}

Find out the length of array


void TestLengthArray()
{
	enum {E_ARRAY_LEN = 2};
	int *a = new int[E_ARRAY_LEN];
	size_t iSize = _msize(a) / sizeof a[0];
	_ASSERT(iSize == E_ARRAY_LEN); //here we got the length of the array
}

MSDN didn’t mention if _msize can be used for ‘new’; it just seems working.
This is not supported by the standard, but good to know it’s possible at runtime.