“No system images installed for this target” even though Image is installed – Android avd

Goto sdk\system-images and open the folder of the current API you are using (eg.android-19 folder in your case). Now you’ll find a folder named ‘default’, open it and you’ll see the folder named ‘armeabi-v7a’ or which ever system image you’ve installed. Now move the folder ‘armeabi-v7a’ to the directory sdk\system-images…i.e simply out of the ‘default’ folder.

That’s it. I had the same problem and this method worked for me. 😀

Advertisements

Horizontal Progress Dialog with percentage

public class XYZ extends Activity {

public static final int DIALOG_DOWNLOAD_PROGRESS = 0;

private Button startBtn;

private ProgressDialog mProgressDialog;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

startBtn = (Button) findViewById(R.id.startBtn);

startBtn.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

startDownload();

}

});

}

private void startDownload() {

String url = http://.jpg”;

new DownloadFileAsync().execute(url);

}

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case DIALOG_DOWNLOAD_PROGRESS:

mProgressDialog = new ProgressDialog(this);

mProgressDialog.setMessage(“Downloading file..”);

mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

mProgressDialog.setCancelable(false);

mProgressDialog.show();

return mProgressDialog;

default:

returnnull;

}

}

class DownloadFileAsync extends AsyncTask<String, String, String> {

@Override

protected void onPreExecute() {

super.onPreExecute();

showDialog(DIALOG_DOWNLOAD_PROGRESS);

}

@Override

protected String doInBackground(String… aurl) {

int count;

try {

URL url = new URL(aurl[0]);

URLConnection conexion = url.openConnection();

conexion.connect();

int lenghtOfFile = conexion.getContentLength();

Log.d(“ANDRO_ASYNC”, “Lenght of file: “ + lenghtOfFile);

InputStream input = new BufferedInputStream(url.openStream());

OutputStream output = new FileOutputStream(

“/sdcard/some_photo_from_gdansk_poland.jpg”);

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {

total += count;

publishProgress(“” + (int) ((total * 100) / lenghtOfFile));

output.write(data, 0, count);

}

output.flush();

output.close();

input.close();

} catch (Exception e) {

}

returnnull;

}

protected void onProgressUpdate(String… progress) {

Log.d(“ANDRO_ASYNC”, progress[0]);

mProgressDialog.setProgress(Integer.parseInt(progress[0]));

}

@Override

protected void onPostExecute(String unused) {

dismissDialog(DIALOG_DOWNLOAD_PROGRESS);

}

}

}

FFmpeg4Android

FFmpeg4Android is a way your application can run FFmpeg commands,  only Java, no need for C code, or NDK.

FFmpeg4Android is now using FFmpeg 2.0 as its code base.

Adding FFMpeg support to your app (Full FFmpeg4Android):

Remove ffmpeg4android app from your device (if you have it installed) and remove the /sdcard/videokit folder.

Add the FFMpeg4Android project library (source code) as a new Android project.

Download the demo client source which use the FFMpeg4Android library, both are ADT projects.

Run the demo client to your device, you should be able to run the FFMpeg command and rotate the video in.mp4, the output video is /sdcard/videokit/vid_trans.mp4
Full installation document for FFmpeg4Android library and the demo client project.

Quick Overview for Adding support to your app

* Writing your own app is extremely simple, all you need is to follow the “demo client” project lead, here are the steps:

  1. Add the FFmpeg4Android library to your app.
  2. Add the service and the needed permissionsto your manifest:

<service android:name=”com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge”

android:process=”:remote”

android:exported=”true”>

<intent-filter><action android:name=”com.netcompss.ffmpeg4android.FFMpegRemoteServiceBridge”></action></intent-filter>

</service>

<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>

<uses-permission android:name=”android.permission.WAKE_LOCK” />

  1. Like in demo app, create an Activity that extends BaseWizard.

Now you can call the transcoding like this:

remoteService.setFfmpegCommand(command);

runWithCommand(command);

Command is a simple String (please note that you are responsible for the validation of this String as a valid FFmpeg command)

That’s it!

Your app has FFmpeg support

