I got the Gaurdian Project FFMPEG android java from the following link
https://github.com/guardianproject/android-ffmpeg-java
Is there any good documents available to use the library for code. Its difficult to use without documentation. Plz help me.
I managed to get it work.
First, download the guardian project ffmpeg library project:
Then import it in eclipse. (no need to follow their Build Procedure, with the NDK just import their project in eclipse directly)
Then right click on your Main project (not the library project) -> Properties -> Android -> Library -> Add
Then, use it this way :
File fileTmp = context.getActivity().getCacheDir();
File fileAppRoot = new File(context.getActivity().getApplicationInfo().dataDir);
FfmpegController fc = new FfmpegController(fileTmp, fileAppRoot);
final Clip out = new Clip("compiled.mp4");
fc.concatAndTrimFilesMP4Stream(videos, out, true, false, new ShellUtils.ShellCallback() {
#Override
public void shellOut(String shellLine) {
System.out.println("MIX> " + shellLine);
}
#Override
public void processComplete(int exitValue) {
if (exitValue != 0) {
System.err.println("concat non-zero exit: " + exitValue);
Log.d("ffmpeg","Compilation error. FFmpeg failed");
} else {
if(new File(out.path).exists()) {
Log.d("ffmpeg","Success file:"+out.path);
}
}
}
});
With an ArrayList<Clip> of videos you want to concatenate.
Related
This is my Build.gradle file:-
project.ext {
// * SWIG options *
// This and the SWIG "task" at the bottom are loosely based on:
//
// http://androiddeveloper.co.il/using-swig/
swigModuleFiles = ['yourfy.i']
swigIncludeDirs = ['src/main/cpp/yourfy/src', 'src/main/cpp/yourfy/src/nxcommon/src/libnxcommon']
swigJavaOutputDir = file("src/main/java/com/yourfy/yourfy/swig").absolutePath
swigCxxOutputDir = file("src/main/cpp/swig").absolutePath
swigModuleFilesAbs = []
swigIncludeDirOpts = []
swigCxxModuleFilesAbs = []
swigModuleFiles.each { moduleFile ->
swigModuleFilesAbs.add(file("src/main/cpp/yourfy/src/yourfy/" + moduleFile).absolutePath)
swigCxxModuleFilesAbs.add(swigCxxOutputDir + "/" + moduleFile + ".cxx")
}
swigIncludeDirs.each { incDir ->
swigIncludeDirOpts.add("-I" + file(incDir).absolutePath)
}
}
// * Generate SWIG wrappers *
// Generate .java and .cxx files for the SWIG bindings.
//
// It has to be done in Gradle (as opposed to the native library's CMakeLists.txt), because
// Gradle calls the Java implementationr BEFORE running the native build, so the .java SWIG files will
// not have been generated yet when the implementationr runs. We have to ensure that they are generated
// before the Java implementationr runs.
//
// Thanks, Gradle!
//
// I would love to do this as a task, but unfortunately, it does not work. For some reason,
// when building from Android Studio (NOT when running Gradle from command line), CMake is
// actually invoked first, before any other tasks, which means that the Gradle-generated SWIG
// CXX source files might still be missing, which CMake then complains about and aborts. For
// now, we will have to run SWIG at the top level all the time to get it working. Right now,
// it's reasonably fast to do so, let's see how long this holds.
// More info:
def swigExec = '/usr/local/bin/swig'
// TODO: Add some auto-detection
if (project.hasProperty('swig.executable')) {
swigExec = project.property('swig.executable')
}
if (swigExec != null && file(swigExec).isFile()) {
file(project.swigJavaOutputDir).mkdirs()
file(project.swigCxxOutputDir).mkdirs()
// Delete previous output files (.cxx, .h and *.java in respective directories)
(file(project.swigJavaOutputDir).listFiles() + file(project.swigCxxOutputDir).listFiles()).each { file ->
if (file.name.toLowerCase().endsWith(".cxx")
|| file.name.toLowerCase().endsWith(".h")
|| file.name.toLowerCase().endsWith(".java")
) {
file.delete()
}
}
[project.swigModuleFilesAbs, project.swigCxxModuleFilesAbs].transpose().each { moduleFile, cxxFile ->
exec {
commandLine(
swigExec,
'-java',
'-c++',
'-package', 'com.yourfy.yourfy.swig',
*project.swigIncludeDirOpts,
'-outdir', project.swigJavaOutputDir,
'-o', cxxFile,
moduleFile
)
}
}
} else {
logger.error('Property swig.executable not set or invalid! You should set it in ' +
'the gradle.properties file of your gradle user home directory, pointing to ' +
'a SWIG > 3.0 executable')
}
How to generate swig wrapper files in android?There are some links added to here but still its not figure out.
Also tried following links also mentioned in the comment:-
Stackoverflow question link
Github link
I was trying both the links but didn't understand but still seems it difficult.
I have got FFmpeg compiled (libffmpeg.so) on Android. Now I have to build either an application like RockPlayer or use existing Android multimedia framework to invoke FFmpeg along with video playing.
Do you have steps / procedures / code / example on integrating FFmpeg on Android / StageFright?
Can you please guide me on how can I use this library for multimedia
playback?
I already did rendering, mixing.
compile 'com.writingminds:FFmpegAndroid:0.3.2' add this to gradle
Add this inside onCreate :
ffmpeg = FFmpeg.getInstance(this.getApplicationContext());
(Declare FFmpeg ffmpeg; first)
Load library : loadFFMpegBinary();
Code to add audio to video using ffmpeg:
call function using execFFmpegBinaryShortest(null);
**
private void execFFmpegBinaryShortest(final String[] command) {
final File outputFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/videoaudiomerger/"+"Vid"+"output"+i1+".mp4");
String[] cmd = new String[]{"-i", selectedVideoPath,"-i",audiopath,"-map","1:a","-map","0:v","-codec","copy","-shortest",outputFile.getPath()};
try {
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
#Override
public void onFailure(String s) {
System.out.println("on failure----"+s);
}
#Override
public void onSuccess(String s) {
System.out.println("on success-----"+s);
}
#Override
public void onProgress(String s) {
//Log.d(TAG, "Started command : ffmpeg "+command);
System.out.println("Started---"+s);
}
#Override
public void onStart() {
//Log.d(TAG, "Started command : ffmpeg " + command);
System.out.println("Start----");
}
#Override
public void onFinish() {
System.out.println("Finish-----");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
System.out.println("exceptio :::"+e.getMessage());
}
}
**
Download ffmpeg from here: http://bambuser.com/opensource. It contains scripts to build ffmpeg for android.
Modify build.sh. Replace "com.bambuser.broadcaster" with your package name. You also need to set the ffmpeg flags to enable to codecs you're interested in.
Run build.sh, and copy the build/ffmpeg directory into your apps jni/lib directory.
Use fasaxc's makefile from the SO post.
Create a native.c file in your jni directory and a java wrapper. To start with you can model it after hello-jni in NDK samples (/samples/hello-jni).
Include headers in your native.c file like this: #include "libavcodec/avcodec.h". And call the functions you need: avcodec_register_all(), etc...
Include the native libraries in your root activity by adding: static { System.loadLibraries(""); }
I am making an application in Unity3D and I have a problem with the file .obb. After downloading the file .obb from my dropbox try to open the next scene and tells me I can not find it. If I close the application and return open functioning OK. What can be?
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class DownloadFile : MonoBehaviour {
private string path;
private string url = "";
private float m_CurrentValue = 0;
public GameObject btnStart;
private string nextScene = "Splash";
void log( string t )
{
print("MYLOG " + t);
}
// Use this for initialization
void Start ()
{
CheckObb ();
}
// Update is called once per frame
void Update () {
}
void CheckObb()
{
if (!GooglePlayDownloader.RunningOnAndroid())
{
log ( "Use GooglePlayDownloader only on Android device!");
return;
}
string expPath = GooglePlayDownloader.GetExpansionFilePath();
if (expPath == null)
{
log("External storage is not available!");
}
else
{
string package = GooglePlayDownloader.Package();
int version = GooglePlayDownloader.Version();
path = String.Format("{0}/main.{1}.{2}.obb", expPath, version, package);
url = String.Format("https://www.dropbox.com/s/xxxxxxxxxxxxxx/main.{0}.{1}.obb?dl=1", version, package);
if (File.Exists(path))
{
// After downloading the file if you close the game and you become open, OK ¿?
Application.LoadLevel(nextScene);
}
else
{
//check if directory doesn't exit
if(!Directory.Exists(expPath))
{
//if it doesn't, create it
Directory.CreateDirectory(expPath);
}
btnStart.SetActive(true);
}
}
}
// Click Start button download obb
public void ClickStart()
{
btnStart.SetActive(false);
StartCoroutine(DownloadObb());
}
// Download obb
IEnumerator DownloadObb() {
WWW download = new WWW(url);
while( !download.isDone ) {
m_CurrentValue = download.progress * 100;
yield return null;
}
if (!string.IsNullOrEmpty(download.error)) {
//Error
} else
{
// success!
File.WriteAllBytes (path, download.bytes);
// Here says that there is the scene
Application.LoadLevel(nextScene);
}
}
}
I tried to upload the apk and obb as alpha version in the developer console but when I go to download the .obb tells me this:
"Download failed because the resources could not be found"
Thanks.
I follow this tutorial in order to split my Unity app into *.obb file. It help me a lot.
Now, when I was performing my test in GooglePlay as an Alpha version everything goes OK, the download of the obb file and the process in the app but it doesn`t load my first scene.
It took me a lot to notice that when I put the loader as the scene 0 my index to load the next Scene was wrong. I know it is a poor error but thats the History behind my 10 hours research.
Hope you'll find useful.
Is it possible to play a sound after my app was compiled and deployed on smartphone in Android Studio / IntelliJ
My workaround is to play a sound inside of onStart() method of my StartActivity, but I have to implement (copy/paste) this pattern for every new project. Not realy nice solution.
In Android Studio, go into Preferences > Appearance & Behavior > Notifications, go down to Gradle Build (Logging) and check the Read aloud box.
This will speak Gradle build finished in x minutes and x seconds when your build is complete.
A blend of https://stackoverflow.com/a/66226491/8636969 and https://stackoverflow.com/a/63632498/8636969 that's very simple for mac:
gradle.buildFinished { BuildResult buildResult ->
try {
"afplay /System/Library/Sounds/Submarine.aiff".execute()
} catch (Throwable ignored) {}
}
in your build.gradle. This just plays the Submarine sounds everytime a build finishes.
Refer to this we need to call the task inside afterEvaluate.
And since I can't comment, I will put my working code here. This code works for windows.
You can add this to your app/.gradle file inside android{ } tag :
afterEvaluate {
gradle.buildFinished{ BuildResult buildResult ->
if (buildResult.failure) {
['powershell', """(New-Object Media.SoundPlayer "C:\\failed_notif.wav").PlaySync();"""].execute()
println("failed doing task")
} else {
['powershell', """(New-Object Media.SoundPlayer "C:\\succeed_notif.wav").PlaySync();"""].execute()
println("build finished")
}
}
}
Please note that this method can only run with .wav file. If you want to use an .mp3 you can try this.
On Windows you can do it like this (in build.gradle):
gradle.buildFinished { BuildResult buildResult ->
// Beep on finish
try {
String filename = buildResult.getFailure() ? 'Alarm10.wav' : 'Alarm02.wav'
['powershell', '-c', """(New-Object Media.SoundPlayer "C:\\Windows\\Media\\${filename}").PlaySync();"""].execute()
} catch (Throwable ignored) {}
}
On mac based on this gist and this answer to find the folder do:
Create file speak.gradle with below content inside ~/.gradle/init.d folder (if you can't find init.d folder, you can create it)
speak.gradle
// When runnning a Gradle build in the background, it is convenient to be notified immediately
// via voice once the build has finished - without having to actively switch windows to find out -
// and being told the actual exception in case of a build failure.
// Put this file into the folder ~/.gradle/init.d to enable the acoustic notifications for all builds
gradle.addBuildListener(new BuildAdapter() {
#Override
void buildFinished(BuildResult result) {
def projectName = gradle.rootProject.name
if (result.failure) {
playSound('Submarine.aiff')
def e = getExceptionParts(result)
"say '$projectName build failed: ${e.first} ${e.second}.'".execute()
} else {
if (projectName != "buildSrc") {
playSound('Glass.aiff')
"say '$projectName build successful.'".execute()
}
}
}
private Tuple2<String, String> getExceptionParts(BuildResult result) {
def exception = result.failure
if (exception.cause != null) {
exception = exception.cause
}
def className = exception.class.simpleName
def of = className.indexOf('Exception')
new Tuple2<String, String>(className.substring(0, of), className.substring(of))
}
private void playSound(def sound) {
"afplay /System/Library/Sounds/$sound".execute()
sleep(100)
}
})
you can simplify more the sound to done and fail
I am trying to unzip a folder in cordova 3.4. But haven't been successful so far. I have seen many tutorials but none of them seems to work for me. Kindly suggest me some plugin or code if you have already done this and if its working.
File is successfully getting saved using http://weblogs.asp.net/soever/cordova-file-transfer-unzip-and-present-adventures, but unzip is not working.
Here is my code, calling for unzip.
document.getElementById("btnUnzip").onclick = function() {
var that = this,
App = new DownloadApp(),
fileName = "ft-p.zip",
folderName = "content";
console.log("zip button clicked");
App.unzip(folderName, fileName,
/*success*/function() { alert("Unzipped and assigned"); },
/*fail*/function(error) { alert("Unzip failed: " + error.code); }
);
};
Thanks.