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
Developer
dynamicdhaka
Posts: 101
Registered: ‎12-10-2009
My Device: styile 9670

Video Recording and playback using H264 codec

Dear All,

            i want to develop a video calling application for blackberry 10 platform. our basic functionality for audio already implemented. i am  going to develop video part now. anyone can post or suggest any way which is accepatable for video recording , playback and if possible to use H264 codec.

Mobile Application Advisor
Retired
gsandhu
Posts: 41
Registered: ‎07-14-2008
My Device: Not Specified

Re: Video Recording and playback using H264 codec

[ Edited ]

For video capture we do have a supported API to get the encoded frames. The two APIs of importance are camera_set_video_property and camera_start_encode.

https://developer.blackberry.com/native/reference/bb10/com.qnx.doc.camera.lib_ref/topic/camera_set_v... https://developer.blackberry.com/native/reference/bb10/com.qnx.doc.camera.lib_ref/topic/camera_start...

 

Basically using the camera_start_encode, the encoded video callback delivers packets out of the video encoder, and the encoded audio callback delivers packets out of the audio encoder.

 

The supported video codecs are CAMERA_VIDEOCODEC_AVC1 and _H264.

Supported audio codecs are CAMERA_AUDIOCODEC_AAC and _RAW (PCM).

  

Developer
dynamicdhaka
Posts: 101
Registered: ‎12-10-2009
My Device: styile 9670

Re: Video Recording and playback using H264 codec

Hy gutter, we want to write video frame into our local buffer instead of file.
Mobile Application Advisor
New Developer
rakib062
Posts: 3
Registered: ‎05-12-2013
My Device: BB10 Dev Alpha

Re: Video Recording and playback using H264 codec

 Hi,

 

