Source: http://stackoverflow.com/questions/25197169/how-to-decode-a-h-264-frame-on-ios-by-hardware-decoding
How to decode a H. Frame on IOS by hardware decoding?
Up vote 8 down vote favorite4 |
I have been used ffmpeg to decode every single frame that I received from my IP cam. The brief code looks like this: -(void) decodeFrame:(unsigned char *)frameData frameSize:(int)frameSize{ AVFrame frame; AVPicture picture; AVPacket pkt; AVCodecContext *context; pkt.data = frameData; pat.size = frameSize; avcodec_get_frame_defaults(&frame); avpicture_alloc(&picture, PIX_FMT_RGB24, targetWidth, targetHeight); avcodec_decode_video2(&context, &frame, &got_picture, &pkt);}
The code woks fine, but it ' s software decoding. I want to enhance the decoding performance by hardware decoding. After lots of the, I know it may is achieved by avfoundation framework. The Avassetreader class may help, but I can ' t figure out what's the next. Could anyone points out the following steps for me? Any help would is appreciated. iOS ffmpeg avfoundation H. hardware-acceleration
ShareImprove this question |
Asked 8 ' in 6:22 Chihhao 1 |
|
|
Add a Comment |
2 Answers Active oldest votes
Up vote vote accepted |
IOS does not provide no public access directly to the hardware decode engine, because hardware are always used to Decode H-Video on IOS. Therefore, Session 513 gives you all the information your need to allow frame-by-frame decoding on IOS. In short, per the session:
- Generate Individual Network Abstraction Layer units (Nalus) from your H. Elementary stream. There is much information on how the IS-done online. VCL Nalus (IDR and NON-IDR) contain your video data and is is fed into the decoder.
- re-package Those nalus according to the ' AVCC ' format, removing NALU start codes and replacing them with a 4-byte Nalu Length header.
- Create a
cmvideoformatdescriptionref from your SPS and PPS Nalus via Cmvideoformatdescriptioncreatefromh264parametersets ()
- package Nalu frames as
cmsamplebuffer s per session 513.
- Create a
vtdecompressionsessionref , and Feed vtdecompressionsessiondecodeframe () with The sample buffers
- Alternatively, use
Avsamplebufferdisplaylayer , whose -enqueuesamplebuf Fer: method obviates the need to create your own decoder.
ShareImprove this answer |
Edited Sep at 1:33
|
answered Oct at 18:37 RPJ 1,9052 |
|
|
|
this works as of IOS 8. Note that the 4-byte Nalu length header was in Big-endian format, so if you had a UInt32 value it must be byte-swapped Before copying to the Cmblockbuffer (use CFSwapInt32). – 12on Dec ' at 16:17 |
|
thank 12on, I was banging my head against decode errors for a long time until I tried swapping the bytes as you s Aid. – greg Feb at 23:30 |
|
@rpj-can you explain the 3rd (packaging) step? How many Nalu frames should I pack (for example all with the same frame number)? – tomasz Wójcik may 7 at 8:57 |
|
This link provide more detail explanation on how to decode H. A step by step:stackoverflow.com/a/29525001/3156169– Chihhao at 2:40 |
Add a Comment |
Up vote 1 down vote |
Edit: This link provide more detail explanation on how to decode H. A step by step:stackoverflow.com/a/29525001/3156169 Original Answer: I watched the session 513 "Direct Access to Video Encoding and decoding" in WWDC yesterday, and got the answer of my Own question. The speaker says:
We have the Video Toolbox (in IOS 8). Video Toolbox has been there in OS X for a while, and now it's finally populated with headers on Ios.this provides direct Access to encoders and decoders.
So, the there is no-to-do hardware decoding-frame by-frame in iOS 7, but the it can be doing in iOS 8. Is there anyone figure out how to directly access to video encoding and decoding frame by frame in IOS 8?
shareimprove this answer |
edited may 2:43 |
answered aug" at 5:47 Chihhao 931 11 |
|
|
|
Thank much for: "Direct Access to Video Encoding and decoding" –user1748502 June one at 22:49 |
Add a Comment |
How to decode a H. Frame on IOS by hardware decoding?