Adding FFMpeg support to your app (Direct JNI FFmpeg4Android):

Direct JNI FFmpeg4Android is the mean and lean version of FFmpeg4Android, with a few lines of code,

and call to the JNI interface.

This is the most strait forward way to go if you want maximum flexability to your app.

This way, FFmpeg commands can be called from your app, from every type of Android Object, or Java Object e.g Service, Fragment, Activity, Thread etc, simply call the JNI directly.

Another advantage is that the native interface is optimized for size and its size if around 5M inside the APK.

Download the ffmpeg4android_client_demo_native full source code from here.

 Commands Examples

This commands verified to work with FFMpeg4Android:

This are only some basic examples, a lot more is possible…

Video Compress:

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -s 160×120 -r 25 -aspect 3:4 -vcodec mpeg4 -b 2097152 -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4

 

Video Rotate (90 degrees cw):

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vf transpose=1 -s 160×120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k /sdcard/video_output/out.mp4

 

Video Crop:

ffmpeg -y -i /sdcard/videokit/short.mp4 -strict experimental -vf crop=100:100:0:0 -s 320×240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 /sdcard/videokit/out.mp4

 

Extract Picture from Video:

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -an -r 1/2 -ss 00:00:00.000 -t 00:00:03 /sdcard/videokit/filename%03d.jpg

 

Extract Sound from Video:

ffmpeg -y -i /sdcard/videokit/in.avi -strict experimental -acodec copy /sdcard/videokit/out.mp3

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vn -ar 44100 -ac 2 -ab 256k -f mp3 /sdcard/videokit/out.mp3

 

Re-encode Audio in Video:

ffmpeg -y -i /sdcard/in.mp4 -strict experimental -vcodec copy -acodec libmp3lame -ab 64k -ac 2 -b 1200000 -ar 22050 /sdcard/out.mp4

 

Change Video Resolution:

ffmpeg -y -i /sdcard/in.mp4 -strict experimental -vf transpose=3 -s 320×240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 /sdcard/out.mp4

 

Cut time segment from Video:

ffmpeg -y -i 101_0077.MP4 -strict experimental -vcodec copy -acodec copy -ss 00:00:00 -t 00:00:01 out.mp4

 

Transcode Audio:

ffmpeg -y -i /sdcard/videokit/big.wav /sdcard/videokit/small.mp3

WaterMark:

 //  test with watermark.png 128×128, add it to /sdcard/videokit/

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/in.mp4″,”-strict”,”experimental”, “-vf”, “movie=/sdcard/videokit/watermark.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]”,”-s”, “320×240″,”-r”, “30”, “-b”, “15496k”, “-vcodec”, “mpeg4″,”-ab”, “48000”, “-ac”, “2”, “-ar”, “22050”, “/sdcard/videokit/out.mp4”};

Streaming simple:

 

* note that all streaming examples will need to add internet permission to the Android project Manifest file ( <uses-permission android:name=”android.permission.INTERNET” />  )

 

// use this command on ffmpeg4android

ffmpeg -i /sdcard/videokit/2.mpg -strict experimental -f mpegts udp://192.168.0.114:8090
// You can use any player that supports streaming, on the target machine, to play the stream, in this case we used ffplay

ffplay -f mpegts -ast 1 -vst 0 -ar 48000 udp://192.168.0.114:8090

STREAM RAW VIDEO FROM CAMERA PREVIEW:

  

GETTING THE RAW STREAM FROM THE CAMERA PREVIEW:

Parameters parameters = camera.getParameters();

imageFormat = parameters.getPreviewFormat();

if (imageFormat == ImageFormat.NV21) {

Camera.Size previewSize = parameters.getPreviewSize();

frameWidth = previewSize.width;

frameHeight = previewSize.height;

Rect rect = new Rect(0, 0, frameWidth, frameHeight);

YuvImage img = new YuvImage(data, ImageFormat.NV21, frameWidth, frameHeight, null);

try {

outStream.write(data);

outStream.flush();

}

}

ENCODE AND STREAM USING FFMPEG4ANDROID: 

