mp4parser icon indicating copy to clipboard operation
mp4parser copied to clipboard

java.lang.IndexOutOfBoundsException: index=0 out of bounds (limit=0)

Open geegee456 opened this issue 7 years ago • 7 comments

The library sucks from the first line of code:

H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(baseDir + "/sample2.mp4"));

java.lang.IndexOutOfBoundsException: index=0 out of bounds (limit=0) at java.nio.Buffer.checkIndex(Buffer.java:528) at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:212) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.getNalUnitHeader(H264TrackImpl.java:96) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.readSamples(H264TrackImpl.java:285) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.parse(H264TrackImpl.java:107) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.(H264TrackImpl.java:83) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.(H264TrackImpl.java:87) at com.googlecode.mp4parser.authoring.tracks.h264.H264TrackImpl.(H264TrackImpl.java:91)

geegee456 avatar Sep 04 '18 21:09 geegee456

I have same issue, found any solution ????

GauravCreed avatar Jan 02 '19 13:01 GauravCreed

Yeah i have the same error.

Ditmar avatar Mar 12 '19 20:03 Ditmar

I also Have Same error Anyone have any solution

ShilpaPatil21 avatar May 02 '19 05:05 ShilpaPatil21

I have the same error when trying to parse this file: https://ia600502.us.archive.org/7/items/NuclearExplosion/NuclearExplosionwww.keepvid.com.mp4

benedikt90 avatar Oct 18 '19 14:10 benedikt90

This issue is fixed in the latest release

implementation 'org.mp4parser:isoparser:1.9.41'
implementation 'org.mp4parser:muxer:1.9.41'
implementation 'org.mp4parser:streaming:1.9.41'

I have tested with @reijin90 video and it is working fine.

Please close this issue.

HBiSoft avatar Jan 27 '20 09:01 HBiSoft

Hi @HBiSoft , i just ran into the same issue again.

Tested with my own mp4 video and @reijin90 video, both of them throw me IndexOutOfBoundException

 java.lang.IndexOutOfBoundsException: index=0 out of bounds (limit=0)
        at java.nio.Buffer.checkIndex(Buffer.java:556)
        at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:224)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.getNalUnitHeader(H264TrackImpl.java:116)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.readSamples(H264TrackImpl.java:306)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.parse(H264TrackImpl.java:138)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.<init>(H264TrackImpl.java:98)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.<init>(H264TrackImpl.java:103)
        at org.mp4parser.muxer.tracks.h264.H264TrackImpl.<init>(H264TrackImpl.java:107)
        at com.otaliastudios.cameraview.demo.CameraActivity.concatenateVideo(CameraActivity.java:441)
        at com.otaliastudios.cameraview.demo.CameraActivity.onClick(CameraActivity.java:299)
        at android.view.View.performClick(View.java:7259)
        at android.view.View.performClickInternal(View.java:7236)
        at android.view.View.access$3600(View.java:801)
        at android.view.View$PerformClick.run(View.java:27892)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

I am using

  implementation 'org.mp4parser:isoparser:1.9.41'
  implementation 'org.mp4parser:muxer:1.9.41'
  implementation 'org.mp4parser:streaming:1.9.41'

Using the code example from demo app, any help would be very much appreciated, thanks!

jianinz avatar May 28 '20 12:05 jianinz

After some researching, i found a work around. If you have a mp4 video, try install ffmpeg CLI tools, for mac users, brew install ffmpeg. Once it's installed, then run ffmpeg -i input.mp4 -vcodec copy -bsf h264_mp4toannexb -an -f h264 output.h264 to convert mp4 to h264 first which can ben later fed into your code, you could find reference from StackOverflow

jianinz avatar May 28 '20 12:05 jianinz