mp4parser icon indicating copy to clipboard operation
mp4parser copied to clipboard

Expected Start Word 0xfff

Open garodev opened this issue 7 years ago • 8 comments

Hello, excuse me for my bad english. I want to merge in the same file two audios (one is music, and the otherone is an audio file record with the mobile) I don´t want append, i want that i can listen music and voice at the same time. I was trying to use:
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl("audio.aac")); But always receive the same error, with the music and with de audio recorder.... Expected Start Word 0xfff My audio is record with mediaMuxer and mediacoder. How can i solve that? i don´t know what else find and test. Thank You so much.

garodev avatar Oct 26 '16 11:10 garodev

Same here

surahul avatar Feb 16 '17 11:02 surahul

Hello, I got the same error any solution? my audio file is a wav I've recorded.

Regards,

grosalex avatar Apr 03 '17 08:04 grosalex

The AACTrackImpl can read a raw AAC track. I cannot read a wav track nor convert wav to aac.

Alex Bruneau [email protected] schrieb am Mo., 3. Apr. 2017 um 10:32 Uhr:

Hello, I got the same error any solution? my audio file is a wav I've recorded.

Regards,

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sannies/mp4parser/issues/229#issuecomment-291080329, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKUD7uUH4ehPz0aRcPPsvbjR57vTLg7ks5rsK5_gaJpZM4KhFXy .

sannies avatar Apr 03 '17 08:04 sannies

