2

I am using MediaExtractor to extract video and audio tracks from a Video file and then feed them again to a MediaMuxer.

The code works fine if extracted Media format contains both csd-0 and csd-1 and the converted video is working nicely. However, some videos only have csd-0 only and these videos cause the application to crash at MediaMuxer.stop().

Here is the stack trace:

 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] Now Executing->Idle  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] onOMXFillBufferDone 0xb9398f00 time 0 us, flags = 0x00000000  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] onOMXFillBufferDone 0xb9355318 time 0 us, flags = 0x00000000  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] Now Idle->Loaded  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.enc] Now Loaded  
 V/ACodec(5925)  Now uninitialized  
 D/MPEG4Writer(5925)  Stopping Video track  
 E/MPEG4Writer(5925)  Missing codec specific data  
 I/MPEG4Writer(5925)  Received total/0-length (59454/0) buffers and encoded 59454 frames. - audio  
 I/MPEG4Writer(5925)  Received total/0-length (33102/0) buffers and encoded 33102 frames. - video  
 I/MPEG4Writer(5925)  Audio track drift time  0 us 
 D/MPEG4Writer(5925)  Stopping Video track source  
 D/MPEG4Writer(5925)  Video track stopped  
 D/MPEG4Writer(5925)  Stopping Audio track  
 D/MPEG4Writer(5925)  Stopping Audio track source  
 D/MPEG4Writer(5925)  Audio track stopped  
 D/MPEG4Writer(5925)  Duration from tracks range is [1380519183, 1380629229] us  
 D/MPEG4Writer(5925)  Stopping writer thread  
 D/MPEG4Writer(5925)  0 chunks are written in the last batch  
 D/MPEG4Writer(5925)  Writer thread stopped  
 W/dalvikvm(5925)  threadid=13  thread exiting with uncaught exception (group=0x417b9700) 
 E/AndroidRuntime(5925)  FATAL EXCEPTION  AsyncTask #2 
 E/AndroidRuntime(5925)  java.lang.RuntimeException  An error occured while executing doInBackground() 
 E/AndroidRuntime(5925)   at android.os.AsyncTask$3.done(AsyncTask.java 299)
 E/AndroidRuntime(5925)   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java 352)
 E/AndroidRuntime(5925)   at java.util.concurrent.FutureTask.setException(FutureTask.java 219)
 E/AndroidRuntime(5925)   at java.util.concurrent.FutureTask.run(FutureTask.java 239)
 E/AndroidRuntime(5925)   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java 230)
 E/AndroidRuntime(5925)   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java 1080)
 E/AndroidRuntime(5925)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java 573)
 E/AndroidRuntime(5925)   at java.lang.Thread.run(Thread.java 841)
 E/AndroidRuntime(5925)  Caused by  java.lang.IllegalStateException  Failed to stop the muxer
 E/AndroidRuntime(5925)   at android.media.MediaMuxer.nativeStop(Native Method) 
 E/AndroidRuntime(5925)   at android.media.MediaMuxer.stop(MediaMuxer.java 190)
 E/AndroidRuntime(5925)   at xxx.xxx.xxx.xxx$AsyncTask1.doInBackground(EditorActivity2.java 1519)
 E/AndroidRuntime(5925)   at xxx.xxx.xxx.xxx$AsyncTask1.doInBackground(EditorActivity2.java 1)
 E/AndroidRuntime(5925)   at android.os.AsyncTask$2.call(AsyncTask.java 287)
 E/AndroidRuntime(5925)   at java.util.concurrent.FutureTask.run(FutureTask.java 234)
 E/AndroidRuntime(5925)   ... 4 more 
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] Now Executing->Idle  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] saw error -1011 instead of an input buffer  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] onOMXFillBufferDone 0xb9160970 time 291950 us, flags = 0x00000000  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] onOMXFillBufferDone 0xb9353db8 time 0 us, flags = 0x00000000  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] Now Idle->Loaded  
 V/ACodec(5925)  [OMX.Exynos.mpeg4.dec] Now Loaded  
 V/ACodec(5925)  Now uninitialized  
Mohamed_AbdAllah
  • 5,311
  • 3
  • 28
  • 47
  • The missing CSD is definitely the problem - `E/MPEG4Writer(5925) Missing codec specific data`. The error is coming from line 2573 in https://android.googlesource.com/platform/frameworks/av/+/kitkat-release/media/libstagefright/MPEG4Writer.cpp . If the video source isn't providing the necessary values you may need to synthesize your own (SPS/PPS for AVC). – fadden Jan 25 '14 at 20:14
  • 1
    @fadden How do I create csd-1? And why MediaExtractor provides only csd-0? – Mohamed_AbdAllah Jan 25 '14 at 20:34
  • What is creating these video files? It might be worth decoding the first few NAL units in working and non-working streams by hand to see how they differ. You can find info about them online (e.g. http://stackoverflow.com/questions/1685494/what-does-this-h264-nal-header-mean). – fadden Jan 25 '14 at 21:47
  • 1
    I am testing with a video that comes with Samsung phones (Wonders of Nature). MediaExtractor.getTrackFormat() returns a MediaFormat Object with only csd-0 – Mohamed_AbdAllah Jan 25 '14 at 21:57
  • @fadden: "Wonders of nature" contains Mpeg-4 part 2 codec, not h264 (Mpeg-4 avc). For this one, it seems that expected behavior is not to have csd-1. (at least sample code that I found only reads csd-1 for avc). In this case, how should csd-1 be generated? – user1592546 Dec 05 '14 at 08:42

0 Answers0