Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
sachinhambar
Posts: 14
Registered: ‎12-06-2012
My Device: BB10
My Carrier: Airtel

H264 support

Hi 

Is H264 encoder is supported in Camera APIs? What are the default profile and level? How to set profile and level with camera APIs?

 

In my test example, following is the code flow

camera_open(...)

camera_set_videovf_property(...)

camera_set_video_property(....,CAMERA_IMGPROP_VIDEOCODEC, CAMERA_VIDEOCODEC_H264)

camera_start_video_viewfinder(....)

camera_start_encode(..,enc_video_callback)

 

Preview is seen and also I am getting the encoded stream in  "enc_video_callback" callback. 

But this stream  is not being decoded by h264 player like VLC?

 

Please let me know if I am missing anything in H264 stream capture?

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: H264 support

Sounds right to me.

VLC doesn't seem to play back truly raw bitstreams.  I have not been able to spend a lot of time trying to find suitable tools for offline playback.  This is RAW H.264, not an mpeg-wrapped stream, so you would need to start adding headers if you wanted to make it playable in VLC or similar.

mplayer/mencoder were what I was going to investigate next, but time doesn't permit it right now.

 

I can tell you that the output H.264 bitstream is the same data we are writing to disk when recording, but we are prepending and appending all the appropriate atoms in an .mp4 container format.  I can also tell you that the bitstream produced can be fed back into our hardware decoder, as the videochat team is making use of this new API now.  Unfortunately, there is no public API for accessing the decoder directly yet, as far as I know.

 

The profile and level is not yet configurable, and is defaulted to:

- Baseline profile, level 3.0 (if width*height < 640*480)

- High profile, level 4.0 (for larger resolutions)

 

Cheers,

Sean

Please use plain text.
New Developer
sachinhambar
Posts: 14
Registered: ‎12-06-2012
My Device: BB10
My Carrier: Airtel

Re: H264 support

Thanks for immediate reply.

 

VLC plays the raw H264 stream with SPS/PPS header. I worked on many H264 encoders till date. H264 streams generated by these encoders are played by VLC

Any way I will debug more on the stream format generated by BB10 encoder. Will let you know if I find more on this,

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: H264 support

great!  please share your findings, as I'm curious to know this myself.  it will greatly help me debug the feature in the future.

 

the data you are getting from this API is the exact data returned from the hardware compressor block.  it should have sps/pps headers (eg. on the first frame). 

The CAMERA_VIDEOCODEC_H264 format you are selecting will be outputting Annex B format (4-byte marker = 00000001) and the CAMERA_VIDEOCODEC_AVC1 format will do NALU (4-byte marker = 32-bit frame size).  It's possible VLC is expecting NALU rather than Annex B?

 

Cheers,

Sean

Please use plain text.
New Developer
sachinhambar
Posts: 14
Registered: ‎12-06-2012
My Device: BB10
My Carrier: Airtel

Re: H264 support [ New ]

Hi

 

I done further analysis of H264 bitstream.

 

It seems that there is issue with the bitstream created in mode "CAMERA_VIDEOCODEC_H264". Stream is not in correct format.

 

But in mode "CAMERA_VIDEOCODEC_AVC1", stream is proper and was able to decode in VLC player when I replaced the NALU length with start code. 

 

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: H264 support [ New ]

Thanks.. I will investigate this.

So you're saying that you had to configure for _AVC1 mode (NALU), and then you had to manually replace NALU length fields with Annex B "0x00000001" code instead ?

So you're saying VLC will play back Annex B raw bitstreams?

 

That's what the _H264 mode is supposed to be doing for you already.  Our encoder actually only supports Annex B output, and when we configure for NALU mode, we actually do an in-line replace of all Annex B codes with NALU length.  So in your case, you're actually going through a double-replace end-to-end.

 

Can you confirm that the _H264 bitstream you generated is missing the Annex B start codes?

 

Please use plain text.
New Developer
sachinhambar
Posts: 14
Registered: ‎12-06-2012
My Device: BB10
My Carrier: Airtel

Re: H264 support [ New ]

Yes I am using AVC mode insteand of H264 mode and replacing NALU length with start code i.e. 0x00000001.

 

The reason is as already mentioned in above messages, H264 mode gives Annex B output but it is corrupted. 

 

You can verify both above mentioned approach with VLC decoder.

1. AVC mode and replace length with start code

2. H264 mode 

 

Only stream with AVC mode and replace length with start code will be played with VLC

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: H264 support [ New ]

yup.. found that bug.  I had moved a variable declaration from inside of a loop outside of a loop, so it only ever replaced the first occurrence of the NALU length code.

 

that being said, the change may not make it into the launch software build, so you should probably keep your code to do the conversion for now, if that's the format you require.

 

run code like this on each AVC1 frame:

static void ConvertNaluToAnnexB(uint8_t *buf, uint64_t len)
{
	int remain = len;
	uint32_t *start = (uint32_t*)buf;
	const int hdr_size = sizeof(*start);
	while(remain >= hdr_size) {
		uint32_t nal_len = ENDIAN_BE32(*start);
		*start = ENDIAN_BE32(1);
		remain -= (nal_len + hdr_size);
		buf += (nal_len + hdr_size);
		start = (uint32_t*)buf;
	}
}

Cheers,

Sean

 

 

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: H264 support [ New ]

[ Edited ]

I thought I should mention that the official fix for this bug will not be available until the first dot-release after BB10 launch.

In the meantime, the workaround posted in my message should be usable to convert AVC1 (NALU) streams to H264 (Annex-B) for anyone implementing video streaming using the hardware encoder.

 

I've confirmed that this results in H.264 streams playable by VLC.

 

When the official fix becomes available, you can remove this workaround code and switch from configuring the encoder in _AVC1 mode to _H264 mode.

 

Cheers,

Sean

Please use plain text.
Developer
dynamicdhaka
Posts: 101
Registered: ‎12-10-2009
My Device: styile 9670
My Carrier: SingTel

Re: H264 support [ New ]

HI smsveigh,

                   we are trying to encode video using H264 and using CAMERA_VIDEOCODEC_AVC1 . i have used your nalutoannexb converter. but my recorded video is not played by vlc or other decoder.

 

Mobile Application Advisor
Please use plain text.