Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add mobile commands for audio recording #1207

Merged
merged 6 commits into from
May 10, 2020

Conversation

mykola-mokhnach
Copy link
Contributor

The idea of this PR is that we could record Simulator audio output using Soundflower like it is described in http://www.lorisware.com/blog/2012/04/28/recording-iphone-emulator-video-with-sound/

For real devices there is a possibility to connect a phone as an input device: https://www.makeuseof.com/tag/play-audio-iphone-mac/, although I've never tested that, since I don't have a real device :-P
In the worst case one could always use the classic audio jack connected to a microphone input of a mac machine.

The feature is insecure, because it allows to access system microphone, so it must be enabled explicitly on the server side.

I'll write a separate doc later on how to configure the Simulator for audio recording. It would be great if @KazuCocoa could help to check how audio capture works with real devices, so we have a complete documentation on the feature.

cc @dpgraham

@KazuCocoa
Copy link
Member

KazuCocoa commented May 10, 2020

$ ffmpeg -f avfoundation -list_devices true -i ""
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.3 (clang-1103.0.32.59)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[AVFoundation input device @ 0x7fd5c1e043c0] AVFoundation video devices:
[AVFoundation input device @ 0x7fd5c1e043c0] [0] FaceTime HD Camera (Built-in)
[AVFoundation input device @ 0x7fd5c1e043c0] [1] Capture screen 0
[AVFoundation input device @ 0x7fd5c1e043c0] AVFoundation audio devices:
[AVFoundation input device @ 0x7fd5c1e043c0] [0] iPhone
[AVFoundation input device @ 0x7fd5c1e043c0] [1] Built-in Microphone

When I did belw input, the input device (iPhone) was recoded

$ ffmpeg -f avfoundation -i ":0" -c:a aac -b:a 128k -ac 2 -ar 44100 ~/Desktop/test.mp4
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.3 (clang-1103.0.32.59)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags=-fno-stack-check --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, avfoundation, from ':0':
  Duration: N/A, start: 150226.979524, bitrate: 2822 kb/s
    Stream #0:0: Audio: pcm_f32le, 44100 Hz, stereo, flt, 2822 kb/s
File '/Users/kazuaki/Desktop/test.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_f32le (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to '/Users/kazuaki/Desktop/test.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.54.100 aac
size=     200kB time=00:00:22.17 bitrate=  73.9kbits/s speed=1.08x
video:0kB audio:196kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.210449%
[aac @ 0x7fcf3109c400] Qavg: 26583.854

Note: We must allow microphone permission (My case was via iTerm.app)

Copy link
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only tested ffmpeg command for a real device


const commands = {};

const AUDIO_RECORD_FEAT_NAME = 'audio_record';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!audioInput) {
log.errorAndThrow(`The mandatory audioInput option is not provided. Please set it ` +
`to a correct value (e. g. ':1'). Use 'ffmpeg -f avfoundation -list_devices true -i ""' ` +
`command to list available input sources`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to log the url, https://www.ffmpeg.org/ffmpeg-devices.html#avfoundation , for iPhone device to check the device audio input format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do log the output of ffmpeg

@mykola-mokhnach
Copy link
Contributor Author

When I did belw input, the input device (iPhone) was recoded

niiice. Many thanks for checking it

@dpgraham
Copy link
Contributor

This is awesome!

@KazuCocoa
Copy link
Member

The limitation of MIDI connect.

Probably we cannot customise the name of below iPhone name (even via Audio MIDI Setup app in macOS). I could not find the method yet.

[AVFoundation input device @ 0x7fdacf621e80] AVFoundation audio devices:
[AVFoundation input device @ 0x7fdacf621e80] [0] iPhone
[AVFoundation input device @ 0x7fdacf621e80] [1] Built-in Microphone

Haven't tested yet, but for real devices, maybe we can record audio with multiple devices if all devices appear as the result of AVFoundation audio devices. (But the listed name should be iPhone or iPhone 2 (iPhone plus number)

@mykola-mokhnach mykola-mokhnach merged commit b788efa into appium:master May 10, 2020
@mykola-mokhnach mykola-mokhnach deleted the audio_record branch May 10, 2020 14:13
khanayan123 pushed a commit to khanayan123/appium-xcuitest-driver that referenced this pull request May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants