title: Stop an Android screen recording in an automated script
body: <p>I'm building automated test scenarios in Appium (for an Android app), and am trying to figure out a way to start recording the screen during a specific moment, running some actions and then stopping the recording. </p>
  
  <p>I could not find any screen record solution implemented in Appium, but found a neat adb shell command, <code>screenrecord</code>, that does exactly what it states. Now my problem is that the only obvious ways to stop the recording are to either set the exact time limit I need in the arguments, or to press Ctrl-C in the interactive shell:</p>
  
  <pre><code>2|shell@mako:/ $ screenrecord --help
  Usage: screenrecord [options] &lt;filename&gt;
  
  Android screenrecord v1.2.  Records the device's display to a .mp4 file.
  
  Options:
  --size WIDTHxHEIGHT
      Set the video size, e.g. "1280x720".  Default is the device's main
      display resolution (if supported), 1280x720 if not.  For best results,
      use a size supported by the AVC encoder.
  --bit-rate RATE
      Set the video bit rate, in bits per second.  Value may be specified as
      bits or megabits, e.g. '4000000' is equivalent to '4M'.  Default 4Mbps.
  --bugreport
      Add additional information, such as a timestamp overlay, that is helpful
      in videos captured to illustrate bugs.
  --time-limit TIME
      Set the maximum recording time, in seconds.  Default / maximum is 180.
  --verbose
      Display interesting information on stdout.
  --help
      Show this message.
  
  Recording continues until Ctrl-C is hit or the time limit is reached.
  </code></pre>
  
  <p>I could use <code>--time-limit</code>, but then I need to estimate how long any given recording should take within the tests, the memory usage will be far from optimal, etc.</p>
  
  <p>Using Ctrl-C offers its own limitations, as it requires an interactive shell session, and my automations should include only simple shell commands:</p>
  
  <pre><code>adb -s DEVICE_UDID shell screenrecord /sdcard/Recordings/video.mp4
  </code></pre>
  
  <p>Does anyone know of a way to actively stop a recording?</p>
  
  <p>Alternatively, does anyone know of how to record the screen using Appium?</p>