I got the same issu after converting to m4a. I've been using this conversion method : ` public static final String COMPRESSED_AUDIO_FILE_MIME_TYPE = "audio/mp4a-latm"; public static final int COMPRESSED_AUDIO_FILE_BIT_RATE = 64000; // 64kbps public static final int SAMPLING_RATE = 48000; public static final int BUFFER_SIZE = 48000; public static final int CODEC_TIMEOUT_IN_MS = 5000; try { String filePath = AUDIO_RECORDING_FILE_NAME; File inputFile = new File(filePath); FileInputStream fis = new FileInputStream(inputFile);

            File outputFile = new File( COMPRESSED_AUDIO_FILE_NAME);
            if (outputFile.exists()) outputFile.delete();

            MediaMuxer mux = new MediaMuxer(outputFile.getAbsolutePath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

            MediaFormat outputFormat = MediaFormat.createAudioFormat(COMPRESSED_AUDIO_FILE_MIME_TYPE,SAMPLING_RATE, 1);
            outputFormat.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
            outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, COMPRESSED_AUDIO_FILE_BIT_RATE);
            outputFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16384);

            MediaCodec codec = MediaCodec.createEncoderByType(COMPRESSED_AUDIO_FILE_MIME_TYPE);
            codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
            codec.start();

            ByteBuffer[] codecInputBuffers = codec.getInputBuffers(); // Note: Array of buffers
            ByteBuffer[] codecOutputBuffers = codec.getOutputBuffers();

            MediaCodec.BufferInfo outBuffInfo = new MediaCodec.BufferInfo();
            byte[] tempBuffer = new byte[BUFFER_SIZE];
            boolean hasMoreData = true;
            double presentationTimeUs = 0;
            int audioTrackIdx = 0;
            int totalBytesRead = 0;
            int percentComplete = 0;
            do {
                int inputBufIndex = 0;
                while (inputBufIndex != -1 && hasMoreData) {
                    inputBufIndex = codec.dequeueInputBuffer(CODEC_TIMEOUT_IN_MS);

                    if (inputBufIndex >= 0) {
                        ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
                        dstBuf.clear();

                        int bytesRead = fis.read(tempBuffer, 0, dstBuf.limit());
                        Log.e("bytesRead","Readed "+bytesRead);
                        if (bytesRead == -1) { // -1 implies EOS
                            hasMoreData = false;
                            codec.queueInputBuffer(inputBufIndex, 0, 0, (long) presentationTimeUs, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
                        } else {
                            totalBytesRead += bytesRead;
                            dstBuf.put(tempBuffer, 0, bytesRead);
                            codec.queueInputBuffer(inputBufIndex, 0, bytesRead, (long) presentationTimeUs, 0);
                            presentationTimeUs = 1000000l * (totalBytesRead / 2) / SAMPLING_RATE;
                        }
                    }
                }


                // Drain audio
                int outputBufIndex = 0;
                while (outputBufIndex != MediaCodec.INFO_TRY_AGAIN_LATER) {
                    outputBufIndex = codec.dequeueOutputBuffer(outBuffInfo, CODEC_TIMEOUT_IN_MS);
                    if (outputBufIndex >= 0) {
                        ByteBuffer encodedData = codecOutputBuffers[outputBufIndex];
                        encodedData.position(outBuffInfo.offset);
                        encodedData.limit(outBuffInfo.offset + outBuffInfo.size);
                        if ((outBuffInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0 && outBuffInfo.size != 0) {
                            codec.releaseOutputBuffer(outputBufIndex, false);
                        }else{
                            mux.writeSampleData(audioTrackIdx, codecOutputBuffers[outputBufIndex], outBuffInfo);
                            codec.releaseOutputBuffer(outputBufIndex, false);
                        }
                    } else if (outputBufIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
                        outputFormat = codec.getOutputFormat();
                        audioTrackIdx = mux.addTrack(outputFormat);
                        mux.start();
                    } else if (outputBufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
                    } else if (outputBufIndex == MediaCodec.INFO_TRY_AGAIN_LATER) {
                        // NO OP
                    } else {
                    }
                }
                percentComplete = (int) Math.round(((float) totalBytesRead / (float) inputFile.length()) * 100.0);

            } while (outBuffInfo.flags != MediaCodec.BUFFER_FLAG_END_OF_STREAM);
            fis.close();
            mux.stop();
            mux.release();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

` My outpu file seems to bo correct and I have the "Expected Start Word 0xfff" exception.

Regards,

grosalex avatar Apr 03 '17 08:04 grosalex

Hello Sannies , I`m getting the same exception. Can u help me out in this? Please check my below code.


val movie = MovieCreator.build(videoPath) //val ct = CroppedTrack(getAudioTrack(), 10, 500) val track = getAudioTrack() // below you will get getAudioTrack methode movie.addTrack(track)

        val mp4file = DefaultMp4Builder().build(movie)
        val fc = FileOutputStream(File(filePath)).channel
        mp4file.writeContainer(fc)
        fc.close()

private fun getAudioTrack(): Track { val track = FileDataSourceImpl(audioPath) var audio: Track? = null

    if (audioPath.contains(".mp3")) {
        readTags()
        //val audioPath = removeTags()
        audio = MP3TrackImpl(track)
    } else if (audioPath.contains(".aac")) {
        audio = AACTrackImpl(track)
    }
    return audio!!
}

ajit321 avatar Dec 12 '18 15:12 ajit321

Same error, Did you fix this error?

fullstact69 avatar Feb 10 '20 21:02 fullstact69

Hi, I had the same issue with " Expected Start Word 0xfff", but I found a solution.

It seams that MediaMuxer creates a container (mp4) so you just need to use the Movie class not the AACTrackImpl

        Movie video = MovieCreator.build(videoFile.getAbsolutePath());
        Track videoTrack = video.getTracks().get(0);


        Movie audio = MovieCreator.build(audioEncodedFile.getAbsolutePath()); // here
        Track audioTrack = audio.getTracks().get(0);

        Movie movie = new Movie();
        movie.addTrack(videoTrack);
        movie.addTrack(audioTrack);

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

// ...

koodzi avatar Jul 22 '20 07:07 koodzi

I got this same issue, I'm using AAC audio file to merge with an mp4 video file.

W/System.err: java.io.IOException: Expected Start Word 0xfff at com.googlecode.mp4parser.authoring.tracks.AACTrackImpl.readADTSHeader(AACTrackImpl.java:291)

Track nuAudio = new AACTrackImpl(new FileDataSourceImpl(audio));

AllwinJohnson avatar Aug 13 '20 08:08 AllwinJohnson