Detect when adb stops recording screen


#1

I’m using startRecordingScreen() to record devices and I want to record more than 3 minutes.
I know that adb shell screenrecord time limit is 180, max.

However, we probably can work around this, by recording one video and after that one ends, start to record again, and again… until we no longer have the need to record.

The thing is: we don’t really know when the device has stopped recording, unless we use a thread, perhaps, to count the seconds that have past since the beginning of our recording.

So it would be great to have some kind of listener to which we could subscribe to know when the recording was stopped, so we could start it again, if we wanted.

Am I making any sense and/or is this even possible?

Note: Subscriber ideia was @tfcardoso 's

Thanks


#2

Interesting proposal. I’ll check if it is possible to implement the support for such feature on Applum side.


#3

As another workaround I searched a bit and found out that using something like
adb shell "screenrecord --time-limit 180 /sdcard/testRun1.mp4; screenrecord --time-limit 180 /sdcard/testRun2.mp4"
as mentioned on: How to increase time limit of ADB screen record of Android Kitkat, would do the trick of recording 2 times x 180 seconds, meaning, in the end, 360 seconds. And on stopRecordingScreen() the String which comes with a Base64 value, would be the junction of all the videos recorded.

So, maybe even if it’s not possible to subscribe the stopRecordingScreen() event, I think it would be possible to ask for more than 180 seconds on withTimeLimit() and if so, depending on the time desired, we could do something like concatenate strings and then run the final adb command with the total amount of desired time, which would be only a “recursive” screenrecord.


#4

Would you mind to assist me with testing?


#5

#6

Sure! Should I wait for the merge on android-appium?


#7

no, you should try it right now.

Just install [email protected], replace the changed screenrecording.js file there inside appium-android-driver/lib/commands and execute gulp transpile command. After that you can start the server and it will contain the necessary changes to set the duration over 180 seconds.


#8

also, it will be necessary to install ffmpeg tool in order to merge the generated files


#9

Hi @notihs ,

Could you pls explain how did you managed to increase the video file size (more than 3.66MB)?

I’m getting an error "Encountered internal error running command: Error: Cannot read the recorded media '/sdcard/1533826793218.mp4' to the memory, because the file is too large (15.25 MB >= 3.66 MB). Try to provide a link to a remote writable location instead."

Thanks


#10

I need a bit more info to help you. Can you paste the code used to reproduce that behaviour?

Anyway, I’m using a simple startScreenRecording() with time limit only and had no problems. Sometimes I get files with 40MB or so aswell.
My guess is that you are doing something wrong :stuck_out_tongue:


#11

@mykola-mokhnach while running test cases while recording i found out 2 issues:
1 - After recording a test, “remains” of video are left., meaning that I had multiple 0:00 videos on my device
2 - Sometimes, some of the videos generated were corrupted.

I think that these 2 issues may be related, but i can’t test it right now.
Just wanted to mention it, since it could be a known issue or something of that sort.
Btw, I’m still using appium [email protected]


#12

1 - After recording a test, “remains” of video are left., meaning that I had multiple 0:00 videos on my device

These are carefully deleted with rm-f command each time the resulting recorded video is delivered to the client. Try to catch the exact scenario where you get these leftovers and analyze the server log.

2 - Sometimes, some of the videos generated were corrupted.

The resulting video is generated by ffmpeg. You could try to provide the -report option to ffmpeg command line and check its actual output. Hovewer you’ll need to modify the source code a bit in order to achieve that.


#13

@notihs - didn’t do anything special

 AndroidDriver driver = (AndroidDriver)appiumConnection.getDriver();
 driver.startRecordingScreen();
 Thread.sleep(10000);
 driver.stopRecordingScreen();

now I see that I do able to record the movie but once the “stopRecordingScreen” being executed the recorded mp4 file is being deleted from the device.

[debug] [ADB] Running ‘/sdk/platform-tools/adb -P 5037 -s HT84T1A04103 pull /sdcard/1535274660436.mp4 /var/folders/c0/yc264yk52_jb580kgkdnmjkxh3sh8r/T/appium118726-72410-1xb0c1v.zphpg.mp4’
[debug] [AndroidDriver] The size of the recent screen recording is 830.39 KB
[debug] [ADB] Running ‘/sdk/platform-tools/adb -P 5037 -s HT84T1A04103 shell rm -rf /sdcard/1535274660436.mp4’
[debug] [W3C] Responding to client with driver.stopRecordingScreen() result: "AAAAGGZ0eXBtcDQyAAAAAGlzb21tcDQyAAAMd2ZyZWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA…
[HTTP] <-- POST /wd/hub/session/df6673d5-f6f7-4463-9ad0-03c342c7d7b0/appium/stop_recording_screen 200 502 ms - 1133776

Then I cannot pull the file.

Any Idea ?


#14

OK ,

Just read the API , and saw that the stopRecord returns String (base64 encoded stream)

Just wonder why the implementation of the “CanRecordScreen” is per each drive separately and not just for AppiumDriver which being extended by the both Android and IOS drivers ?


#15

@igal_epshtein

Relating your first reply, I think you already figured it out. You just need to get the result on stopRecording() and then construct a File object with it, something like this:

AndroidDriver driver = (AndroidDriver)appiumConnection.getDriver();
(...)
base64 =driver.stopRecordingScreen();
byte[] base64Bytes = Base64.getDecoder().decode(base64);`

And then just create a file with those bytes, for example.

Relating your second reply, this occurs because some features that AndroidDriver allows you to do cannot be achieved by the iOSDriver. Why? Idk, that’s something for maybe @mykola-mokhnach to answer, but my guess it’s because iOS is a pain in the ass :stuck_out_tongue:


#16

For sure pain…

The entire code for record being duplicated.