Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample RecordActivity.java seems isn't practical at all - java very high memory usage #806

Open
anonym24 opened this issue Oct 6, 2017 · 4 comments

Comments

@anonym24
Copy link

anonym24 commented Oct 6, 2017

https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java

I'm not sure about this part of code (as practical solution):

private void initRecorder() {

        Log.w(LOG_TAG,"init recorder");

        if (RECORD_LENGTH > 0) {
            imagesIndex = 0;
            images = new Frame[RECORD_LENGTH * frameRate];
            timestamps = new long[images.length];
            for (int i = 0; i < images.length; i++) {
                Log.i(LOG_TAG, "Allocating buffer for new Frame " + i);
                images[i] = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
                timestamps[i] = -1;
            }
        } else if (yuvImage == null) {
            yuvImage = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
            Log.i(LOG_TAG, "create yuvImage");
        }

        Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
        recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
        recorder.setFormat("mp4");
        recorder.setSampleRate(sampleAudioRateInHz);
        // Set in the surface changed method
        recorder.setFrameRate(frameRate);
        recorder.setVideoCodec(28);
        recorder.setVideoOption("crf", "28");
        recorder.setVideoOption("preset", "superfast");

        Log.i(LOG_TAG, "recorder initialize success");

        audioRecordRunnable = new AudioRecordRunnable();
        audioThread = new Thread(audioRecordRunnable);
        runAudioThread = true;
    }

Example sets small image size:

private int imageWidth = 320;
private int imageHeight = 240;

yeah, it would work ok.

when I set 640x480, java memory allocating is pretty big:

screenshot_8

on my phone max java heap == ~200

when I set hd (1280x720) it would fail to record almost at start:

