Intel INDE Media Pack

    Last time in a review article about Intel INDE, we mentioned the Media Pack and its key features. In this article we will dwell on it in more detail.

    INDE Media Pack is a library that includes various components for working with audio and video. In terms of implementation, this is an add-on to Android media components that uses hardware acceleration to encode and decode video. Compared to using classes for working with multimedia in Android, it is much simpler to use, the developer does not need to understand all the intricacies of the work of media codecs, extractor, muxer, just to embed the ability to work with video in his application.

    Applications using Media Packwill work on all architectures ( ARM , IA ), on devices running Android 4.3 and above.

    You can download the library using the link on the official Intel INDE page . After installing the Intel INDE manager, open it, select the Media component , then Download , after it is downloaded, start the installation ( Install ).

    image

    Upon completion of the installation, a folder containing everything you need to start working with Media Pack will be created in the selected directory .

    image

    Let's start by building and running the examples, as This is the fastest and most visual way to evaluate what Media Pack is capable of.. To do this, we need Eclipse and an Android device version 4.3 or higher.

    Run Eclipse next File -> New -> Project -> Android Project From Existing Code

    image

    The samples project has a dependency on the effects project , so that Eclipse correctly defines all the dependencies, you need to import both projects at once. To do this, specify the path to the samples folder as the root directory and mark both projects for import - apps and effects .

    image

    We launch the imported apps package as an Android application, after the application is built and launched, the main activity of the application will appear, in which the various usage models that the Media Pack offers are presented .

    image

    Game Capturing - capture video from an application that uses OpenGL
    Transcode Video - convert video with the specified parameters
    Join Video - glue two video files
    Cut Video - cut a video from a given segment
    Video Effect - convert video with video overlay
    Audio Effect - convert video with audio overlay
    Streaming from Camera effect - broadcast video from the camera to the Wowza service
    Get Media File Info - getting information about a media file

    After playing with samples, you can begin to study the insides, the first candidate for analysis will be

    Transcode video


    This example contains two activities.

    • ComposerTranscodeActivity - provides a video file selection and displays it in the preview, nothing interesting
    • ComposerTranscodeCoreActivity - displays detailed information about the selected video file, performs its conversion


    image

    The key element in this example is the MediaComposer class , which takes one or more media files as input and converts them according to the specified parameters.

    In order to convert the video, we need to follow five simple steps.

    1. Create a MediaComposer object

    MediaComposer mediaComposer = new AndroidMediaObjectFactory(getApplicationContext());


    2. Specify the path to the source and resulting files

    String srcPath = “…”;
    String dstPath = “…”;
    mediaComposer.addSourceFile(srcPath);
    mediaComposer.setTargetFile(dstPath);


    3. Set the parameters of the resulting video

    // Создаем и инициализируем видео формат
    // Формат видео
    String videoMimeType = “video/avc”;
    // Ширина кадра
    int videoFrameWidth = 640;
    // Высота кадра
    int videoFrameHeight = 480;
    // Битрейт в килобайтах
    int videoBitRate = 5000;
    // Частота кадров в секунду
    int videoFrameRate = 30;
    // Частота ключевых кадров
    int videoIFrameInterval = 1;
    VideoFormatAndroid videoFormat = new VideoFormatAndroid(videoMimeType, videoFrameWidth, videoFrameHeight);
    videoFormat.setVideoBitRateInKBytes(videoBitRate);
    videoFormat.setVideoFrameRate(videoFrameRate);
    videoFormat.setVideoIFrameInterval(videoIFrameInterval);
    // Задаем видео формат
    mediaComposer.setTargetVideoFormat(videoFormat);
    // Создаем и инициализируем аудио формат
    // Формат Audio
    String audioMimeType = “audio/mp4a-latm”;
    // Частота аудио сэмплов
    int audioSampleRate = 48000;
    // Количество уадио каналов
    int audioChannelCount = 2;
    // Аудио профайл
    int audioProfile = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
    AudioFormatAndroid audioFormat = new AudioFormatAndroid(audioMimeType , audioSampleRate, audioChannelCount);
    audioFormat.setAudioBitrate(audioBitRate);
    audioFormat.setAudioAacProfile(audioProfile);
    // Задаем аудио формат
    mediaComposer.setTargetAudioFormat(audioFormat); 


    4. Implement the MediaComposer.IProgressListener interface

    Conversion of video in MediaComposer occurs asynchronously, in a separate stream. In order for the application to be notified of the beginning and end of the conversion process, to receive progress messages and errors, it must implement the MediaComposer.IProgressListener interface and pass a pointer to it for the MediaComposer object .

    public MediaComposer.IProgressListener progressListener = new MediaComposer.IProgressListener() {
            @Override
            public void onMediaStart() {  
    	// Процесс преобразования начался          
            }
            @Override
            public void onMediaProgress(float progress) {
    	// Текущий прогресс          
            }
            @Override
            public void onMediaDone() {
    // Процесс преобразования завершился по завершению
            }
            @Override
            public void onMediaPause() {
    // Процесс преобразования был приостановлен
            }
            @Override
            public void onMediaStop() {
    // Процесс преобразования остановлен
            }
            @Override
            public void onError(Exception exception) {
    // Процесс преобразования завершился с ошибкой
            }
        };
    // Передаем указатель на интерфейс в MediaComposer
    mediaComposer.addProgressListener(progressListener); 


    5. Starting the conversion process

    The final step at which the conversion process starts with the given parameters.

    mediaComposer.start(); 


    Yes, the code turned out a lot, but basically it relates to the transfer of encoding parameters and the processing of the current state. Again, when compared with the implementation using the “standard” Android classes, such as MediaCodec , MediaExtractor , MediaMuxer , the code in our example is incomparably smaller.

    Video conversion is not the only model for using Media Pack . In the following articles, we will describe how, with the help of the GLCapture class , you can add the ability to capture and encode video in Android applications using Open GL or based on such popular frameworks as Unity and libGDX .

    Also popular now: