I want to attach Pre-Rolls to videos taken on android devices
Asked Answered
G

2

12

I'm using mp4parser and the videos need to be of the same kind. I was thinking of using android's media codec to decode & encode the preroll video to fit the same encoding output of the cameras (front & back) any suggestion on how this can be done (how to get specific device encoding params)?

Gman answered 15/5, 2018 at 19:25 Comment(2)
You want to know codec capabilities?Mock
well, I want a magic android lib that detects android's camera default video encoding (framerate, bitrate, codec etc) decodes my custom pre-roll video and encode it using the device's codec capabilities so I can merge it using m4parser (you can only merge files of the same type).Gman
A
0

If you want to find out what encoding your Android camera is using, try using this: https://developer.android.com/reference/android/media/CamcorderProfile

This should suffice to answer your questions for detecting the video encoding including : The file output format, Video codec format, Video bit rate in bits per second, Video frame rate in frames per second, Video frame width and height, Audio codec format, Audio bit rate in bits per second, Audio sample rate Number of audio channels for recording.

Pulled a lot of the above information from here as well: https://developer.android.com/guide/topics/media/camera#capture-video

As for transcoding videos that are already in the users roll, I found this useful transcoder that was written in pure java using the Android MediaCodec API and can be found here: https://github.com/ypresto/android-transcoder

Also, as rupps mentioned below, you can use ffmeg which is proven to work countless times on Android. However, the reasoning for me linking the other transcoder first is because, as the author states, "FFmpeg is the most famous solution for transcoding. But using FFmpeg binary on Android can cause GPL and/or patent issues. Also using native code for Android development can be troublesome because of cross-compiling, architecture compatibility, build time and binary size." So use whichever one you believe better suits you. Here is the link for ffmeg for Android: https://github.com/WritingMinds/ffmpeg-android

If you don't want to use the transcoder that someone else made then I reccomend making your own transcoder using the MediaCodec API that can be found here: https://developer.android.com/reference/android/media/MediaCodec

Aubergine answered 24/5, 2018 at 13:48 Comment(6)
also tak a look at Android ffmpeg. github.com/WritingMinds/ffmpeg-android and github.com/WritingMinds/ffmpeg-android-java ... ffmpeg is a command line Unix utility that can transcode to virtually any format. You can launch it from your app.Stefaniastefanie
@Stefaniastefanie yup! ffmpeg is a very popular choice. I just decided to add this persons transcoder because, as he states in his README, "FFmpeg is the most famous solution for transcoding. But using FFmpeg binary on Android can cause GPL and/or patent issues. Also using native code for Android development can be troublesome because of cross-compiling, architecture compatibility, build time and binary size." So I just added another option. Thanks for your input!Aubergine
oh sorry i didnt read it... very right, the binary size is too much, I am still deciding whether to include thse extra 25Mb just for a transcoding.Stefaniastefanie
@Stefaniastefanie Good point, it can be a little heavy. I wouldn't spend too much time trying to find a better solution just to decrease your size from 25Mb though. I imagine if you try yourself you will run into a lot of headaches as transcoding can be an absolute pain.Aubergine
using FFmpeg binary on Android can cause GPL and/or patent issues. Also using native code for Android development can be troublesome because of cross-compiling, architecture compatibility, build time and binary size.Simms
@MKVimalan That is exactly why I recommended the Android transcoder written by ypresto that uses the MediaCodec APIAubergine
C
0

If you want magic, try this library.

https://github.com/INDExOS/media-for-mobile/

Take a look at the MediaComposer class.

Here's also a code snippet on how it's done.

org.m4m.MediaComposer mediaComposer = new org.m4m.MediaComposer(factory, progressListener);

mediaComposer.addSourceFile(mediaUri1);
int orientation = mediaFileInfo.getRotation();

mediaComposer.setTargetFile(dstMediaPath, orientation);

// set video encoder
VideoFormatAndroid videoFormat = new VideoFormatAndroid(videoMimeType, width, height);
videoFormat.setVideoBitRateInKBytes(videoBitRateInKBytes);
videoFormat.setVideoFrameRate(videoFrameRate);
videoFormat.setVideoIFrameInterval(videoIFrameInterval);
mediaComposer.setTargetVideoFormat(videoFormat);

// set audio encoder
AudioFormatAndroid aFormat = new AudioFormatAndroid(audioMimeType, audioFormat.getAudioSampleRateInHz(), audioFormat.getAudioChannelCount());
aFormat.setAudioBitrateInBytes(audioBitRate);
aFormat.setAudioProfile(MediaCodecInfo.CodecProfileLevel.AACObjectLC);
mediaComposer.setTargetAudioFormat(aFormat);

mediaComposer.setTargetFile(dstMediaPath, orientation);
mediaComposer.start();
Colvin answered 24/5, 2018 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.