7

I'm executing an adb shell call to create a new image file with ffmpeg. Currently, I save the outputted jpg of the ffmpeg conversion to the device, and then pull the file to the computer using adb pull. I'm wondering if I can cut out having to save it on the android first, and just save it directly to the computer instead.

Here is the code (essentially) I am trying to run:

adb shell "screencap | /data/local/tmp/tools/./ffmpeg -f rawvideo -vcodec mjpeg -q:v 5 -" > C:/Users/User/Desktop/new.jpg

Unfortunately, when I run this, it copies not only the output data of the ffmpeg call, but everything that would have been printed to the adb standard output. So I am left with a jpg file that has all of my image data, but with a bunch of words at the top (the output of the adb shell call).

Thank you.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
parameter
  • 894
  • 2
  • 18
  • 35

2 Answers2

3

If you know the beginning string of your jpg file you can pipe it to sed before redirecting to the file:

adb shell "screencap | /data/local/tmp/tools/./ffmpeg -f rawvideo -vcodec mjpeg -q:v 5 - | sed -n ‘/PATTERN/,$p’" > C:/Users/User/Desktop/new.jpg

Sed will match from pattern to the end of file and print only these lines to your jpg file.

R.Sicart
  • 671
  • 3
  • 10
1

If you have a grep utility for your either your Android device or your Windows host, you could pipe the output through a grep -v command and suppress the extraneous lines. To minimize the number of patterns that you'd need to supply to grep, you could set the ffmpeg logging option to quiet via -loglevel quiet.

scottt
  • 8,301
  • 1
  • 31
  • 41
  • loglevel quiet reduces the output to nothing, but the image is still not able to be opened...any suggestions? – parameter Jul 07 '14 at 16:58
  • It sounds like there's still some extra lines that will need to be filtered-out using a grep or the like. Have you inspected the resulting file to see what extra cruft is being added to the top and/or bottom? Since you're on Windows, you'll probably have to manually find and install a grep-like tool. – scottt Jul 07 '14 at 23:17
  • Possibly, but I believe this is actually the issue now. http://stackoverflow.com/questions/13578416/read-binary-stdout-data-from-adb-shell – parameter Jul 07 '14 at 23:21
  • Oh yeah. I forgot that going from Android-Linux to Windows would involve a line-endings conversion and that ADB would dutifully make the change for you. As noted in a couple of the answers to your linked S/O Q&A, fixing the line-endings on the fly is fairly easy; unfortunately it means using yet another Linux-style command line tool such as sed. – scottt Jul 07 '14 at 23:57