I am trying to get the encoded data from camera API and then write this data to a file. But after writing I can not play it using any H264 player. Here is the code to start encoding:

 if (mCameraHandle != CAMERA_HANDLE_INVALID) {
        qDebug() << "camera already running";
        return EBUSY;
    }
    mCameraUnit = cameraUnit;
    camera_error_t error;
    if (camera_open(mCameraUnit,
                CAMERA_MODE_RW | CAMERA_MODE_ROLL,
                    &mCameraHandle) != CAMERA_EOK) {
        qDebug() << "could not open camera";
        return EIO;
    }
    if(camera_can_feature(mCameraHandle,CAMERA_FEATURE_VIDEO))
    {
        fprintf(stderr,"Camera can feature video\n");
    }
    else
    {
        fprintf(stderr,"Camera can not feature video\n");
    }
    if(camera_can_feature(mCameraHandle,CAMERA_FEATURE_PREVIEWISVIDEO ))
    {
        fprintf(stderr,"Camera can feature CAMERA_FEATURE_PREVIEWISVIDEO \n");
    }
    else
    {
        fprintf(stderr,"Camera can not feature CAMERA_FEATURE_PREVIEWISVIDEO \n");
    }


    if ((error=camera_set_videovf_property(mCameraHandle,
                                    CAMERA_IMGPROP_WIN_GROUPID, group.toStdString().c_str(),
                                    CAMERA_IMGPROP_WIN_ID, id.toStdString().c_str(),
                                    CAMERA_IMGPROP_FRAMERATE, (double)30.0  )) == CAMERA_EOK)
    {
        fprintf(stderr,"viewfinder configured\n");

        error=camera_start_video_viewfinder(mCameraHandle,NULL,NULL,NULL);
        if(error==CAMERA_EOK)
        {
            fprintf(stderr,"Camera viewfinder open success\n");
        }
        else
        {
            fprintf(stderr,"Camera viewfinder open failed:%s\n",ErrorToString(error).toAscii().constData());
        }

        if(mCameraHandle==CAMERA_HANDLE_INVALID)
            fprintf(stderr,"Invalid camera handle\n");
        else
            fprintf(stderr,"Valid camera handle\n");

        QString f("data/myvideo.mp4");
    
        this->audioFile.setFileName("data/audio.mp3");
        this->videoFile.setFileName(f);

        audioFile.remove();
        videoFile.remove();

        if(!videoFile.open(QIODevice::WriteOnly))
        {
            fprintf(stderr,"Can not open file to write video:%s\n",f.toAscii().constData());
            exit(-1);
        }
        if(!audioFile.open(QIODevice::WriteOnly))
        {
            fprintf(stderr,"Can not open file to write audio:%s\n",f.toAscii().constData());
            exit(-1);
        }

        error=camera_start_encode(mCameraHandle,&VideoCallBack,&EncVideoCallBack,&EncAudioCallBack,&VideoStatusCallBack,this);
        if(error==CAMERA_EOK)
        {
            fprintf(stdout,"Encoding started\n");
             mStartFrontButton->setVisible(false);
                        mStartRearButton->setVisible(false);
                        mStopButton->setVisible(true);
                        mTakePictureButton->setVisible(true);
                        mTakePictureButton->setEnabled(true);
                        return EOK;
        }
        else
        {
            fprintf(stdout,"Encoding failed: %d, %s\n",error,ErrorToString(error).toAscii().constData());
        }

 

And here is the call back function:

 

static void VideoCallBack(camera_handle_t handle, camera_buffer_t* buffer, void* ob)
    {
        fprintf(stderr,"Video callback function called. buffer  size:%ld\n",buffer->framesize);
        ((HelloCameraApp*)ob)->SaveVideoData((const char*)buffer->framebuf,buffer->framesize);
    }

 

 static void EncAudioCallBack(camera_handle_t handle, camera_buffer_t* buffer, void* ob)
    {
        fprintf(stderr,"EncAudioCallBack function called\n");
        ((HelloCameraApp*)ob)->SaveAudioData((const char*)buffer->framebuf,buffer->framesize);
    }

    void SaveVideoData(const char* data,uint64_t size)
    {
        qint64 len=this->videoFile.write(data,size);
        this->bufCount++;
        fprintf(stderr,"End of data saving:%lld. bufCount:%d\n",len,bufCount);
    }
    
    void SaveAudioData(const char* data,uint64_t size)
    {
        qint64 len=this->audioFile.write(data,size);
        this->bufCount++;
        fprintf(stderr,"End of data saving:%lld. bufCount:%d\n",len,bufCount);
    }

 

Any help will be highly appreciated.

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Video Recording and playback using H264 codec

camera_buffer_t::framesize is not the size of the data.

it is the size of the camera_buffer_t struct (which contains a union, hence the need to provide a size field).

 

you will need to check ::frametype, and based on that value, you will then scope in on the ::framedesc union to find the appropriate descriptor size field.

 

eg.

if (buffer->frametype == CAMERA_FRAMETYPE_COMPRESSEDVIDEO) {

   thesize = buffer->framedesc.compvid.bufsize;

}

Contributor
oly104
Posts: 15
Registered: ‎04-16-2013
My Device: DevAlpha B

Re: Video Recording and playback using H264 codec

I have recorded H264 encoded video frames in a camera_buffer_t array.  Is it possible to play the video from the array in cascades using MediaPlayer or any other way?

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Video Recording and playback using H264 codec

not just yet.  but the MM team should have something for this soon.

 

However... if you encapsulate this using a local http server or something as HLS, then it might work.. or feeding the data through a filesystem pipe, but I am told that using pipes as input to mm-renderer is not tested - specifically, I have been warned not to let the pipe run dry.

 

Cheers,

Sean

Regular Contributor
dlacerte
Posts: 68
Registered: ‎03-12-2013
My Device: BB Z10

Re: Video Recording and playback using H264 codec

Hi,

 

This thread sounds very promising, is there a similar solution for decoding h264 on-the-fly and playing it back?

 

Dominique