Camera High FPS Recording on AOSP (40 fps so far) with hax & Mp4SlowMotionMaker

I was browsing through the decompiled seccamera.jar and found this file called Mp4SlowMotionMaker.java, it includes the code to convert high fps videos to slowmo videos.

I have made an app for it. which I have included the eclipse project from.



With a max of 30fps (or actually more like 20fps) its no use, so I did some small tweaks here and there and the result is constant 40fps video on 1920x1080 (buggy though)), I will try to get higher. but when having 40fps and the converting with timescale 1.3 or 1.5 its a nice "fast" slomo video.



What i have done is editing the camera app like this:

 
Code:
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index ed6e853..a2a377f 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -63,6 +63,7 @@
     for time lapse recording -->
     <string-array name="pref_video_time_lapse_frame_interval_entryvalues" trans
         <item>0</item>
+        <item>25</item>
         <item>500</item>
         <item>1000</item>
         <item>1500</item>
@@ -108,6 +109,7 @@
     different units (i.e. seconds, minutes, hours) for time lapse recording -->
     <string-array name="pref_video_time_lapse_frame_interval_entries">
         <item>@string/pref_video_time_lapse_frame_interval_off</item>
+        <item>@string/pref_video_time_lapse_frame_interval_25</item>
         <item>@string/pref_video_time_lapse_frame_interval_500</item>
         <item>@string/pref_video_time_lapse_frame_interval_1000</item>
         <item>@string/pref_video_time_lapse_frame_interval_1500</item>
@@ -152,6 +154,7 @@
     <!-- These values correspond to the time interval between frame capture
     for time lapse recording -->
     <string-array name="pref_video_time_lapse_frame_interval_duration_values" t
+       <item>0.025</item>
         <item>0.5</item>
         <item>1</item>
         <item>1.5</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index dc23bc1..e55cdb2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -252,6 +252,7 @@
     time lapse recording. Appears at top of the dialog. [CHAR LIMIT=30] -->
     <string name="pref_video_time_lapse_frame_interval_title">Time lapse</strin
     <string name="pref_video_time_lapse_frame_interval_default" translatable="f
+    <string name="pref_video_time_lapse_frame_interval_25">25ms</string>
 
     <!-- Settings screen, Camera setting category title -->
     <string name="pref_camera_settings_category">Camera settings</string>

This will make time lapse mode record in 40fps (1000ms / 25ms = 40fps)


And another patch in libstagefright, this was needed because libstagefright forced an error when exceeding range of 15,30
 
Code:
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/Camera
index 295c0f5..a899855 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -356,8 +356,7 @@ status_t CameraSource::configureCamera(
 
     if (frameRate != -1) {
         CHECK(frameRate > 0 && frameRate <= 120);
-        const char* supportedFrameRates =
-                params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES
+        const char* supportedFrameRates = "15,40";
         CHECK(supportedFrameRates != NULL);
         ALOGV("Supported frame rates: %s", supportedFrameRates);
         char buf[4];
@@ -365,7 +364,7 @@ status_t CameraSource::configureCamera(
         if (strstr(supportedFrameRates, buf) == NULL) {
             ALOGE("Requested frame rate (%d) is not supported: %s",
                 frameRate, supportedFrameRates);
-            return BAD_VALUE;
+//            return BAD_VALUE;
         }
 
         // The frame rate is supported, set the camera to the requested value.




and this patch to media_profiles.xml
 
Code:
diff --git a/media/media_profiles.xml b/media/media_profiles.xml
index 499e1fd..62098ec 100644
--- a/media/media_profiles.xml
+++ b/media/media_profiles.xml
@@ -191,12 +191,12 @@
              channels="1" />
     </EncoderProfile>
 
-    <EncoderProfile quality="timelapsehigh" fileFormat="mp4" duration="30">
+    <EncoderProfile quality="timelapsehigh" fileFormat="mp4" duration="40">
       <Video codec="h264"
-             bitRate="17000000"
-             width="1920"
-             height="1080"
-             frameRate="30" />
+             bitRate="15000000"
+             width="1280"
+             height="720"
+             frameRate="40" />
 
       <!--
             The Audio part of the profile will not be used since time lapse mod
@@ -261,10 +261,10 @@
 
     <EncoderProfile quality="timelapse720p" fileFormat="mp4" duration="30">
       <Video codec="h264"
-             bitRate="12000000"
-             width="1280"
-             height="720"
-             frameRate="30" />
+             bitRate="17000000"
+             width="1920"
+             height="1080"
+             frameRate="40" />
 
       <!--
             The Audio part of the profile will not be used since time lapse mod
@@ -281,7 +281,7 @@
              bitRate="17000000"
              width="1920"
              height="1080"
-             frameRate="30" />
+             frameRate="40" />
 
       <!--
             The Audio part of the profile will not be used since time lapse mod
@@ -468,10 +468,10 @@
 
     <EncoderProfile quality="timelapse720p" fileFormat="mp4" duration="30">
       <Video codec="h264"
-             bitRate="12000000"
-             width="1280"
-             height="720"
-             frameRate="30" />
+             bitRate="17000000"
+             width="1920"
+             height="1080"
+             frameRate="40" />
 
        <!--
              The Audio part of the profile will not be used since time lapse mo
@@ -483,12 +483,12 @@
              channels="1" />
     </EncoderProfile>
 
-    <EncoderProfile quality="timelapse1080p" fileFormat="mp4" duration="30">
+    <EncoderProfile quality="timelapse1080p" fileFormat="mp4" duration="40">
       <Video codec="h264"
              bitRate="17000000"
              width="1920"
              height="1080"
-             frameRate="30" />
+             frameRate="40" />
 
        <!--
              The Audio part of the profile will not be used since time lapse mo
@@ -519,7 +519,7 @@
         minBitRate="64000" maxBitRate="20000000"
         minFrameWidth="176" maxFrameWidth="1920"
         minFrameHeight="144" maxFrameHeight="1080"
-        minFrameRate="1" maxFrameRate="30" />
+        minFrameRate="1" maxFrameRate="40" />
 
     <VideoEncoderCap name="h263" enabled="true"
         minBitRate="64000" maxBitRate="1000000"


mare sure not to use h264 but mp4 because else base levels gets too high and it will crash before recording, with mp4 codec it will crash after recording which doesnt seem to affect the output
Attached Files
File Type: zip mp4slomomaker-eclipse.zip - [Click for QR Code] (1.47 MB, 41 views)
Device: Samsung Galaxy S4 (i9505)

Latest Development:
 

Roms:
AOSP v4.4.4 (KTU84P) from source for I9505 (Github)
- Cleanest ROM available for i9505. along with up-to-date stock kernel, also forms a perfect base for ROM developers.

Apps:
Galaxy S4 Glove Mode App (Playstore link)
- Do you want the Glove Mode of the S4 but your ROM doesn't support it? Use this app to enable/disable it easily.

Latest Scraps:
Proprietary Lib Cleaner / Silent proprietary libs / Live Thermal Monitor / GIT Conflict Fixer

Projects in development:
 

broodROM KitKat "Aiming for perfection"
- Custom ROM with really high standards, more info soon

For sources you can visit my Github. Or take a look at all my projects