“ffmpeg -f rawvideo -pix_fmt nv21 -s 640×480 -r 15 -i ” + Environment.getExternalStorageDirectory().getAbsolutePath().toString() + “/yuv.data rtmp://host/stream.flv”

STREAM ON ONE DEVICE, RECEIVE A STEAM ON SECOND DEVICE AND SAVE IT:

on the first device:

ffmpeg -i /sdcard/one3.mp4 -f mpegts udp://192.168.0.107:8090

on the second device:

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “udp://192.168.0.108:8090″,”-strict”,”experimental”,”-crf”, “30”,”-preset”, “ultrafast”, “-acodec”, “aac”, “-ar”, “44100”, “-ac”, “2”, “-b:a”, “96k”, “-vcodec”, “libx264”, “-r”, “25”, “-b:v”, “500k”, “-f”, “flv”, “/sdcard/videokit/t.flv”};

* this needs internet permission in the manifest.

H264 encoding:

ffmpeg -y -i /sdcard/Video/1.MTS -strict experimental -vcodec libx264 -preset ultrafast -crf 24 /sdcard/videokit/out.mp4

ffmpeg -y -i /sdcard/videokit/m.mkv -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -sn /sdcard/videokit/m2.mkv
Subtitles:

ffmpeg -y -i /sdcard/videokit/m2.mkv -i /sdcard/videokit/in.srt -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -scodec copy /sdcard/videokit/mo.mkv

ffmpeg -y -i /sdcard/videokit/m2.mkv -i /sdcard/videokit/in.srt -strict experimental -scodec copy /sdcard/videokit/outm3.mkv
Convert Audio file to m4a
ffmpeg -i /sdcard/videokit/in.mp3 /sdcard/videokit/out.m4a

Encode h264 video and aac audio in one command
ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vcodec libx264 -crf 24 -acodec aac /sdcard/videokit/out.mkv

Vintage filter

commandStr = “ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vf curves=vintage -s 640×480 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k -vcodec mpeg4 /sdcard/videokit/curve.mp4”;

Fade in and out transition

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/in.m4v”,”-acodec”, “copy”, “-vf”, “fade=t=in:st=0:d=5, fade=t=out:st=20:d=5”, “/sdcard/videokit/out.mp4”};

Join 2 files using of the same size using filter_complex

String[] complexCommand = {“ffmpeg”,”-y”,”-i”, “/sdcard/videokit/in1.mp4”, “-i”, “/sdcard/videokit/in2.mp4”, “-strict”,”experimental”, “-filter_complex”, “[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1”, “/sdcard/videokit/out.mp4”};

// concat videos with different codecs, and different sizes, different rate (limitation, needs the same aspect on both videos):

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/in.mp4″,”-i”, “/sdcard/videokit/in.mp4″,”-strict”,”experimental”,”-filter_complex”, “[0:v]scale=w=160:h=120[v1]; [1:v]scale=w=160:h=120[v2]; [v1][0:a][v2][1:a] concat=n=2:v=1:a=1 [v] [a]”,”-map”,”[v]”,”-map”,”[a]”, “-b”, “2097k”, “-vcodec”, “mpeg4”, “/sdcard/videokit/out.mp4”};

Create a video from pictures

commandStr = “ffmpeg -y -r 1/5 -i /sdcard/videokit/pic00%d.jpg /sdcard/videokit/out.mp4”;

Advanced filtering

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/in.mp4″,”-strict”,”experimental”, “-vf”, “crop=iw/2:ih:0:0,split[tmp],pad=2*iw[left]; [tmp]hflip[right]; [left][right] overlay=W/2”, “-vb”, “20M”, “-r”, “23.956”, “/sdcard/videokit/out.mp4”};

Increase video and audio speed

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/in.mp4″,”-strict”,”experimental”, “-filter_complex”, “[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]”,”-map”,”[v]”,”-map”,”[a]”, “-b”, “2097k”,”-r”,”60″, “-vcodec”, “mpeg4”, “/sdcard/videokit/out.mp4”};

Supporting old ARM devices (ARMv5)
Regular FFmpeg4android library is complied for ARMv7 architecture which cover most devices on the market, and gives optimal performance.

