Skip to content

Commit 8dbdd14

Browse files
authored
Merge pull request #8 from MobileRoboticsSkoltech/unusedvideos
Remove unused videos created on setup
2 parents cff4353 + da10fcf commit 8dbdd14

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

app/src/main/java/com/googleresearch/capturesync/ImageMetadataSynchronizer.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import androidx.annotation.NonNull;
3232

33+
import java.io.File;
3334
import java.util.ArrayList;
3435
import java.util.LinkedList;
3536
import java.util.List;
@@ -392,13 +393,18 @@ public void onCaptureCompleted(
392393
@Override
393394
public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, int sequenceId, long frameNumber) {
394395
super.onCaptureSequenceCompleted(session, sequenceId, frameNumber);
395-
Log.v(TAG, "YAAAY I've completed succesfully");
396396
if (context.getLastVideoSeqId() != null && sequenceId == context.getLastVideoSeqId() && context.getLogger() != null) {
397397
context.getMediaRecorder().stop();
398-
// mLogger.close();
399-
// mLogger = null;
398+
399+
if (context.isVideoRecording()) {
400+
context.setVideoRecording(false);
401+
} else {
402+
// MediaRecorder created an empty video on preview, should perform a cleanup
403+
context.deleteUnusedVideo();
404+
}
405+
400406
context.getMediaRecorder().reset();
401-
context.setVideoRecording(false);
407+
402408
context.getLogger().close();
403409
context.setLogger(null);
404410
}

app/src/main/java/com/googleresearch/capturesync/MainActivity.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import java.util.Date;
8080
import java.util.List;
8181
import java.util.Locale;
82-
import java.util.concurrent.Future;
8382
import java.util.concurrent.FutureTask;
8483
import java.util.stream.Collectors;
8584

@@ -95,6 +94,21 @@ public class MainActivity extends Activity {
9594
private String lastTimeStamp;
9695
private PeriodCalculator periodCalculator;
9796

97+
public String getLastVideoPath() {
98+
return lastVideoPath;
99+
}
100+
101+
public void deleteUnusedVideo() {
102+
String videoPath = getLastVideoPath();
103+
File videoFile = new File(videoPath);
104+
boolean result = videoFile.delete();
105+
if (!result) {
106+
Log.d(TAG, "Video file could not be deleted");
107+
}
108+
}
109+
110+
private String lastVideoPath;
111+
98112
public Integer getLastVideoSeqId() {
99113
return lastVideoSeqId;
100114
}
@@ -951,6 +965,7 @@ private void createRecorderSurface() throws IOException {
951965
MediaRecorder recorder = setUpMediaRecorder(surface, false);
952966
recorder.prepare();
953967
recorder.release();
968+
deleteUnusedVideo();
954969
}
955970

956971
private MediaRecorder setUpMediaRecorder(Surface surface) throws IOException {
@@ -968,8 +983,8 @@ private MediaRecorder setUpMediaRecorder(Surface surface, boolean specifyOutput)
968983
* set output file in media recorder
969984
*/
970985

971-
String currentPath = getOutputMediaFilePath();
972-
recorder.setOutputFile(currentPath);
986+
lastVideoPath = getOutputMediaFilePath();
987+
recorder.setOutputFile(lastVideoPath);
973988

974989
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
975990
recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

0 commit comments

Comments
 (0)