14

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 (180 seconds).

Is there any way or workaround or way by which we can increase this time limit?

silwar
  • 6,470
  • 3
  • 46
  • 66
  • What is your goal? If all you want to do is to record a video of your application, you can use https://code.google.com/p/androidscreencast/ – Skynet Feb 21 '14 at 15:52
  • The SO question you link to has nothing to do with `screenrecord`. – CommonsWare Feb 21 '14 at 15:53
  • Oh.. updated question by removing last line – silwar Feb 21 '14 at 15:54
  • @NunChai - Does this screencast link you sent record videos on actual device or desktop? Because if this works on desktop then I already have softwares for recording video. I want to record video on actual device so that I can capture smoother animation effects and can capture high quality video like adb screenrecord does – silwar Feb 21 '14 at 15:58
  • It will record whatever you do on the device to a path on the Computer, provided by you. – Skynet Feb 21 '14 at 15:59
  • Great! I will give it a try – silwar Feb 21 '14 at 16:00
  • The website for AndroidScreencast says: "Current limitations: Slow refresh rate (about 4-5 fps)" No one wants to record a screencast with such low framerates, might as well take screenshots. – Mathieu Comandon Jul 10 '15 at 21:36
  • @Mathieu Please ignore. I thought you were talking about `screenrecord`. My bad. – ADTC Jul 30 '15 at 04:28

7 Answers7

14

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...

ercan
  • 1,639
  • 1
  • 20
  • 34
  • Hi ercan, this is workaround for task I want to accomplish but it works – silwar Apr 09 '14 at 08:21
  • On mac/unix, you could then automatically stitch these files together with something like this: `mkvmerge -o sr.mp4 sr1.mp4 \+ sr2.mp4 \+ sr3.mp4`. See https://askubuntu.com/a/831883/268299 for more information. – Joshua Pinter Jul 19 '20 at 20:38
  • For MacOS you can also merge the files using QuickTime and choose the option "Edit -> Add Clip to End..." without having to install additional software – Tihomir Mateev Oct 06 '21 at 15:04
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!)

superweijiafeng
  • 559
  • 1
  • 4
  • 12
  • Have you tried put your re-compiled executable in your app's private directory, instead of copy it to /system/bin (which requires root permission I suppose)? does it still work? – yorkw Jul 03 '15 at 09:59
  • 1
    I haven't tried this. And the recompiled version of `screenrecord` has been removed for a while. So I now try to put the original `screenrecord` to /sdcard/Download, and it does work normally. You can give it a try. – superweijiafeng Jul 05 '15 at 12:48
  • This is an amazing solution! I used a [DigitalOcean](https://www.digitalocean.com) VM to compile one as per your instructions. I checked out the branch for Android 4.4.4_r1 (since that's my target device) and did a `make` then extracted the file from `/out/target/product/generic/system/bin`. If you want my version of screenrecord (records for **10 days** max - GO NUTS!), [click here](https://drive.google.com/folderview?id=0B8ueg6WQMioKdFJfNVVfRE90UGc). If you want help setting up and compiling one yourself, just ping me. – ADTC Jul 29 '15 at 17:39
  • BTW, you will need to get root access and install it in `/system/bin` (rename the old one to `screenrecold`). It doesn't work if you just copy into the phone (internal/external SD card) and try to run it as `./screenrecord` ... you will get permission errors. Also remember to `chown root:shell` and `chmod a+x` after installing in `/system/bin`. – ADTC Jul 29 '15 at 17:43
7

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

  • My version on Armv7 did not have that value as a 32 bit int, but it was in a cmp. I used Hopper Disassembler (demo) to find that place (Find > Hexa Value > b4), and replaced the cmp with a cmp that would pass the following jump. – Michaël Apr 01 '20 at 00:59
  • Awesome Michaël, you are a true hacker. What's also cool about this solution is that once you set the max time limit value to a very large number, you can always set it to a smaller number on the command line with --time-limit=n where n is whatever number of seconds you need. You can also stop it with a Ctrl-C, or kill it from within your program with a kill( pid, SIGINT); command, (where pid=screenrecorder process id). – wxWhatsHisName Apr 02 '20 at 09:46
6

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.

Community
  • 1
  • 1
Moe Be
  • 100
  • 1
  • 8
6
#!/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.

MShaffer
  • 61
  • 1
  • 2
2

Elegant solution using ffmpeg

Here is an oneliner to record screencast into a local file without time limits:

adb shell "while true; do screenrecord --output-format=h264 -; done" | ffmpeg -i - screencast.mp4

Note: ffmpeg utility required to run this command

Explanation

This command recursively runs adb shell screenrecord command, pipes the output to the ffmpeg utility, and stream the result to a file named "screencast.mp4" using h264 encoding:

landyrev
  • 143
  • 1
  • 7
1

Collecting all previous answers here to a single coherent BASH script.
ffmpeg (ffplay) is required (how to install ffmpeg)

capture-screen.sh

#!/bin/bash

set -e

# Usage:
# bash ./capture-screen.sh
# bash ./capture-screen.sh -s 192.168.1.10

ADB_FLAGS="$@"

CAPTURE_BITRATE=2000000
CAPTURE_HEIGHT=720
CAPTURE_WIDTH="$((($CAPTURE_HEIGHT / 9 * 16)))" # automatically calculate width

# this call will fail if no single device could be selected
adb ${ADB_FLAGS} shell uptime

screenStream() {
  while true; do
    adb ${ADB_FLAGS} exec-out screenrecord --output-format=h264 --bit-rate ${CAPTURE_BITRATE} --size "${CAPTURE_WIDTH}x${CAPTURE_HEIGHT}" -
  done
}

screenStream | ffplay -hide_banner -framerate 60 -framedrop -f h264 -i -

Also available as a gist

MrBar
  • 950
  • 6
  • 15