10-06 11:09:15.726 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 0
10-06 11:09:15.731 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 1
10-06 11:09:15.732 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 2
10-06 11:09:15.732 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 3
10-06 11:09:15.732 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 4
10-06 11:09:15.733 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 5
10-06 11:09:15.733 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 6
10-06 11:09:15.736 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 7
10-06 11:09:15.736 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 8
10-06 11:09:15.736 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 9
10-06 11:09:15.737 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 10
10-06 11:09:15.737 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 11
10-06 11:09:15.741 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 12
10-06 11:09:15.742 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 13
10-06 11:09:15.742 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 14
10-06 11:09:15.743 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 15
10-06 11:09:15.743 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 16
10-06 11:09:15.743 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 17
10-06 11:09:15.744 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 18
10-06 11:09:15.744 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 19
10-06 11:09:15.744 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 20
10-06 11:09:15.745 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 21
10-06 11:09:15.745 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 22
10-06 11:09:15.745 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 23
10-06 11:09:15.745 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 24
10-06 11:09:15.745 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 25
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 26
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 27
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 28
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 29
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 30
10-06 11:09:15.746 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 31
10-06 11:09:15.747 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 32
10-06 11:09:15.749 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 33
10-06 11:09:15.749 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 34
10-06 11:09:15.749 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 35
10-06 11:09:15.757 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 36
10-06 11:09:15.757 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 37
10-06 11:09:15.758 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 38
10-06 11:09:15.759 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 39
10-06 11:09:15.761 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 40
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 41
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 42
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 43
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 44
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 45
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 46
10-06 11:09:15.762 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 47
10-06 11:09:15.763 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 48
10-06 11:09:15.763 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 49
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 50
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 51
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 52
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 53
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 54
10-06 11:09:15.764 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 55
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 56
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 57
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 58
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 59
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 60
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 61
10-06 11:09:15.765 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 62
10-06 11:09:15.766 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 63
10-06 11:09:15.768 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 64
10-06 11:09:15.769 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 65
10-06 11:09:15.769 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 66
10-06 11:09:15.769 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 67
10-06 11:09:15.770 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 68
10-06 11:09:15.770 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 69
10-06 11:09:15.770 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 70
10-06 11:09:15.771 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 71
10-06 11:09:15.771 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 72
10-06 11:09:15.771 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 73
10-06 11:09:15.771 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 74
10-06 11:09:15.772 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 75
10-06 11:09:15.772 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 76
10-06 11:09:15.772 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 77
10-06 11:09:15.773 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 78
10-06 11:09:15.773 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 79
10-06 11:09:15.773 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 80
10-06 11:09:15.773 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 81
10-06 11:09:15.774 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 82
10-06 11:09:15.775 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 83
10-06 11:09:15.775 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 84
10-06 11:09:15.776 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 85
10-06 11:09:15.776 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 86
10-06 11:09:15.776 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 87
10-06 11:09:15.777 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 88
10-06 11:09:15.777 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 89
10-06 11:09:15.777 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 90
10-06 11:09:15.777 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 91
10-06 11:09:15.778 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 92
10-06 11:09:15.778 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 93
10-06 11:09:15.778 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 94
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 95
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 96
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 97
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 98
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 99
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 100
10-06 11:09:15.779 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 101
10-06 11:09:15.780 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 102
10-06 11:09:15.780 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 103
10-06 11:09:15.780 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 104
10-06 11:09:15.780 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 105
10-06 11:09:15.780 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 106
10-06 11:09:15.783 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 107
10-06 11:09:15.784 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 108
10-06 11:09:15.784 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 109
10-06 11:09:15.784 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 110
10-06 11:09:15.785 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 111
10-06 11:09:15.785 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 112
10-06 11:09:15.785 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 113
10-06 11:09:15.785 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 114
10-06 11:09:15.785 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 115
10-06 11:09:15.786 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 116
10-06 11:09:15.786 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 117
10-06 11:09:15.786 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 118
10-06 11:09:15.787 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 119
10-06 11:09:15.787 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 120
10-06 11:09:15.787 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 121
10-06 11:09:15.787 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 122
10-06 11:09:15.787 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 123
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 124
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 125
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 126
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 127
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 128
10-06 11:09:15.788 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 129
10-06 11:09:15.789 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 130
10-06 11:09:15.789 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 131
10-06 11:09:15.789 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 132
10-06 11:09:15.789 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 133
10-06 11:09:15.790 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 134
10-06 11:09:15.790 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 135
10-06 11:09:15.790 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 136
10-06 11:09:15.790 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 137
10-06 11:09:15.790 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 138
10-06 11:09:15.791 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 139
10-06 11:09:15.791 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 140
10-06 11:09:15.791 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 141
10-06 11:09:15.791 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 142
10-06 11:09:15.791 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 143
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 144
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 145
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 146
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 147
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 148
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 149
10-06 11:09:15.792 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 150
10-06 11:09:15.793 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 151
10-06 11:09:15.793 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 152
10-06 11:09:15.794 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 153
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 154
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 155
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 156
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 157
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 158
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 159
10-06 11:09:15.795 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 160
10-06 11:09:15.796 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 161
10-06 11:09:15.796 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 162
10-06 11:09:15.796 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 163
10-06 11:09:15.796 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 164
10-06 11:09:15.796 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 165
10-06 11:09:15.797 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 166
10-06 11:09:15.797 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 167
10-06 11:09:15.797 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 168
10-06 11:09:15.798 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 169
10-06 11:09:15.798 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 170
10-06 11:09:15.800 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 171
10-06 11:09:15.801 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 172
10-06 11:09:15.801 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 173
10-06 11:09:15.801 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 174
10-06 11:09:15.801 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 175
10-06 11:09:15.801 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 176
10-06 11:09:15.802 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 177
10-06 11:09:15.802 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 178
10-06 11:09:15.802 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 179
10-06 11:09:15.802 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 180
10-06 11:09:15.803 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 181
10-06 11:09:15.803 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 182
10-06 11:09:15.803 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 183
10-06 11:09:15.803 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 184
10-06 11:09:15.803 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 185
10-06 11:09:15.804 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 186
10-06 11:09:15.804 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 187
10-06 11:09:15.804 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 188
10-06 11:09:15.805 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 189
10-06 11:09:15.805 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 190
10-06 11:09:15.805 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 191
10-06 11:09:15.805 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 192
10-06 11:09:15.805 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 193
10-06 11:09:15.806 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 194
10-06 11:09:15.806 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 195
10-06 11:09:15.806 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 196
10-06 11:09:15.806 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 197
10-06 11:09:15.807 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 198
10-06 11:09:15.808 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 199
10-06 11:09:15.808 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 200
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 201
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 202
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 203
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 204
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 205
10-06 11:09:15.809 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 206
10-06 11:09:15.810 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 207
10-06 11:09:15.810 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 208
10-06 11:09:15.810 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 209
10-06 11:09:15.810 7599-7599/test.app.com I/LOGGG: Allocating buffer for new Frame 210
10-06 11:09:15.810 7599-7599/test.app.com I/art: Waiting for a blocking GC Alloc
10-06 11:09:15.814 7599-7610/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.814 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.814 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.817 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.822 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.823 7599-7599/test.app.com I/art: Alloc partial concurrent mark sweep GC freed 7(288B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 260us total 5.133ms
10-06 11:09:15.823 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.832 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.833 7599-7599/test.app.com I/art: Alloc concurrent mark sweep GC freed 6(12KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 242us total 9.730ms
10-06 11:09:15.833 7599-7599/test.app.com I/art: Forcing collection of SoftReferences for 1800KB allocation
10-06 11:09:15.833 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.842 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.842 7599-7599/test.app.com I/art: Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 257us total 8.879ms
10-06 11:09:15.842 7599-7599/test.app.com W/art: Throwing OutOfMemoryError "Failed to allocate a 1843219 byte allocation with 212680 free bytes and 207KB until OOM"
10-06 11:09:15.842 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.842 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.846 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.851 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.851 7599-7599/test.app.com I/art: Alloc partial concurrent mark sweep GC freed 4(128B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 215us total 5.029ms
10-06 11:09:15.851 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.860 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.860 7599-7599/test.app.com I/art: Alloc concurrent mark sweep GC freed 2(64B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 184us total 8.690ms
10-06 11:09:15.860 7599-7599/test.app.com I/art: Forcing collection of SoftReferences for 1800KB allocation
10-06 11:09:15.860 7599-7599/test.app.com I/art: Starting a blocking GC Alloc
10-06 11:09:15.869 7599-7599/test.app.com I/art: Clamp target GC heap from 399MB to 384MB
10-06 11:09:15.869 7599-7599/test.app.com I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 383MB/384MB, paused 189us total 8.531ms
10-06 11:09:15.869 7599-7599/test.app.com W/art: Throwing OutOfMemoryError "Failed to allocate a 1843219 byte allocation with 212680 free bytes and 207KB until OOM"
10-06 11:09:15.869 7599-7599/test.app.com D/AndroidRuntime: Shutting down VM
10-06 11:09:15.870 7599-7599/test.app.com E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: test.app.com, PID: 7599
                                                               java.lang.OutOfMemoryError: Failed to allocate a 1843219 byte allocation with 212680 free bytes and 207KB until OOM
                                                                   at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                   at java.nio.MemoryBlock.allocate(MemoryBlock.java:131)
                                                                   at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:73)
                                                                   at org.bytedeco.javacv.Frame.<init>(Frame.java:108)
                                                                   at test.app.com.RecordActivity.initRecorder(RecordActivity.java:109)
                                                                   at test.app.com.RecordActivity.startRecording(RecordActivity.java:136)
                                                                   at test.app.com.RecordActivity.onClick(RecordActivity.java:447)
                                                                   at android.view.View.performClick(View.java:5207)
                                                                   at android.view.View$PerformClick.run(View.java:21177)
                                                                   at android.os.Handler.handleCallback(Handler.java:742)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                   at android.os.Looper.loop(Looper.java:154)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5527)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
10-06 11:09:15.872 7599-7599/test.app.com E/MQSEventManagerDelegate: failed to get MQSService.
10-06 11:09:15.891 7599-7599/test.app.com I/Process: Sending signal. PID: 7599 SIG: 9

so it just allocates too much java memory (it won't be able to record in hd quality or full hd)

In my projects I use this example of javacv ffmpeg recording for Android https://github.com/CrazyOrr/FFmpegRecorder (java ffmpegrecorder class: https://github.com/CrazyOrr/FFmpegRecorder/blob/master/app/src/main/java/com/github/crazyorr/ffmpegrecorder/FFmpegRecordActivity.java)

Earlier this example also had mem issues, but author made some fixes: CrazyOrr/FFmpegRecorder#15 (comment) (and I don't notice any quality suffering when recording hd size)

so it doesn't have problems with high java memory usage, I can record in hd or even in full hd quality without problems

though it does quite use many cpu (~25-50%) and doesn't matter which quality I set (crf, image resolution, framerate)

RecordActivity.java sample seems doesn't load cpu at all, but eats many java memory and won't be able to record with size like hd

@saudet
Copy link
Member

saudet commented Oct 7, 2017

It's possible to optimize the sample to require less memory. As usual, contributions are welcome! Let me know if you'd like to try, but are encountering any issues. Thanks

@anonym24
Copy link
Author

anonym24 commented Oct 9, 2017

I tried original CrazyOrr/FFmpegRecorder project again and it actually seems doesn't use much cpu as I thought (10-30). It's in my project cpu usage is much bigger (35-60), I have to recheck my project. For memory usage issues I guess we can use CrazyOrr/FFmpegRecorder solution, I think it works ok

@anonym24
Copy link
Author

anonym24 commented Oct 9, 2017

I just had cameraParams.setRecordingHint(true); in my project, it's of course good for recording (more smooth, better fps), but would eat our devices cpu

@saudet
Copy link
Member

saudet commented Oct 9, 2017

Sounds good! Could you update the RecordActivity sample and include the relevant additions from CrazyOrr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants