Skip to content

Commit

Permalink
Updated HBRecorderCodecInfo to get more info
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Oct 20, 2020
1 parent 051ec94 commit 21a14c4
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@
import androidx.core.content.ContextCompat;

import com.hbisoft.hbrecorder.HBRecorder;
import com.hbisoft.hbrecorder.HBRecorderCodecInfo;
import com.hbisoft.hbrecorder.HBRecorderListener;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static android.content.res.Configuration.ORIENTATION_PORTRAIT;


/**
Expand Down Expand Up @@ -122,6 +128,44 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

// Examples of how to use the HBRecorderCodecInfo class to get codec info
HBRecorderCodecInfo hbRecorderCodecInfo = new HBRecorderCodecInfo();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
int mWidth = hbRecorder.getDefaultWidth();
int mHeight = hbRecorder.getDefaultHeight();
String mMimeType = "video/avc";
int mFPS = 30;
if (hbRecorderCodecInfo.isMimeTypeSupported(mMimeType)) {
String defaultVideoEncoder = hbRecorderCodecInfo.getDefaultVideoEncoderName(mMimeType);
boolean isSizeAndFramerateSupported = hbRecorderCodecInfo.isSizeAndFramerateSupported(mWidth, mHeight, mFPS, mMimeType, ORIENTATION_PORTRAIT);
Log.e("EXAMPLE", "THIS IS AN EXAMPLE OF HOW TO USE THE (HBRecorderCodecInfo) TO GET CODEC INFO:");
Log.e("HBRecorderCodecInfo", "defaultVideoEncoder for (" + mMimeType + ") -> " + defaultVideoEncoder);
Log.e("HBRecorderCodecInfo", "MaxSupportedFrameRate -> " + hbRecorderCodecInfo.getMaxSupportedFrameRate(mWidth, mHeight, mMimeType));
Log.e("HBRecorderCodecInfo", "MaxSupportedBitrate -> " + hbRecorderCodecInfo.getMaxSupportedBitrate(mMimeType));
Log.e("HBRecorderCodecInfo", "isSizeAndFramerateSupported @ Width = "+mWidth+" Height = "+mHeight+" FPS = "+mFPS+" -> " + isSizeAndFramerateSupported);
Log.e("HBRecorderCodecInfo", "isSizeSupported @ Width = "+mWidth+" Height = "+mHeight+" -> " + hbRecorderCodecInfo.isSizeSupported(mWidth, mHeight, mMimeType));
Log.e("HBRecorderCodecInfo", "Default Video Format = " + hbRecorderCodecInfo.getDefaultVideoFormat());

HashMap<String, String> supportedVideoMimeTypes = hbRecorderCodecInfo.getSupportedVideoMimeTypes();
for (Map.Entry<String, String> entry : supportedVideoMimeTypes.entrySet()) {
Log.e("HBRecorderCodecInfo", "Supported VIDEO encoders and mime types : " + entry.getKey() + " -> " + entry.getValue());
}

HashMap<String, String> supportedAudioMimeTypes = hbRecorderCodecInfo.getSupportedAudioMimeTypes();
for (Map.Entry<String, String> entry : supportedAudioMimeTypes.entrySet()) {
Log.e("HBRecorderCodecInfo", "Supported AUDIO encoders and mime types : " + entry.getKey() + " -> " + entry.getValue());
}

ArrayList<String> supportedVideoFormats = hbRecorderCodecInfo.getSupportedVideoFormats();
for (int j = 0; j < supportedVideoFormats.size(); j++) {
Log.e("HBRecorderCodecInfo", "Available Video Formats : " + supportedVideoFormats.get(j));
}
}else{
Log.e("HBRecorderCodecInfo", "MimeType not supported");
}

}

}

//Create Folder
Expand Down
14 changes: 14 additions & 0 deletions hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ private void setScreenDensity() {
mScreenDensity = metrics.densityDpi;
}

//Get default width
public int getDefaultWidth(){
HBRecorderCodecInfo hbRecorderCodecInfo = new HBRecorderCodecInfo();
hbRecorderCodecInfo.setContext(context);
return hbRecorderCodecInfo.getMaxSupportedWidth();
}

//Get default height
public int getDefaultHeight(){
HBRecorderCodecInfo hbRecorderCodecInfo = new HBRecorderCodecInfo();
hbRecorderCodecInfo.setContext(context);
return hbRecorderCodecInfo.getMaxSupportedHeight();
}

//Set Custom Dimensions (NOTE - YOUR DEVICE MIGHT NOT SUPPORT THE SIZE YOU PASS IT)
public void setScreenDimensions(int heightInPX, int widthInPX){
mScreenHeight = heightInPX;
Expand Down
Loading

0 comments on commit 21a14c4

Please sign in to comment.