2
votes

I have a bunch of jpeg images representing a video. I need to encode the images in H264 format so I can stream it to a server (from android device). I understand this can be done using ffmpeg library. I compiled ffmpeg to a .so file and now I'm trying to find out what methods to use and how...

Anyone know how can I convert jpeg into H264 stream on Android using ffmpeg? Any sample code will be appreciated :)

Thanks! PB

2
Hi. Did you succeed? I could get to convert images to MPEG from linux, but when copy the same code to JNI in Android (yes I could build libffmpeg.so) I get a green video. I will try with H264. - JScoobyCed

2 Answers

0
votes

https://github.com/jhotovy/android-ffmpeg

ProjectTest in this project has android code that creates mp4 from collection of jpg's (video) and an mp3 (audio)

This project is forked from another project on git .. you can build it on linux following the instructions

0
votes

I use the modified script to compile ffmpeg with android NDK r8 and ffmpeg 0.1.11.

#!/bin/bash

######################################################
# FFmpeg builds script for Android+ARM platform
#
# This script is released under term of 
#   CDDL (http://www.opensource.org/licenses/cddl1) 
# Wrote by pinxue ([email protected]) from RockPlayer.com
#                                   2010-8 ~ 2011-4
# Modified by Jacx Wang jacxwang(@)gmail.com 2012-07
######################################################

NDK=/Users/jacxwang/app/android-ndk-r8
PLATFORM=/Users/jacxwang/app/android-ndk-r8/platforms/android-8/arch-arm
PREBUILT=/Users/jacxwang/app/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86


function build_one
{

./configure --target-os=linux \
--prefix=$PREFIX \
--enable-cross-compile \
--extra-libs="-lgcc" \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums  -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
--disable-shared \
--enable-static \
--extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -nostdlib -lc -lm -ldl -llog" \
--enable-parsers \
--enable-encoders  \
--enable-decoders \
--enable-muxers \
--enable-demuxers \
--enable-swscale  \
--disable-ffplay \
--enable-ffprobe \
--enable-ffserver \
--enable-network \
--enable-indevs \
--disable-bsfs \
--disable-filters \
--enable-protocols  \
--enable-asm \
--enable-gpl \
$ADDITIONAL_CONFIGURE_FLAG


#make clean
make  -j3 install

$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o

$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a 

}

#arm v6
CPU=armv6
OPTIMIZE_CFLAGS="-marm -march=$CPU"
PREFIX=./android/$CPU 
ADDITIONAL_CONFIGURE_FLAG=
#build_one

#arm v7vfpv3
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU 
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v7vfp
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
PREFIX=./android/$CPU-vfp
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v6+vfp
CPU=armv6
OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
PREFIX=./android/${CPU}-vfp 
ADDITIONAL_CONFIGURE_FLAG=
build_one