HarmonyOS AVScreenCapture: Complete Screen Recording Development Guide with ArkTS & NDK Examples

This guide covers HarmonyOS AVScreenCapture for screen recording, detailing features like hardware-accelerated H.264/H.265 encoding, dual audio tracks, full-screen and region capture, plus complete ArkTS and C++ NDK code examples with configuration parameters and development workflows.

HarmonyOS Developer Technology
HarmonyOS Developer Technology
HarmonyOS Developer Technology
HarmonyOS AVScreenCapture: Complete Screen Recording Development Guide with ArkTS & NDK Examples

Overview of AVScreenCapture

AVScreenCapture is HarmonyOS's powerful screen recording component supporting high-definition, low-latency, multi-scenario screen content capture. It enables developers to implement:

Game recording: precise per-frame capture to reproduce highlight moments

Teaching demos: clear recording of operation flows to improve learning efficiency

Meeting sharing: one-click screen + voice recording for efficient remote collaboration

Live streaming push: low-latency output adapted for live platform requirements

Supported recording modes include:

Full-screen recording / region recording (custom window)

System audio + microphone dual-track recording

Hardware-accelerated encoding: H.264 / H.265 for efficient compression without stutter

Container formats: MP4, M4A, compatible with mainstream players

Typical applications: game recording tools, online education platforms, remote office assistants, live streaming apps.

Development Languages Supported

ArkTS Development

Rapidly build recording UI with clear state transitions

Integrated recording control and error callbacks

C/C++ NDK Development

Deep integration with underlying graphics system, suitable for high-performance recording engines

Screen Recording Workflow (ArkTS Example)

// 1. Create AVScreenCapture instance
const screenCapture = await media.createScreenCapture();
let filePath: string = 'screenCapture.mp4';
let captureFile: fs.File = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);

// 2. Configure recording parameters
const captureConfig = {
  // Developers can set width and height as needed.
  frameWidth: 768,
  frameHeight: 1280,
  // Refer to app file access and management dev example to create and read/write a file fd.
  fd: captureFile.fd,
  // Optional parameters and their defaults.
  videoBitrate: 10000000,
  audioSampleRate: 48000,
  audioChannelCount: 2,
  audioBitrate: 96000,
  displayId: 0,
  preset: media.AVScreenCaptureRecordPreset.SCREEN_RECORD_PRESET_H264_AAC_MP4
};
await screenCapture.init(captureConfig);

// 3. Start/stop recording
screenCapture.startRecording();
screenCapture.stopRecording();

// 4. Release resources
screenCapture.release();

NDK Development (C++ Example)

// 1. Create AVScreenCapture instance
struct OH_AVScreenCapture *capture = OH_AVScreenCapture_Create();

// 2. Configure parameters and prepare recording
OH_AudioCaptureInfo miccapinfo = {.audioSampleRate = 16000, .audioChannels = 2, .audioSource = OH_MIC};
OH_VideoCaptureInfo videocapinfo = {
    .videoFrameWidth = 768, .videoFrameHeight = 1280, .videoSource = OH_VIDEO_SOURCE_SURFACE_RGBA};
OH_AudioInfo audioinfo = {
    .micCapInfo = miccapinfo,
};
OH_VideoInfo videoinfo = {.videoCapInfo = videocapinfo};
OH_AVScreenCaptureConfig config = {.captureMode = OH_CAPTURE_HOME_SCREEN,
        .dataType = OH_ORIGINAL_STREAM,
        .audioInfo = audioinfo,
        .videoInfo = videoinfo};
OH_AVScreenCapture_Init(capture, config);

// 3. Start/stop screen recording.
OH_AVScreenCapture_StartScreenRecording(capture);
OH_AVScreenCapture_StopScreenRecording(capture);

// 4. Release resources
OH_AVScreenCapture_Release(capture);

Why Choose AVScreenCapture?

Efficient and Stable, Easily Build Professional-Grade Recording Apps

Native support for HarmonyOS graphics architecture, hardware-accelerated encoding, smooth recording without stutter, stable frame rate, precise audio-video synchronization.

Flexible Configuration for Diverse Needs

Supports full-screen/region recording, multi-track audio mixing, custom resolution and bitrate, adaptable to gaming, teaching, meeting, live streaming and other scenarios.

Open Documentation + Community Support for Quick Onboarding

Provides comprehensive API documentation, complete sample code, and debugging tools, combined with an active developer community to help you go from 0 to 1 rapidly.

Official Documentation Links

AVScreenCapture Development Guide ArkTS API: https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-media-avscreencapturerecorder

AVScreenCapture Development Guide C API: https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-native-avscreen-capture-h

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mobile developmentHarmonyOShardware-accelerationArkTSNDKscreen-recordingmedia APIavscreencapture
HarmonyOS Developer Technology
Written by

HarmonyOS Developer Technology

HarmonyOS developers provide key technology analysis, version updates, Codelabs practice, and event information for HarmonyOS. Welcome developers to join the HarmonyOS ecosystem and create infinite possibilities together!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.