Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8756211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:01:16+00:00 2026-06-13T14:01:16+00:00

EDIT I have check the execution and found that the error is not (yet)

  • 0

EDIT
I have check the execution and found that the error is not (yet) at the swscale point. My current issue is that the JPG image is not found:
No such file or directory
when doing the avformat_open_input(&pFormatCtx, imageFileName, NULL, NULL);
Before you tell me I need to register anything, I can tell I already did (I updated the code below).
I also added the Android permission to access the external storage (I don’t think it is related to Android since I can already write to the /mnt/sdcard/ where the image is also located)
END EDIT

I have been through several tutorials (including the few posted from SO, i.e. http://dranger.com/ffmpeg/, how to compile ffmpeg for Android…,been through dolphin-player source code). Here is what I have:
. Compiled ffmpeg for android
. Ran basic tutorials using NDK to create a dummy video on my android device
. been able to generate a MPEG2 video from images on Ubuntu using a modified version of dummy video code above and a lot of Googling
. running the new code on Android device gives a green screen video (duration 1 sec whatever the number of frames I encode)

I saw another post about iPhone in a similar situation that mentioned the ARM processor optimization could be the culprit. I tried a few ldextra-flags (-arch armv7-a and similar) to no success.

I include at the end the code that loads the image. Is there something different to do on Android than on linux? Is my ffmpeg build not correct for Android video encoding?

void copyFrame(AVCodecContext *destContext, AVFrame* dest,
            AVCodecContext *srcContext, AVFrame* source) {
struct SwsContext *swsContext;
swsContext = sws_getContext(srcContext->width, srcContext->height, srcContext->pix_fmt,
                destContext->width, destContext->height, destContext->pix_fmt,
                SWS_FAST_BILINEAR, NULL, NULL, NULL);
sws_scale(swsContext, source->data, source->linesize, 0, srcContext->height, dest->data, dest->linesize);
sws_freeContext(swsContext);
}

int loadFromFile(const char* imageFileName, AVFrame* realPicture, AVCodecContext* videoContext) {
AVFormatContext *pFormatCtx = NULL;
avcodec_register_all();
av_register_all();

int ret = avformat_open_input(&pFormatCtx, imageFileName, NULL, NULL);
if (ret != 0) {
    // ERROR hapening here
    // Can't open image file. Use strerror(AVERROR(ret))) for details
    return ERR_CANNOT_OPEN_IMAGE;
}

AVCodecContext *pCodecCtx;

pCodecCtx = pFormatCtx->streams[0]->codec;
pCodecCtx->width = W_VIDEO;
pCodecCtx->height = H_VIDEO;
pCodecCtx->pix_fmt = PIX_FMT_YUV420P;

// Find the decoder for the video stream
AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (!pCodec) {
    // Codec not found
    return ERR_CODEC_NOT_FOUND;
}

// Open codec
if (avcodec_open(pCodecCtx, pCodec) < 0) {
    // Could not open codec
    return ERR_CANNOT_OPEN_CODEC;
}

// 
AVFrame *pFrame;

pFrame = avcodec_alloc_frame();

if (!pFrame) {
    // Can't allocate memory for AVFrame
    return ERR_CANNOT_ALLOC_MEM;
}

int frameFinished;
int numBytes;

// Determine required buffer size and allocate buffer
numBytes = avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
uint8_t *buffer = (uint8_t *) av_malloc(numBytes * sizeof (uint8_t));

avpicture_fill((AVPicture *) pFrame, buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
AVPacket packet;
int res = 0;
while (av_read_frame(pFormatCtx, &packet) >= 0) {
    if (packet.stream_index != 0)
        continue;

    ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
    if (ret > 0) {
        // now, load the useful info into realPicture
        copyFrame(videoContext, realPicture, pCodecCtx, pFrame);
        // Free the packet that was allocated by av_read_frame
        av_free_packet(&packet);
        return 0;
    } else {
        // Error decoding frame. Use strerror(AVERROR(ret))) for details
        res = ERR_DECODE_FRAME;
    }
}
av_free(pFrame);

// close codec
avcodec_close(pCodecCtx);

// Close the image file
av_close_input_file(pFormatCtx);

return res;
}

Some ./configure options:
--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 -mfloat-abi=softfp -mfpu=vfp -marm -march=armv7-a -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE"

--extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog"

--arch=armv7-a --enable-armv5te --enable-armv6 --enable-armvfp --enable-memalign-hack

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:01:17+00:00Added an answer on June 13, 2026 at 2:01 pm

    The code above is actually working. I tried on other devices (Samsung Galaxy Tab 7) and it is fine. The issue could be due to the cyanomodgen or specific Android version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT I have finally figured out the problem i have been having on my
EDIT: I have fixed all but two warnings now, so thank you all for
EDIT: I have edited my post... Working on a project (c#), I have a
EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i
EDIT: I have realized the source of my problem. I only have count information
EDIT: I have changed the question as it was too localized and gained negative
I won't want to have edit any working sets. I just want a way
I have an edit text which functions as a search box in my application.
I have two Edit Fields Username and Password and everytime i revert back to
I have 2 edit texts. I will type a message in one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.