Skip to content

Commit

Permalink
simplification AND improvement to video obscura features
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Aug 10, 2017
1 parent 387bcb5 commit 0c2548a
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 486 deletions.
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
Expand Down
118 changes: 74 additions & 44 deletions app/src/main/java/org/witness/ssc/video/FFMPEGWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public void onFinish() {}



public void processVideo(File redactSettingsFile,
ArrayList<RegionTrail> regionTrails, File inputFile, File outputFile, String format, int mDuration,
int iWidth, int iHeight, int oWidth, int oHeight, int frameRate, int kbitRate, String vcodec, String acodec, ExecuteBinaryResponseHandler listener) throws Exception {
public void processVideo(
ArrayList<RegionTrail> regionTrails, File inputFile, File outputFile, int frameRate, int mDuration, int mOutputLength,
boolean compressVideo, int obscureVideoAmount, int obscureAudioAmount, ExecuteBinaryResponseHandler listener) throws Exception {

DecimalFormat df = new DecimalFormat("####0.00");

Expand All @@ -65,46 +65,74 @@ public void processVideo(File redactSettingsFile,
alCmds.add("-i");
alCmds.add(inputFile.getCanonicalPath());

if (mOutputLength > 0)
{
alCmds.add("-t");
alCmds.add(mOutputLength+"");
}

float widthMod = ((float)oWidth)/((float)iWidth);
float heightMod = ((float)oHeight)/((float)iHeight);

// writeRedactData(redactSettingsFile, obscureRegionTrails, widthMod, heightMod, mDuration);
if (frameRate > 0)
{
alCmds.add("-r");
alCmds.add(frameRate+"");
}

alCmds.add("-b:v");
alCmds.add("1M");
if (compressVideo) {
alCmds.add("-b:v");
alCmds.add("500K");

}

alCmds.add("-b:a");
alCmds.add("64k");
if (obscureAudioAmount > 0) {
alCmds.add("-filter_complex");
alCmds.add("vibrato=f=" + obscureAudioAmount);

alCmds.add("-vf");
alCmds.add("-b:a");
alCmds.add("4K");

alCmds.add("-ab");
alCmds.add("4K");

alCmds.add("-ar");
alCmds.add("11025");

alCmds.add("-ac");
alCmds.add("1");
}

StringBuffer filters = new StringBuffer();

if (obscureVideoAmount > 0) {
int pixelScale = obscureVideoAmount;

//scale down and up to fully pixelize
filters.append("scale=iw/" + pixelScale + ":ih/" + pixelScale + ",scale=" + pixelScale + "*iw:" + pixelScale + "*ih:flags=neighbor,");
}

for (RegionTrail trail : regionTrails)
{

if (trail.isDoTweening())
{
if (regionTrails.size() == 0) {
//do what?
}
else {
for (RegionTrail trail : regionTrails) {

if (trail.isDoTweening() && trail.getRegionCount() > 1) {
int timeInc = 100;

for (int i = 0; i < mDuration; i = i+timeInc)
{
for (int i = 0; i < mDuration; i = i + timeInc) {
ObscureRegion or = trail.getCurrentRegion(i, trail.isDoTweening());
if (or != null)
{
if (or != null) {

int x = (int)or.getBounds().left;
int y = (int)or.getBounds().top;
int height = (int)or.getBounds().height();
int width = (int)or.getBounds().width();
int x = (int) or.getBounds().left;
int y = (int) or.getBounds().top;
int height = (int) or.getBounds().height();
int width = (int) or.getBounds().width();
String color = "black";
float timeStart = ((float)or.timeStamp)/1000f;
float timeStop = (((float)or.timeStamp)+100)/1000f;
float timeStart = ((float) or.timeStamp) / 1000f;
float timeStop = (((float) or.timeStamp) + 100) / 1000f;

float timeEnd = ((float)mDuration)/1000f;
timeStop = Math.max(timeStop,timeEnd);
float timeEnd = ((float) mDuration) / 1000f;
timeStop = Math.max(timeStop, timeEnd);

filters.append("drawbox=x=" + x + ":y=" + y
+ ":w=" + width + ":h=" + height
Expand All @@ -115,43 +143,45 @@ public void processVideo(File redactSettingsFile,
}
}

}
else
{
} else {

for (Integer orKey : trail.getRegionKeys())
{
for (Integer orKey : trail.getRegionKeys()) {
ObscureRegion or = trail.getRegion(orKey);

int x = (int)or.getBounds().left;
int y = (int)or.getBounds().top;
int height = (int)or.getBounds().height();
int width = (int)or.getBounds().width();
int x = (int) or.getBounds().left;
int y = (int) or.getBounds().top;
int height = (int) or.getBounds().height();
int width = (int) or.getBounds().width();
String color = "black";

filters.append("drawbox=x=" + x + ":y=" + y
+ ":w=" + width + ":h=" + height
+ ":color=" + color
+ ":t=max");

}
}


}
}
}


Log.d(getClass().getName(),"filters: " + filters.toString());
if (filters.toString().length() > 0) {
Log.d(getClass().getName(), "filters: " + filters.toString());

String filterCmd = filters.toString();
alCmds.add("-vf");

alCmds.add(filterCmd.substring(0,filterCmd.length()-1));
String filterCmd = filters.toString();

alCmds.add(filterCmd.substring(0, filterCmd.length() - 1));
}

alCmds.add(outputFile.getCanonicalPath());
alCmds.add(outputFile.getCanonicalPath());

String[] cmd = alCmds.toArray(new String[alCmds.size()]);
String[] cmd = alCmds.toArray(new String[alCmds.size()]);

try {
try {


FFmpeg ffmpeg = FFmpeg.getInstance(context);
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/org/witness/ssc/video/RegionTrail.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public ObscureRegion getRegion (Integer key)
{
return regionMap.get(key);
}


public int getRegionCount ()
{
return regionMap.size();
}

public TreeSet<Integer> getRegionKeys ()
{
TreeSet<Integer> regionKeys = new TreeSet<Integer>(regionMap.keySet());
Expand Down
Loading

0 comments on commit 0c2548a

Please sign in to comment.