9

I'm appending two audio file using mp4parser. Appending is done but it is very slow don't know what is the issue.

On this line debugger stuck for big audio files for example approx 30 minutes audio file.

Container out = new DefaultMp4Builder().build(result);

Here is code.

Movie[] inMovies = null;
                inMovies = new Movie[]{
                        MovieCreator.build(fileOne),
                        MovieCreator.build(fileTwo)};
                List<Track> audioTracks = new LinkedList<Track>();

                for (Movie m : inMovies) {
                    for (Track t : m.getTracks()) {
                        if (t.getHandler().equals("soun")) {
                            audioTracks.add(t);
                        }
                    }
                }
                Movie result = new Movie();
                if (audioTracks.size() > 0) {
                    result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
                }
                Container out = new DefaultMp4Builder().build(result);
                String fileName = getFilename();
                FileChannel fc = new RandomAccessFile(String.format(fileName), "rw").getChannel();
                out.writeContainer(fc);
                fc.close();

Manifestfile

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ehrlite"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ehr_icon"
        android:label="@string/app_name"
        android:name="com.webservice.myApplication"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.ehrlite.LoginActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
             android:windowSoftInputMode="stateVisible|adjustResize"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.ehrlite.MasterActivity"
            android:screenOrientation="portrait">
        </activity>
          <activity
            android:name="com.ehrlite.MainActivity"
            android:screenOrientation="portrait"
            >
        </activity>
        <activity
            android:name="com.ehrlite.PrevMemo"
            android:screenOrientation="portrait">
        </activity>
        <activity
            android:name="com.webviewcall.WebViewActivity"
            android:screenOrientation="portrait">
        </activity>`enter code here`
        <activity
            android:name="com.ehrlite.TranscribedActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden"
            android:windowSoftInputMode="adjustPan">
        </activity>


    </application>

</manifest>

Can anyone help me out to improve performance, thanks in advance.

solidau
  • 4,021
  • 3
  • 24
  • 45
Bhumit
  • 338
  • 3
  • 12
  • can you put your manifests? – Bhunnu Baba Oct 18 '16 at 11:43
  • @BhunnuBaba I have updated my question. – Bhumit Oct 18 '16 at 12:37
  • perhaps MyApplication file extends with MultiDexApplication if yes then once add android:largeHeap="true" in application tag – Bhunnu Baba Oct 18 '16 at 12:44
  • @BhunnuBaba I have tried but not getting success... – Bhumit Oct 18 '16 at 12:52
  • once try with separate thread – Bhunnu Baba Oct 18 '16 at 12:56
  • @BhunnuBaba Tried but debugger still stuck on this line new DefaultMp4Builder().build(result)... – Bhumit Oct 19 '16 at 06:32
  • I was having the same problem. but if you do not put it on debug it runs fine. that said you should not put it on main thread as bigger files may take longer time to process. I put few logs instead of debugging for a work around. this problem is rather general, CPU intensive task runs slow when you put the process on debug. – Ankit Oct 22 '16 at 08:48
  • Checkd this different approach ? http://stackoverflow.com/questions/6731155/how-to-merge-two-mp3-files-into-one-combine-join Or with library like https://github.com/sannies/mp4parser/blob/master/examples/src/main/java/com/googlecode/mp4parser/AppendExample.java – Sreehari Oct 24 '16 at 07:22
  • Guys any solution ? – Abhishek Chauhan Mar 26 '18 at 18:37

1 Answers1

0

I found the solution for your answer. I was faced issue previously. You are using RandomAccessfile. You need to use FileOutputStream

Container out = new DefaultMp4Builder().build(result);
        String outputFilePath = getfilename();
        FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
        out.writeContainer(fos.getChannel());
        fos.close();

Reference:

why are java RandomAccessFile so much slower than FileOutputStream?

Community
  • 1
  • 1
NovusMobile
  • 1,813
  • 2
  • 21
  • 48
  • I have tried FileOutputStream inplace of RandomAccessfile but still it takes much time for concatenating two audio files. No Success. – Bhumit Oct 25 '16 at 10:42
  • do one thing. there may is a chance to didn't find proper path for getFilename(). Use hardcoded path for this – NovusMobile Oct 26 '16 at 04:04
  • @NovusMobile great observation for code. Bhumit You should try this .Thanks for sharing. I was facing same issue. +1 for this. – full Error Oct 26 '16 at 10:22