How to increase time limit of ADB screen record of Android Kitkat

后端 未结 5 804
北海茫月
北海茫月 2020-12-15 09:31

I was using screen record functionality of ADB to record video of my application. It is very convenient and useful. Only issue I found is maximum time limit of 3 minutes (18

相关标签:
5条回答
  • 2020-12-15 09:50

    Here's how I solved it. Make sure you backup screenrecorder some place before you go messing with it. I know that the max time is 180 seconds, and is stored in a 32-bit integer. In hex, this would be B4 00 00 00. So I loaded up screenrecorder into ghex, (my hex editor), and searched for B4 00 00 00. There were only a few candidates. On the 6th try, I found the location where the constant was stored. In my version it was at offset 0001B008. I changed the B4 to D4, which is 212 decimal, and screenrecorder ran for 3 min 32 sec. So then I changed it to 10 02 00 00, which would be 210 hex, which is 528 dec, and it ran for 8 min 48 sec. So I changed it to 10 00 01 00, which would be 10010 hex, which is 65552, and it ran... well, it's still running.

    I didn't want to mess with recompiling my OS, I just wanted to change this one constant in the screenrecorder program. So I did. You have to have root permissions to overwrite the screenrecorder, and I had to remount my system folder because it was mounted as read-only. I did that with the command: mount -o rw,remount /system

    It would have been awesome if the developers had written screenrecorder to default to 180 seconds, but allowed you to set whatever max timeout you wanted. It's an open source project. I should probably figure out how to submit a patch.

    Cheers

    0 讨论(0)
  • 2020-12-15 09:52

    On windows my trick is creating a screenrecord.bat file and running it. For 9 minutes:

    adb shell screenrecord --bit-rate 8000000 /sdcard/sr1.mp4
    adb shell screenrecord --bit-rate 8000000 /sdcard/sr2.mp4
    adb shell screenrecord --bit-rate 8000000 /sdcard/sr3.mp4
    

    Then you can merge the files with any video editing software.

    I know this is a lame solution but adb screenrecord is to blame for not allowing longer video lengths...

    0 讨论(0)
  • 2020-12-15 10:08
    #!/bin/bash 
    

    Function to keep stream going after 3mins

    screenStream() {
    while true
    do
    adb exec-out screenrecord --output-format=h264 --size 1024x768 - 
    done
    }
    

    Unique file name variable

    SecondString=$(date +%s)
    

    Display to screen

    screenStream | ffplay -framerate 30 -framedrop -bufsize 16M -
    

    Save to file

    screenStream | ffmpeg -i - -s 1024x768 -framerate 30 -bufsize 16M $SecondString.mp4
    

    #Ctrl+C to exit.

    0 讨论(0)
  • 2020-12-15 10:14

    I encounter the same problem.

    Here is my solution. Briefly speaking, it can be solved by recompiling the android source. Patients are needed.

    1, Following the instruction here https://source.android.com/source/initializing.html to initialize a build environment.

    2, Download the source code from git (Take about 1 hour with 10 M bandwidth).

    3, Modify the path_to_working_directory/frameworks/av/cmds/screenrecord/screenrecord.cpp by changing the kMaxTimeLimitSec to 7200 (means 2 hours).

    4, Compile the android (Take about 2 hours with Core i5-2500k and 8G RAM)

    5, Copy the path_to_working_directory/out/target/product/flo/system/bin/screenrecord to /system/bin in your android phone (Remember to make backup of origin screenrecord in case!)

    0 讨论(0)
  • 2020-12-15 10:14

    An alternative solution:

    adb shell "screenrecord --time-limit 5 /sdcard/testRun1.mp4; screenrecord --time-limit 5 /sdcard/testRun2.mp4"
    

    Notice the quotes and the semi-colon. The shell command is executed as a shell script on the Android device. The command above would create two mp4 files of 5 seconds each, one after the other.

    In our Jenkins test projects we do an exec step with a command like this:

    adb shell "screenrecord /sdcard/test1.mp4; screenrecord /sdcard/test2.mp4; screenrecord /sdcard/test3.mp4" & 
    

    The ampersand backgrounds the adb command to allow the rest of the test script to proceed. The command above will record up to 9 minutes.

    0 讨论(0)
提交回复
热议问题