1

i have saved the mjpeg stream to the sdcard as xxx.mjpeg .However, the mjpeg video file was not supported in android. so how could i encode mjpeg video into 3gp or mp4 format and then store them on sdcard ,at last ,i can play back the 3gp or mp4 video on my android phone ,thanks in advance.

evan
  • 318
  • 3
  • 14
  • This isn't really an Android question, is it? You should be able to convert mjpeg coded video to 3gp or mp4 format with any decent video conversion tool, e.g. [HandBrake](http://handbrake.fr/). – MH. Dec 26 '11 at 03:49
  • it is an android question. I have got each bitmap from internet lively.so i want to save this bitmaps as an 3gp or mp4 video file.finally,i can save this 3gp or mp4 video on sdcard. At present ,my idea is to use android ndk with c++ code to encode the bitmaps manually,but it is hard . – evan Dec 26 '11 at 05:03
  • Ah, that wasn't really clear to me. There's a [related question](http://stackoverflow.com/questions/3205191/android-and-mjpeg) on SO on displaying an mjpeg stream on Android that will probably also have your answer below it. – MH. Dec 26 '11 at 05:09
  • I have got the bitmaps using the method from the related question : http://stackoverflow.com/questions/3205191/android-and-mjpeg . But i do not know how to process this bitmaps ,manually encode this bitmaps to 3gp or mp4 video files and save them to the sdcard. – evan Dec 26 '11 at 06:21
  • Right, so your question has little to do with mjpeg en has more to do with *"How to convert an image sequence to 3gp/mp4 on an Android device?"* I'm afraid I can't really help you with that. I'm also not sure if you should want this at all, with devices' processing power and battery power in mind. My best guess would be using some native lib compiled for Android. Good luck! – MH. Dec 26 '11 at 08:01
  • yeah,your guess are right.Maybe some native code can do that,but it is confused.In short,thank you for your advises and passions. – evan Dec 26 '11 at 08:08
  • Feel free to share the code mentioned in your original post, ("i have saved the mjpeg stream to the sdcard as xxx.mjpeg .") as I'm working on an application for field projects that does this exclusively with MJPEG as the final format....Thanks. – portsample Feb 09 '15 at 04:11

2 Answers2

1

There is no way you can achieve this with current Android API.

You need to encode the frames using an encoder in C++ and pass your bitmaps to the encoder via JNI. You can start with MoboPlayer's ffmpeg port. You may find the download link to their ffmpeg port at the bottom of this page

If you have the image sequence in Bitmaps, you can access the Bitmap's buffer from JNI using the AndroidBitmap_* methods and pass it on to ffmpeg for encoding

peasea
  • 346
  • 2
  • 4
  • thanks for your advices.I have download the ffmpeg port of moboplayer. But i do not know how to use the ffmpeg port to my android projects .how to use the ffmpeg and build it ? i have installed the ndk and cygwin in windows platform . – evan Dec 30 '11 at 05:09
  • Copy the ffmpeg source to jni folder (if you dont have the folder 'jni', create one) of your application workspace. there is an Android.mk in the ffmpeg source provided by mobo team. Through cygwin go to this path and issue a ndk-build. This should build a libffmpeg.so. Now add a JNI file to your project that implements all native methods that you need using ffmpeg. Link the prebuilt libffmpeg.so to this jni library. – peasea Dec 30 '11 at 06:21
  • i get error when i use the cygwin and ndk build .there are some errors so that i did not get a libffmpeg.so file. i just get obj folder in my project. – evan Dec 30 '11 at 06:51
  • 1
    $ /cygdrive/e/android-ndk-r6b/ndk-build Android NDK: WARNING: Unsupported source file extensions in /cygdrive/d/AAN/eclipse/workspace/AnR/jni/Android.mk for module ffmpegCompile thumb : ffmpeg <= asm.S Compile thumb : ffmpeg <= base64.c Compile thumb : ffmpeg <= crc.c E:\cygwin\tmp\ccxDmRFI.s: Assembler messages: E:\cygwin\tmp\ccxDmRFI.s:239: Error: unshifted register required -- `bic r5,r5,#0xFF0000' E:\cygwin\tmp\ccxDmRFI.s:241: Error: unshifted register required -- `eor r4,r4,r5,lsr#8' make: *** [/cygdrive/d/AAN/eclipse/workspace/AnR/obj/local/armeabi/objs/ffmpeg/libavutil/crc.o] Error 1 – evan Dec 30 '11 at 06:56
  • even : I remember building it with these options in Android.mk. You may try # Optional compiler flags. **LOCAL_CFLAGS := -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 - D_LARGEFILE_SOURCE -DPIC -march=armv6 -DANDROID=1 LOCAL_CFLAGS += $(CC_OPTIMIZE_FLAG) LOCAL_ARM_MODE := arm LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib -lz -llog ** – peasea Jan 03 '12 at 06:30
  • peasea: according to your advices above. I have compiled some files in the jni.However ,there are some issues happened when the cygwin compile this folder: /libavcodec/arm/dsputil_armv6.S: Assembler messages: D:/AAN/eclipse/workspace/AnR/jni/libavcodec/arm/dsputil_armv6.S:101: Error: selected processor does not support `uhadd8 r4,r4,r6' – evan Jan 03 '12 at 07:11
  • my ndk version is :android-ndk-r6b .the error show that selected processor does not support ....so how could i build the ffmpeg success? could you help me ? thank you in advance. – evan Jan 03 '12 at 07:15
  • the full errors are below: processor does not support `uxtb16 r12,r5' processor does not support `uxtb16 r8,r5,ror#8' processor does not support `pkhbt r5,r6,r4,lsl#16' ..........and then the cygwin stopped the compile process. the how did i modify the android.mk so that i can compile the ffmpeg success? – evan Jan 03 '12 at 07:20
  • even, I am not aware of mobo's ffmpeg source out there. I had built it long back.I tried the rockplayer's ffmpeg port. This has hassle free build. I was able to build it today successfully on NDK_r4b. You can download the source from here : http://www.rockplayer.com/tech_en.html – peasea Jan 03 '12 at 13:56
  • "LOCAL_CFLAGS +=-O4 -mno-thumb-interwork -mno-thumb -marm" in Android.mk has helped me compile the rockplayer libFFMPEG sources as JNI. – Marcus Wolschon May 30 '12 at 13:26
1

I am not aware of state of mobo's ffmpeg source out there. I had built it long back.

I tried the rockplayer's ffmpeg port. This has hassle free build. I was able to build it today successfully on NDK_r4b.

You can download the source from here : http://www.rockplayer.com/tech_en.html

modify the config.mk to change your tool paths and run build_andriod.sh (spelling is wrong, but it works :) )

let me know how it goes

peasea
  • 346
  • 2
  • 4
  • sorry for my leave. I cannot complie the source code of the rockplayer by your method. I just use another method in this website: http://zouyuefen.blog.163.com/blog/static/102780156201111312130944/ .However, i just get 1.6kb libffmpeg.so file. so i was failed . i hope that you can give me some websites or advice that i can compile the ffmpeg step by step. thanks. – evan Jan 19 '12 at 08:05
  • i will get your answer as the best answer if we can compile the ffmpeg success together. Now you are the best one ,too. – evan Jan 19 '12 at 08:07