In some cases you need to support old devices, and devices that do not comply to ARMv7.

In this case you can use the ARMv5 compilation.

For this reasons, We created FFmpeg4Android for old devices library, and client.

Download it from Here:
FFmpeg4Android for old devices library
FFmpeg4Android for old devices demo client
This version does not support complex filtering, and some other advanced FFmpeg capabilities, and
Its significantly slower then the main FFmpeg4Android version.

This version can support both ARMv7 and ARMv5, the device automaticly choose the best fit.
If you need only ARMv5 delete the armeabi-v7a folder from the libs directory.

libs

armeabi         -> contains libvideokit.so for ARMv5

armeabi-v7a   -> Remove this folder if you need only ARMv5

Using complex commands
A complex command is a command that contains embeded elements (in most cases it uses quotations for that.
Here is an example:
ffmpeg -i /sdcard/videokit/in.mp4 -aspect 1:1 -vf split “[main][tmp];[tmp] crop=iw/2:ih:0:0, hflip[tp],[tp] pad=2*iw[left]; [main] crop=iw/2:ih:iw/2:0[right]; [left][right] overlay=W/2” -vb 20M -r 23.956 /sdcard/videokit/outs.mp4

To set a complex command you should create a String array and use the method:
setCommandComplex()

Like this:
String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/mo.mkv”,”-strict”,”experimental”, “-vf”, “crop=iw/2:ih:0:0,split[tmp],pad=2*iw[left]; [tmp]hflip[right]; [left][right] overlay=W/2”, “-vb”, “20M”, “-r”, “23.956”, “/sdcard/videokit/out.mp4”};

setCommandComplex(complexCommand);

The internals
As mentioned before, FFmpeg4Android runs as an Android remote service, this service is actually a separate Android process, that encapsulate the FFmpeg native process, that runs directly on the device Linux.
The demo application command will convert vid.mp4 to vid_trans.mp4, it will rotate it 270 degrees, change its resolution to 320×240, change the aspect ratio to 3:4 and encode it with mpeg4 encoder, this is all with one command! (actually it does more, it defines the audio codec, and set the audio bit rate also).
This is done at the native FFmpeg level, JNI is used to make the calls from the Remote service to the native FFmpeg process.

Updates – new version – 8.0

* Version 8 is a significant upgrade, Its based on FFmpeg 2.0 and can now support much more complex commands.

Here is a command example:

String[] complexCommand = {“ffmpeg”,”-y” ,”-i”, “/sdcard/videokit/mo.mkv”,”-strict”,”experimental”, “-vf”, “crop=iw/2:ih:0:0,split[tmp],pad=2*iw[left]; [tmp]hflip[right]; [left][right] overlay=W/2”, “-vb”, “20M”, “-r”, “23.956”, “/sdcard/videokit/out.mp4”};

Updates – new version – 7.0
* Version 7 simplifies the client interface, 2 java lines of code to run transcoding via you app.

* Added simple customization options via optional commands, for example setting the notification icon.

Here are the optional commands:

setProgressDialogTitle(“Transcoding…”);

setProgressDialogMessage(” transcoding can take a few minutes”);

setNotificationIcon(R.drawable.notification_icon);

setNotificationMessage(“Demo is running…”);

setNotificationTitle(“DemoClient”);

setNotificationfinishedMessage(“Transcoding finished”);

setNotificationStoppedMessage(“Transcoding stopped”);

Using this methods from your application, you can easily and quickly change the FFmpeg4Android messages, and notifications.

Updates – new version – 6.0

* Version 6 now supports simplified library installation.

* No need for apk installation to run the demo client, simply add the FFmpeg4Android library to your project, and you are good to go.

Updates – new version – 5.0

* Version 5 now support Background processing out of the box, no need to write any code for that!

*  Version 5 has streaming support,  to stream use this command:

String command = “ffmpeg -i /sdcard/videokit/2.mpg -f mpegts udp://192.168.0.114:8090”;

To get the streamed video use this on the machine you stream to (in this case 192.168.0.114):

ffplay -f mpegts -ast 1 -vst 0 -ar 48000 udp://192.168.0.114:8090

