0
votes

I'm trying to get ffmpeg to encode several individual JPEG images into a video on Android. I've successfully built it for Android (see the configuration string at the end of this post).

I can encode an h.263+ video with randomly generated frame content, and ffmpeg otherwise appears to work well.

A similar question suggests that the following code should be sufficient to load an image into an AvFrame:

// Make sure we have the codecs
av_register_all();

AVFormatContext *pFormatCtx;
int ret = av_open_input_file(&pFormatCtx, imageFileName, NULL, 0, NULL);

if (ret != 0) {
    printf("Can't open image file '%s': code %d, %s",
        imageFileName, ret, strerror(AVERROR(ret)));
}

The above returns the correct absolute file path and error:

Failed '/sdcard/DCIM/Camera/IMG083.jpg': code -1094995529, Unknown error: 1094995529

Incidentally, if I omit av_register_all(), it returns with error 2.

I've compiled ffmpeg with the following arguments:

./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 " --enable-shared --enable-static --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" --disable-everything --enable-demuxer=mov --enable-demuxer=h264 --disable-ffplay --enable-protocol=file --enable-avformat --enable-avcodec --enable-decoder=mjpeg --enable-decoder=png --enable-parser=h264 --enable-encoder=h263 --enable-encoder=h263p --disable-network --enable-zlib --disable-avfilter --disable-avdevice

Any suggestions would be most welcome!

3
By the way, the error code is AVERROR_INVALIDDATA.LawfulEvil

3 Answers

3
votes

This error suggests that the decoder needed for JPEG was not built along with ffmpeg. I believe enabling mjpeg is sufficient in order for it to work, but out of frustration I simply enabled everything and it worked.

I would suggest adding --enable-decoder=mjpeg to the configuration string and rebuilding the library with NDK for Android. If that doesn't work, remove --disable-everything and individually remove incompatible components until it successfully compiles (I believe just adding --disable-indev worked for Android).

3
votes

Note: in addition to "mjpeg" muxer/demuxer/parser, you need "image2" muxer/demuxer.

0
votes

As No One wrote you need to enable mjpeg and image2 when calling ./configure

--enable-decoder=mjpeg --enable-demuxer=image2

I've just checked it with my code that reads jpg.