
Recherche avancée
Médias (91)
-
DJ Z-trip - Victory Lap : The Obama Mix Pt. 2
15 septembre 2011
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Matmos - Action at a Distance
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
DJ Dolores - Oslodum 2004 (includes (cc) sample of “Oslodum” by Gilberto Gil)
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Danger Mouse & Jemini - What U Sittin’ On ? (starring Cee Lo and Tha Alkaholiks)
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Cornelius - Wataridori 2
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
The Rapture - Sister Saviour (Blackstrobe Remix)
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
Autres articles (11)
-
Soumettre améliorations et plugins supplémentaires
10 avril 2011Si vous avez développé une nouvelle extension permettant d’ajouter une ou plusieurs fonctionnalités utiles à MediaSPIP, faites le nous savoir et son intégration dans la distribution officielle sera envisagée.
Vous pouvez utiliser la liste de discussion de développement afin de le faire savoir ou demander de l’aide quant à la réalisation de ce plugin. MediaSPIP étant basé sur SPIP, il est également possible d’utiliser le liste de discussion SPIP-zone de SPIP pour (...) -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Sélection de projets utilisant MediaSPIP
29 avril 2011, parLes exemples cités ci-dessous sont des éléments représentatifs d’usages spécifiques de MediaSPIP pour certains projets.
Vous pensez avoir un site "remarquable" réalisé avec MediaSPIP ? Faites le nous savoir ici.
Ferme MediaSPIP @ Infini
L’Association Infini développe des activités d’accueil, de point d’accès internet, de formation, de conduite de projets innovants dans le domaine des Technologies de l’Information et de la Communication, et l’hébergement de sites. Elle joue en la matière un rôle unique (...)
Sur d’autres sites (7292)
-
Android : FFMpeg video creation crashes with no exception in lower APIs (18 in my case)
28 avril 2019, par Diego PerezI have an app that uses FFMpeg for video creation (these next lines are the relevant build.gradle plugin files) :
//writingminds
api 'com.writingminds:FFmpegAndroid:0.3.2'
//JavaCV video
api group: 'org.bytedeco', name: 'javacv', version: '1.4.4'
api group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '4.0.1-1.4.4', classifier: 'android-arm'
api group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '4.1-1.4.4', classifier: 'android-arm'And my app is working (and creating video) just fine in my phone with a newer Android 8 version but I’m having weird problems in my old API 18 tablet (where, as a note, I had to install multidex).
These next lines are the main part of FFMpeg video creation, where binaries are loaded, and, in fact, binaries load are where app crashes in my old tablet in the line "ffmpeg.loadBinary(new LoadBinaryResponseHandler()..."
As you can see, I have a try/catch where the app crashes, but it crashes with no exception, as catch blocks are never hit.
public static String recordVideo(JSONObject objJSON) {
String strReturn = Enum.Result.OK;
try {
fileName = objJSON.has("file_name") ? String.valueOf(objJSON.getString("file_name")) : "";
videoPath = objJSON.has("video_path") ? String.valueOf(objJSON.getString("video_path")) : "";
} catch (JSONException e) {
ExceptionHandler.logException(e);
}
FFmpeg ffmpeg = FFmpeg.getInstance(ApplicationContext.get());
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onFailure() {}
@Override
public void onSuccess() {}
@Override
public void onFinish() {}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
} catch (Exception e) {
}
...These next lines are the relevant part of the LogCat, but I cannot figure out where the problem resides, maybe an out of memory problem ?
Any help will be much appreciated.
04-28 21:44:45.873 13743-13964/com.artandwords.thoughtoftheday A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 13964 (AsyncTask #4)
04-28 21:44:45.973 144-144/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-28 21:44:45.983 144-144/? I/DEBUG: Build fingerprint: 'asus/WW_epad/ME302C:4.3/JSS15Q/WW_epad-V5.0.21-20140701:user/release-keys'
04-28 21:44:45.983 144-144/? I/DEBUG: Revision: '0'
04-28 21:44:45.983 144-144/? I/DEBUG: pid: 13743, tid: 13964, name: AsyncTask #4 >>> com.artandwords.thoughtoftheday <<<
04-28 21:44:45.983 144-144/? I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
04-28 21:44:46.003 144-144/? I/DEBUG: eax 00000000 ebx 000000c6 ecx 00000000 edx 00000000
04-28 21:44:46.003 144-144/? I/DEBUG: esi 00000e59 edi 00000000
04-28 21:44:46.003 144-144/? I/DEBUG: xcs 00000073 xds 0000007b xes 0000007b xfs 00000043 xss 0000007b
04-28 21:44:46.003 144-144/? I/DEBUG: eip 784ed378 ebp 2200ff0c esp 2200fec4 flags 00210246
04-28 21:44:46.003 144-144/? I/DEBUG: backtrace:
04-28 21:44:46.003 144-144/? I/DEBUG: #00 pc 00087378 /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #01 pc 00085d0e /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #02 pc 00073328 /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #03 pc 0006f7ff /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #04 pc 0006f3bf /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #05 pc 000b92de /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.003 144-144/? I/DEBUG: #06 pc ffffffff <unknown>
04-28 21:44:46.003 144-144/? I/DEBUG: #07 pc 001445aa /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.013 144-144/? I/DEBUG: stack:
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436850 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436854 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436858 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b43685c 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436860 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436864 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436868 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b43686c 3822676c /system/lib/arm/libc.so
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436870 7b436a98
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436874 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436878 7b4368c8
04-28 21:44:46.013 144-144/? I/DEBUG: 7b43687c 7b436a98
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436880 383003a0 /system/lib/arm/libdl.so
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436884 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436888 7b4368c8
04-28 21:44:46.013 144-144/? I/DEBUG: 7b43688c 785aa5ab /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.013 144-144/? I/DEBUG: #07 7b436890 7b4368a0
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436894 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b436898 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b43689c 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368a0 7b4368c8
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368a4 7b436890
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368a8 785aa59d /system/lib/libhoudini.so.3.4.7.44914
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368ac 7b436a98
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368b0 7b437930
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368b4 220001d0
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368b8 7b436a70
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368bc 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368c0 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368c4 00000000
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368c8 7b436a88
04-28 21:44:46.013 144-144/? I/DEBUG: 7b4368cc 785f3141 /system/lib/libhoudini.so.3.4.7.44914
--------- beginning of /dev/log/system
04-28 21:44:46.063 450-470/? I/BootReceiver: Copying /data/tombstones/tombstone_03 to DropBox (SYSTEM_TOMBSTONE)
04-28 21:44:46.063 450-13973/? W/ActivityManager: Force finishing activity com.artandwords.thoughtoftheday/.activities.DisplayThoughtActivity
04-28 21:44:46.073 145-862/? E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 75
04-28 21:44:46.093 450-13973/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
04-28 21:44:46.093 450-483/? W/InputDispatcher: channel '21edd9e8 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.main.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
04-28 21:44:46.093 450-483/? E/InputDispatcher: channel '21edd9e8 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.main.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
04-28 21:44:46.093 155-13945/? W/TimedEventQueue: Event 25 was not found in the queue, already cancelled?
04-28 21:44:46.093 155-3134/? W/AudioFlinger: session id 324 not found for pid 155
04-28 21:44:46.103 450-450/? W/InputDispatcher: Attempted to unregister already unregistered input channel '21edd9e8 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.main.MainActivity (server)'
04-28 21:44:46.103 450-755/? I/WindowState: WIN DEATH: Window{21b33a28 u0 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.DisplayThoughtActivity}
04-28 21:44:46.103 450-13973/? W/ActivityManager: Exception thrown during pause
android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:642)
at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:1007)
at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:3905)
at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:3837)
at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:8588)
at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:8465)
at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:9170)
at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:8699)
at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
04-28 21:44:46.103 450-450/? I/WindowState: WIN DEATH: Window{21edd9e8 u0 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.main.MainActivity}
04-28 21:44:46.103 450-636/? I/WindowState: WIN DEATH: Window{21be0690 u0 com.artandwords.thoughtoftheday/com.artandwords.thoughtoftheday.activities.DisplayThoughtActivity}
04-28 21:44:46.113 450-13973/? I/WindowManager: computeScreenConfigurationLocked() Enter {1.15 ?mcc?mnc ?locale ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
04-28 21:44:46.113 450-13973/? I/WindowManager: dw=1200, dh=1920
04-28 21:44:46.113 450-13973/? I/WindowManager: appWidth=1200, appHeight=1848
04-28 21:44:46.113 450-13973/? I/WindowManager: tempdm=DisplayMetrics{density=1.5, width=1200, height=1848, scaledDensity=1.5, xdpi=221.201, ydpi=220.591}
04-28 21:44:46.113 450-13973/? I/WindowManager: dm=DisplayMetrics{density=1.5, width=1200, height=1848, scaledDensity=1.5, xdpi=221.201, ydpi=220.591}, ro.product.device=ME302C
04-28 21:44:46.113 450-13973/? I/WindowManager: getConfigDisplayWidth=1200, getConfigDisplayHeight=1810
04-28 21:44:46.113 450-13973/? I/WindowManager: screenWidthDp=800, screenHeightDp=1206
04-28 21:44:46.113 450-13973/? I/WindowManager: computeScreenConfigurationLocked() Leave {1.15 ?mcc?mnc ?locale ?layoutDir sw800dp w800dp h1206dp 240dpi xlrg port ?uimode ?night finger -keyb/v/h -nav/h}
04-28 21:44:46.113 450-13973/? I/ActivityManager: Restarting because process died: ActivityRecord{21ab1f80 u0 com.artandwords.thoughtoftheday/.activities.main.MainActivity}
04-28 21:44:46.113 450-13973/? W/ActivityManager: Exception when starting activity com.artandwords.thoughtoftheday/.activities.main.MainActivity
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.app.ApplicationThreadProxy.scheduleLaunchActivity(ApplicationThreadNative.java:730)
at com.android.server.am.ActivityStack.realStartActivityLocked(ActivityStack.java:733)
at com.android.server.am.ActivityStack.startSpecificActivityLocked(ActivityStack.java:840)
at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1790)
at com.android.server.am.ActivityStack.resumeTopActivityLocked(ActivityStack.java:1449)
at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:1058)
at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:3905)
at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:3837)
at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:8588)
at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:8465)
at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:9170)
at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:8699)
at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
04-28 21:44:46.123 450-13973/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1396 com.android.server.am.ActivityStack.sendActivityBroadcastLocked:4923 com.android.server.am.ActivityStack.removeActivityFromHistoryLocked:4089 com.android.server.am.ActivityStack.removeHistoryRecordsForAppLocked:4346 com.android.server.am.ActivityManagerService.handleAppDiedLocked:3163
04-28 21:44:46.123 450-13973/? I/ActivityManager: Start proc com.artandwords.thoughtoftheday for activity com.artandwords.thoughtoftheday/.activities.main.MainActivity: pid=13975
</unknown>Edit 1 :
Still investigating and entered FFmpeg.java to the method loadBinary while debugging, which code I’ll paste below and the line making the crash is switch (CpuArchHelper.getCpuArch())
@Override
public void loadBinary(FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler) throws FFmpegNotSupportedException
String cpuArchNameFromAssets = null ;
switch (CpuArchHelper.getCpuArch())
case x86 :
Log.i("Loading FFmpeg for x86 CPU") ;
cpuArchNameFromAssets = "x86" ;
break ;
case ARMv7 :
Log.i("Loading FFmpeg for armv7 CPU") ;
cpuArchNameFromAssets = "armeabi-v7a" ;
break ;
case NONE :
throw new FFmpegNotSupportedException("Device not supported") ;
if (!TextUtils.isEmpty(cpuArchNameFromAssets)) {
ffmpegLoadLibraryAsyncTask = new FFmpegLoadLibraryAsyncTask(context, cpuArchNameFromAssets, ffmpegLoadBinaryResponseHandler);
ffmpegLoadLibraryAsyncTask.execute();
} else {
throw new FFmpegNotSupportedException("Device not supported");
}I’ll keep on investigating...
Edit 2 :
Further debugging has just lead me to the exact line where app crashes, and it’s CpuArchHelper.java from FFmpeg library :
The line causing the crash is the next :
String archInfo = cpuNativeArchHelper.cpuArchFromJNI();
and I cannot even go inside cpuArchFromJNI() with F7 as it just crashes.
package com.github.hiteshsondhi88.libffmpeg;
import android.os.Build;
class CpuArchHelper {
static CpuArch getCpuArch() {
Log.d("Build.CPU_ABI : " + Build.CPU_ABI);
// check if device is x86 or x86_64
if (Build.CPU_ABI.equals(getx86CpuAbi()) || Build.CPU_ABI.equals(getx86_64CpuAbi())) {
return CpuArch.x86;
} else {
// check if device is armeabi
if (Build.CPU_ABI.equals(getArmeabiv7CpuAbi())) {
ArmArchHelper cpuNativeArchHelper = new ArmArchHelper();
String archInfo = cpuNativeArchHelper.cpuArchFromJNI();
// check if device is arm v7
if (cpuNativeArchHelper.isARM_v7_CPU(archInfo)) {
// check if device is neon
return CpuArch.ARMv7;
}
// check if device is arm64 which is supported by ARMV7
} else if (Build.CPU_ABI.equals(getArm64CpuAbi())) {
return CpuArch.ARMv7;
}
}
return CpuArch.NONE;
}
static String getx86CpuAbi() {
return "x86";
}
static String getx86_64CpuAbi() {
return "x86_64";
}
static String getArm64CpuAbi() {
return "arm64-v8a";
}
static String getArmeabiv7CpuAbi() {
return "armeabi-v7a";
}
}This is ArmArchHelper.java class :
package com.github.hiteshsondhi88.libffmpeg;
class ArmArchHelper {
static {
System.loadLibrary("ARM_ARCH");
}
native String cpuArchFromJNI();
boolean isARM_v7_CPU(String cpuInfoString) {
return cpuInfoString.contains("v7");
}
boolean isNeonSupported(String cpuInfoString) {
// check cpu arch for loading correct ffmpeg lib
return cpuInfoString.contains("-neon");
}
} -
Android merging PCM and MP3 into AAC
4 février 2019, par katarotyI have a program that records user input sound as
PCM
(I needed to do it separately to "play" with the voice) and then I also have a custom audio track, which is inMP3
format, that I want merge with thePCM
file.To start off I convert both of them to
WAV
separately, then I combine the 2WAV
files, and finally convert the result toAAC
because I also need to merge the audio with video later.I tried merging 2
AAC
files, but that did not work out for me.For audio conversion I am using FFmpeg-Android.
The problem is that it takes way too long, around 1-2min to do the whole conversion and because of that I need a new way to do it all. I have looked into other libraries but this was the only one I could get to work.
Can someone recommend something that would do the whole process faster ?
Here is my code to merge all of the files :
public class AudioProcessor {
private Context context;
private FFmpeg ffmpeg;
private AudioProcessorListener listener;
private File micPcmFile;
private File backgroundMp3File;
private File pcmtowavTempFile;
private File mp3towavTempFile;
private File combinedwavTempFile;
private File outputFile;
private File volumeChangedTempFile;
private FFtask currentTask;
private int videoRecordingLength = 0;
TextView extensionDownload, percentProgress;
private static final String TAG = "FFMPEG AV Processor";
public AudioProcessor(Context context, Activity activity) {
ffmpeg = null;
ffmpeg = FFmpeg.getInstance(context);
percentProgress = activity.findViewById(R.id.percentProgress);
percentProgress.setSingleLine(false);
this.context = context;
prepare();
}
/**
* Program main method. Starts running program
* @throws Exception
*/
public void process() throws Exception {
if (!ffmpeg.isSupported()) {
Log.e(TAG, "FFMPEG not supported! Cannot convert audio!");
throw new RuntimeException("FFMPeg has to be supported");
}
if (!checkIfAllFilesPresent()) {
Log.e(TAG, "All files are not set yet. Please set file first");
throw new RuntimeException("Files are not set!");
}
Log.e(TAG, "Start processing audio!");
listener.onStart();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
convertPCMToWav();
}
}, 200);
}
/**
* Prepares program
*/
private void prepare() {
Log.d(TAG, "Preparing everything...");
prepareTempFiles();
}
/**
* Converts PCM to wav file. Automatically create new file.
*/
private void convertPCMToWav() {
Log.d(TAG, "Convert PCM TO Wav");
//ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
String[] cmd = { "-f" , "s16le", "-ar", "44.1k", "-i", micPcmFile.toString(), "-y", pcmtowavTempFile.toString()};
currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setVisibility(View.VISIBLE);
percentProgress.setText("Converting your recording\n"+"1/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
convertMP3ToWav();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
convertPCMToWav();
}
});
}
/**
* Converts mp3 file to wav file.
* Automatically creates Wav file
*/
private void convertMP3ToWav() {
Log.e(TAG, "Convert MP3 TO Wav");
//ffmpeg -ss 0 -t 30 -i file.mp3 file.wav
//String[] cmd = { "-ss", "0", "-t", Integer.toString(videoRecordingLength), "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
String[] cmd = { "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Converting background audio\n"+"2/5");
Log.d(TAG, "Convert MP3 TO Wav");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
changeMicAudio();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
Log.e(TAG, "Failed to convert MP3 TO Wav");
onError(message);
throw new RuntimeException("Failed to convert MP3 TO Wav");
}
});
}
/**
* Combines 2 wav files into one wav file. Overlays audio
*/
private void combineWavs() {
Log.e(TAG, "Combine wavs");
//ffmpeg -i C:\Users\VR1\Desktop\_mp3.wav -i C:\Users\VR1\Desktop\_pcm.wav -filter_complex amix=inputs=2:duration=first:dropout_transition=3 C:\Users\VR1\Desktop\out.wav
String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", volumeChangedTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", "-y",combinedwavTempFile.toString()};
currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Combining the two audio files\n"+"4/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
encodeWavToAAC();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
}
});
}
private void changeMicAudio(){
Log.e(TAG, "Change audio volume");
//ffmpeg -i input.wav -filter:a "volume=1.5" output.wav
String[] cmdy = { "-i", mp3towavTempFile.toString(), "-af", "volume=0.9", "-y",volumeChangedTempFile.toString()};
currentTask = ffmpeg.execute(cmdy, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Normalizing volume\n"+"3/5");
}
@Override
public void onSuccess(String message) {
combineWavs();
super.onSuccess(message);
}
@Override
public void onFailure(String message) {
super.onFailure(message);
Log.e("AudioProcessor", message);
}
});
}
/**
* Do something on error. Releases program data (deletes files)
* @param message
*/
private void onError(String message) {
completed();
if (listener != null) {
//listener.onError(message);
}
}
/**
* Encode to AAC
*/
private void encodeWavToAAC() {
Log.d(TAG, "Encode Wav file to AAC");
//ffmpeg -i file.wav -c:a aac -b:a 128k -f adts output.m4a
String[] cmd = { "-i" , combinedwavTempFile.toString(), "-c:a", "aac", "-b:a", "128k", "-f", "adts", "-y",outputFile.toString()};
currentTask = ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Normalizing volume\n"+"3/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
if (listener != null) {
listener.onSuccess(outputFile);
}
completed();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
encodeWavToAAC();
}
});
}
/**
* Uninitializes class
*/
private void completed() {
if (listener != null) {
listener.onFinish();
}
Log.d(TAG, "Process completed successfully!");
destroyTempFiles();
}
/**
* Prepares temp required files by deleteing them if they exsist.
* Files cannot exists before ffmpeg actions. FFMpeg automatically creates those files.
*/
private void prepareTempFiles() {
Log.d(TAG, "Preparing Temp files...");
pcmtowavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_pcm.wav");
mp3towavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_mp3.wav");
combinedwavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_combined.wav");
volumeChangedTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_volumeChanged.wav");
}
/**
* Destroys temp required files
*/
private void destroyTempFiles() {
Log.d(TAG, "Destroying Temp files...");
pcmtowavTempFile.delete();
mp3towavTempFile.delete();
combinedwavTempFile.delete();
volumeChangedTempFile.delete();
Log.d(TAG, "Destroying files completed!");
}
/**
* Checks if all files are set, so we can process them
* @return - all files ready
*/
private boolean checkIfAllFilesPresent() {
if(micPcmFile == null || backgroundMp3File == null || outputFile == null) {
Log.e(TAG, "All files are not set! Set all files!");
throw new RuntimeException("Output file is not present!");
}
Log.d(TAG, "All files are present!");
return true;
}
public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
public void setListener(AudioProcessorListener listener) {
this.listener = listener;
}
public void setMicPcmFile(File micPcmFile) {
this.micPcmFile = micPcmFile;
}
public void setBackgroundMp3File(File backgroundMp3File) {
this.backgroundMp3File = backgroundMp3File;
}
public void setVideoRecordingLength(int seconds) {
this.videoRecordingLength = seconds;
}
/**
* Quits current processing ffmpeg task
*/
public void killCurrentTask() {
if (currentTask != null) {
currentTask.killRunningProcess();
}
}
public interface AudioProcessorListener {
void onStart();
void onSuccess(File output);
void onError(String message);
void onFinish();
}
} -
FFmpeg Processes keep running even after finishAndRemoveTask()
9 octobre 2018, par katarotyI have a program that gets
Audio files
and converts them usingBravobit FFmpeg
Bravobit FFmpeg github.It works as intended until someone minimizes screen during the convertion process. I am trying to fix that but so far I have not been successful.
This part is in the
Main Activity
that creates and starts myAudioProcessor
:AudioProcessor ac = new AudioProcessor(getApplicationContext(), PostNewActivity.this);
ac.setBackgroundMp3File(backgroundAudio);
ac.setMicPcmFile(micOutputPCM);
ac.setOutputFile(tempOutFile);
ac.setListener(new AudioProcessor.AudioProcessorListener() {
public void onStart() {
Log.d("Audioprocessor", "Audioprocessor is successful");
}
public void onSuccess(File output) {
Log.d("Audioprocessor", "Audioprocessor is successful");
goToPublishView();
}
public void onError(String message) {
System.out.println("Audioprocessor: " + message);
}
public void onFinish() {
Log.d("Audioprocessor", "Audioprocessor is finshed");
}
});
try {
if (tempOutFile.exists()) {
tempOutFile.delete();
}
ac.process();
} catch (Exception ex) {
System.out.println("Processing failed!");
ex.printStackTrace();
}And here is the
AudioProcessor
itself :public class AudioProcessor {
private Context context;
private FFmpeg ffmpeg;
private AudioProcessorListener listener;
private File micPcmFile;
private File backgroundMp3File;
private File pcmtowavTempFile;
private File mp3towavTempFile;
private File combinedwavTempFile;
private File outputFile;
private File volumeChangedTempFile;
TextView extensionDownload, percentProgress;
public AudioProcessor(Context context, Activity activity) {
ffmpeg = null;
ffmpeg = FFmpeg.getInstance(context);
percentProgress = activity.findViewById(R.id.percentProgress);
percentProgress.setSingleLine(false);
this.context = context;
prepare();
}
/**
* Program main method. Starts running program
* @throws Exception
*/
public void process() throws Exception {
if (!ffmpeg.isSupported()) {
Log.e("AudioProcessor", "FFMPEG not supported! Cannot convert audio!");
throw new Exception("FFMPeg has to be supported");
}
if (!checkIfAllFilesPresent()) {
Log.e("AudioProcessor", "All files are not set yet. Please set file first");
throw new Exception("Files are not set!");
}
Log.e("AudioProcessor", "Start processing audio");
listener.onStart();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
convertPCMToWav();
}
}, 200);
}
/**
* Prepares program
*/
private void prepare() {
prepareTempFiles();
}
/**
* Converts PCM to wav file. Automatically create new file.
*/
private void convertPCMToWav() {
Log.e("AudioProcessor", "Convert PCM TO Wav");
//ffmpeg -f s16le -ar 44.1k -ac 2 -i file.pcm file.wav
String[] cmd = { "-f" , "s16le", "-ar", "44.1k", "-i", micPcmFile.toString(), "-y", pcmtowavTempFile.toString()};
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setVisibility(View.VISIBLE);
percentProgress.setText("Converting your recording\n"+"1/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
convertMP3ToWav();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
convertPCMToWav();
}
});
}
/**
* Converts mp3 file to wav file.
* Automatically creates Wav file
*/
private void convertMP3ToWav() {
Log.e("AudioProcessor", "Convert MP3 TO Wav");
//ffmpeg -i file.mp3 file.wav
String[] cmd = { "-i" , backgroundMp3File.toString(), "-y", mp3towavTempFile.toString() };
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Converting background audio\n"+"2/5");
Log.e("AudioProcessor", "Starging convertgf MP3 TO Wav");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
changeMicAudio();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
Log.e("AudioProcessor", "Failed to convert MP3 TO Wav");
//onError(message);
throw new RuntimeException("Failed to convert MP3 TO Wav");
//convertMP3ToWav();
}
});
}
/**
* Combines 2 wav files into one wav file. Overlays audio
*/
private void combineWavs() {
Log.e("AudioProcessor", "Combine wavs");
//ffmpeg -i C:\Users\VR1\Desktop\_mp3.wav -i C:\Users\VR1\Desktop\_pcm.wav -filter_complex amix=inputs=2:duration=first:dropout_transition=3 C:\Users\VR1\Desktop\out.wav
String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", volumeChangedTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", "-y",combinedwavTempFile.toString()};
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Combining the two audio files\n"+"4/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
encodeWavToAAC();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
}
});
}
private void changeMicAudio(){
Log.e("AudioProcessor", "Change audio volume");
//ffmpeg -i input.wav -filter:a "volume=1.5" output.wav
String[] cmdy = { "-i", mp3towavTempFile.toString(), "-af", "volume=0.9", "-y",volumeChangedTempFile.toString()};
ffmpeg.execute(cmdy, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Normalizing volume\n"+"3/5");
}
@Override
public void onSuccess(String message) {
combineWavs();
super.onSuccess(message);
}
@Override
public void onFailure(String message) {
super.onFailure(message);
Log.e("AudioProcessor", message);
}
});
}
/**
* Do something on error. Releases program data (deletes files)
* @param message
*/
private void onError(String message) {
release();
if (listener != null) {
//listener.onError(message);
}
}
/**
* Encode to AAC
*/
private void encodeWavToAAC() {
Log.e("AudioProcessor", "Encode to AAC");
//ffmpeg -i file.wav -c:a aac -b:a 128k -f adts output.m4a
String[] cmd = { "-i" , combinedwavTempFile.toString(), "-c:a", "aac", "-b:a", "128k", "-f", "adts", "-y",outputFile.toString()};
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
super.onStart();
percentProgress.setText("Normalizing volume\n"+"3/5");
}
@Override
public void onSuccess(String message) {
super.onSuccess(message);
if (listener != null) {
listener.onSuccess(outputFile);
}
release();
}
@Override
public void onFailure(String message) {
super.onFailure(message);
onError(message);
encodeWavToAAC();
}
});
}
/**
* Uninitializes class
*/
private void release() {
if (listener != null) {
listener.onFinish();
}
destroyTempFiles();
}
/**
* Prepares temp required files by deleteing them if they exsist.
* Files cannot exists before ffmpeg actions. FFMpeg automatically creates those files.
*/
private void prepareTempFiles() {
pcmtowavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_pcm.wav");
mp3towavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_mp3.wav");
combinedwavTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_combined.wav");
volumeChangedTempFile = new File(context.getFilesDir()+ Common.TEMP_LOCAL_DIR + "/" + "_volumeChanged.wav");
destroyTempFiles();
}
/**
* Destroys temp required files
*/
private void destroyTempFiles() {
pcmtowavTempFile.delete();
mp3towavTempFile.delete();
combinedwavTempFile.delete();
volumeChangedTempFile.delete();
}
/**
* Checks if all files are set, so we can process them
* @return - all files ready
*/
private boolean checkIfAllFilesPresent() {
if(micPcmFile == null || backgroundMp3File == null || outputFile == null) {
Log.e("AudioProcessor", "All files are not set! Set all files!");
return false;
}
return true;
}
public void setOutputFile(File outputFile) {
this.outputFile = outputFile;
}
public void setListener(AudioProcessorListener listener) {
this.listener = listener;
}
public void setMicPcmFile(File micPcmFile) {
this.micPcmFile = micPcmFile;
}
public void setBackgroundMp3File(File backgroundMp3File) {
this.backgroundMp3File = backgroundMp3File;
}
public interface AudioProcessorListener {
void onStart();
void onSuccess(File output);
void onError(String message);
void onFinish();
}
}How I am usually testing it and getting the crashes is letting the
AudioProcessor
get to the 2nd method, which isconvertMP3ToWav()
and then close the application. When I start it back up again and start processing the files the application crashes.I have tried many ways and I thought about throwing the application back to start when it is minimized with this code in the
Main Activity
@Override
protected void onUserLeaveHint()
{
if (Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
} else {
finish();
}
}I thought that it would stop everything but it still kept crashing. After doing some debugging I found that even when I minimize the app and do the
finishAndRemoveTask()
theAudioProcessor
is still working and it still does all of theffmpeg
commands and even calls theonSuccess()/onFinish()
methods.How can I completely stop everything or at least stop and clear the
AudioProcessor
when the application is minimized ?