Simplified api, all your app has to do is add the library, and with a few lines of code you have FFMpeg support

Updates – new version – 4.0

This use the latest FFmpeg stable source to date, and adds libmp3lame to support mp3 encoding, so now you can easily run commands like this:

* ffmpeg -y -i /sdcard/videokit/in.wav out.mp3

This command transcode WAV file to MP3 file

* ffmpeg -y -i /sdcard/videokit/in.mp4 -vn -ar 44100 -ac 2 -ab 192 -f mp3 /sdcard/videokit/out.mp3

This command extract mp3 sound from the input video.

How to change or clear default app settings in Android

complete action

 

Ever browsed through your Twitter feed on your device, tapped on a link, and been directed to the page via your ‘non-preferred’ browser?

Have you ever wanted to snap a picture using the hardware camera button on your device, but it keeps opening your default camera app, rather than the brand new Google Camera app you downloaded, or perhaps another third-party camera app?

There are plenty of apps in the Play Store that can be used  to “replace” functions already on your device. In order to use them properly and set them as the “default” app for the specific function they fulfill on your device, you’ll have to do some tinkering.

It isn’t tough, but some Android users have expressed frustration with the ease of setting up default apps and even completely resetting the functions. In order to help you out, I’ve set up this guide to show you how to both change default apps in Android as well as quickly wipe your previous settings.

complete action using

 

You’ve seen that before, haven’t you? It’s quite frustrating to continually tap the “just once” button, but it’s maybe even more frustrating to tap the “always,” just before you find that “perfect app” to replace the functions of the one you’d be using as your default.

So how do you go back into your settings and reset your default app?

It’s easy.

STEP ONE:

Settings

Head on over to your phone’s “Settings” app. If you don’t know where that is, you probably shouldn’t have an Android phone it’s in your app drawer. The icon looks different on different devices (depends on manufacturer, icon pack, ROM, etc.), but it shouldn’t be hard to find. With most devices, you can also swipe down from the right part of the notification area and tap on the gear icon.

STEP TWO:

Once you’re in the “Settings” app, select the “App manager” or “Apps” button. (Again, it may appear differently depending on your device.) In the picture from the last step, you’ll see the “App manager” at the bottom of the screen. This is on my HTC One (M8), so if you have an HTC phone, it should look familiar.

STEP THREE:

app manager

Once you get into the “App manager,” you’ll find that the default screen of apps is your “Downloaded” apps. If you swipe your finger to the left (again, on most devices) you’ll be able to see the apps “On SD Card,” “Running,” and “All.”

Move over to “All,” (some apps won’t appear in the other sections of the app manager, especially if they come pre-downloaded on your device) and select the app you want to clear the default settings for.

STEP FOUR:

For the sake of this guide, let’s pretend that you want to remove Firefox as the default browser on your device and set Chrome as the new default.

all apps

Tap on Firefox (or whatever app you want to remove as the default), and you’ll get a screen that looks like this near the bottom (you’ll have to scroll down a bit):

clear defaults

Tap on “Clear defaults,” and now whenever you click on a link on your phone, you will no longer go directly to Firefox by default. Now, you’ll be prompted to select a preferred application, and if you want to set a new default, just click on Chrome (or whatever other app you want to use) and select “Always.”

Unfortunately, unlike Windows (and some other operating systems), Android doesn’t let its users look at all of the default applications at once on a list. However there are some apps that exist on the Play Store that will give you that functionality.

One such app is Default App Manager Lite and another is Clear Defaults.

Default app manager

 

Get folder size Android:

public static long getFileSize( File file) {
if (file == null || !file.exists())
return 0;
if (!file.isDirectory())
return file.length();
final List<File> dirs = new LinkedList<File>();
dirs.add(file);
long result = 0;
while (!dirs.isEmpty()) {
final File dir = dirs.remove(0);
if (!dir.exists())
continue;
final File[] listFiles = dir.listFiles();
if (listFiles == null || listFiles.length == 0)
continue;
for (final File child : listFiles) {
result += child.length();
if (child.isDirectory())
dirs.add(child);
}
}
return result;
}