
Recherche avancée
Médias (3)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (36)
-
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs -
Support de tous types de médias
10 avril 2011Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)
-
Other interesting software
13 avril 2011, parWe don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
We don’t know them, we didn’t try them, but you can take a peek.
Videopress
Website : http://videopress.com/
License : GNU/GPL v2
Source code : (...)
Sur d’autres sites (8368)
-
Saving frames as JPG with FFMPEG (Visual Studio / C++)
10 novembre 2022, par Diego SatizabalI am trying to save all frames from a mp4 video in separate JPG files, I have a code that runs and actually saves something to JPG files but files are not recognized as images and nothing is showing.


Below my full code, I am using Visual Studio 2022 in Windows 11 and FFMPEG 5.1. The function that saves the images is save_frame_as_jpeg which is actually an adaption from the code provided here but changing the use of avcodec_encode_video2 for avcodec_send_frame/avcodec_receive_packet as indicated in the documentation.


I am obiously doing something wrong but cannot quite find it, BTW, I know that a simple command (ffmpeg -i input.mp4 -vf fps=1 vid_%d.png) will do this but I am requiring to do it by code.


Any help is appreciated, thanks in advance !


// FfmpegTests.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#pragma warning(disable : 4996)
extern "C"
{
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
 #include "libavfilter/avfilter.h"
 #include "libavutil/opt.h"
 #include "libavutil/avutil.h"
 #include "libavutil/error.h"
 #include "libavfilter/buffersrc.h"
 #include "libavfilter/buffersink.h"
 #include "libswscale/swscale.h"
}

#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avfilter.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "swscale.lib")

#include <cstdio>
#include <iostream>
#include <chrono>
#include <thread>


static AVFormatContext* fmt_ctx;
static AVCodecContext* dec_ctx;
AVFilterGraph* filter_graph;
AVFilterContext* buffersrc_ctx;
AVFilterContext* buffersink_ctx;
static int video_stream_index = -1;

const char* filter_descr = "scale=78:24,transpose=cclock";
static int64_t last_pts = AV_NOPTS_VALUE;

static int open_input_file(const char* filename)
{
 const AVCodec* dec;
 int ret;

 if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n");
 return ret;
 }

 if ((ret = avformat_find_stream_info(fmt_ctx, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
 return ret;
 }

 /* select the video stream */
 ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file\n");
 return ret;
 }
 video_stream_index = ret;

 /* create decoding context */
 dec_ctx = avcodec_alloc_context3(dec);
 if (!dec_ctx)
 return AVERROR(ENOMEM);
 avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar);

 /* init the video decoder */
 if ((ret = avcodec_open2(dec_ctx, dec, NULL)) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n");
 return ret;
 }

 return 0;
}

static int init_filters(const char* filters_descr)
{
 char args[512];
 int ret = 0;
 const AVFilter* buffersrc = avfilter_get_by_name("buffer");
 const AVFilter* buffersink = avfilter_get_by_name("buffersink");
 AVFilterInOut* outputs = avfilter_inout_alloc();
 AVFilterInOut* inputs = avfilter_inout_alloc();
 AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;
 enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };

 filter_graph = avfilter_graph_alloc();
 if (!outputs || !inputs || !filter_graph) {
 ret = AVERROR(ENOMEM);
 goto end;
 }

 /* buffer video source: the decoded frames from the decoder will be inserted here. */
 snprintf(args, sizeof(args),
 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
 time_base.num, time_base.den,
 dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den);

 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
 args, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
 goto end;
 }

 /* buffer video sink: to terminate the filter chain. */
 ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",
 NULL, NULL, filter_graph);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
 goto end;
 }

 ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
 goto end;
 }

 outputs->name = av_strdup("in");
 outputs->filter_ctx = buffersrc_ctx;
 outputs->pad_idx = 0;
 outputs->next = NULL;

 inputs->name = av_strdup("out");
 inputs->filter_ctx = buffersink_ctx;
 inputs->pad_idx = 0;
 inputs->next = NULL;

 if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,
 &inputs, &outputs, NULL)) < 0)
 goto end;

 if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)
 goto end;

end:
 avfilter_inout_free(&inputs);
 avfilter_inout_free(&outputs);

 return ret;
}

static void display_frame(const AVFrame* frame, AVRational time_base)
{
 int x, y;
 uint8_t* p0, * p;
 int64_t delay;

 if (frame->pts != AV_NOPTS_VALUE) {
 if (last_pts != AV_NOPTS_VALUE) {
 /* sleep roughly the right amount of time;
 * usleep is in microseconds, just like AV_TIME_BASE. */
 AVRational timeBaseQ;
 timeBaseQ.num = 1;
 timeBaseQ.den = AV_TIME_BASE;

 delay = av_rescale_q(frame->pts - last_pts, time_base, timeBaseQ);
 if (delay > 0 && delay < 1000000)
 std::this_thread::sleep_for(std::chrono::microseconds(delay));
 }
 last_pts = frame->pts;
 }

 /* Trivial ASCII grayscale display. */
 p0 = frame->data[0];
 puts("\033c");
 for (y = 0; y < frame->height; y++) {
 p = p0;
 for (x = 0; x < frame->width; x++)
 putchar(" .-+#"[*(p++) / 52]);
 putchar('\n');
 p0 += frame->linesize[0];
 }
 fflush(stdout);
}

int save_frame_as_jpeg(AVCodecContext* pCodecCtx, AVFrame* pFrame, int FrameNo) {
 int ret = 0;

 const AVCodec* jpegCodec = avcodec_find_encoder(AV_CODEC_ID_JPEG2000);
 if (!jpegCodec) {
 return -1;
 }
 AVCodecContext* jpegContext = avcodec_alloc_context3(jpegCodec);
 if (!jpegContext) {
 return -1;
 }

 jpegContext->pix_fmt = pCodecCtx->pix_fmt;
 jpegContext->height = pFrame->height;
 jpegContext->width = pFrame->width;
 jpegContext->time_base = AVRational{ 1,10 };

 ret = avcodec_open2(jpegContext, jpegCodec, NULL);
 if (ret < 0) {
 return ret;
 }
 FILE* JPEGFile;
 char JPEGFName[256];

 AVPacket packet;
 packet.data = NULL;
 packet.size = 0;
 av_init_packet(&packet);

 int gotFrame;

 ret = avcodec_send_frame(jpegContext, pFrame);
 if (ret < 0) {
 return ret;
 }

 ret = avcodec_receive_packet(jpegContext, &packet);
 if (ret < 0) {
 return ret;
 }

 sprintf(JPEGFName, "c:\\folder\\dvr-%06d.jpg", FrameNo);
 JPEGFile = fopen(JPEGFName, "wb");
 fwrite(packet.data, 1, packet.size, JPEGFile);
 fclose(JPEGFile);

 av_packet_unref(&packet);
 avcodec_close(jpegContext);
 return 0;
}

int main(int argc, char** argv)
{
 AVFrame* frame;
 AVFrame* filt_frame;
 AVPacket* packet;
 int ret;

 if (argc != 2) {
 fprintf(stderr, "Usage: %s file\n", argv[0]);
 exit(1);
 }

 frame = av_frame_alloc();
 filt_frame = av_frame_alloc();
 packet = av_packet_alloc();

 if (!frame || !filt_frame || !packet) {
 fprintf(stderr, "Could not allocate frame or packet\n");
 exit(1);
 }

 if ((ret = open_input_file(argv[1])) < 0)
 goto end;
 if ((ret = init_filters(filter_descr)) < 0)
 goto end;

 while (true)
 {
 if ((ret = av_read_frame(fmt_ctx, packet)) < 0)
 break;

 if (packet->stream_index == video_stream_index) {
 ret = avcodec_send_packet(dec_ctx, packet);
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
 break;
 }

 while (ret >= 0)
 {
 ret = avcodec_receive_frame(dec_ctx, frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
 break;
 }
 else if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n");
 goto end;
 }

 frame->pts = frame->best_effort_timestamp;

 /* push the decoded frame into the filtergraph */
 if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
 av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
 break;
 }

 /* pull filtered frames from the filtergraph */
 while (1) {
 ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 break;
 if (ret < 0)
 goto end;
 display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
 av_frame_unref(filt_frame);
 
 ret = save_frame_as_jpeg(dec_ctx, frame, dec_ctx->frame_number);
 if (ret < 0)
 goto end;
 }
 av_frame_unref(frame);
 }
 }
 av_packet_unref(packet);
 }

end:
 avfilter_graph_free(&filter_graph);
 avcodec_free_context(&dec_ctx);
 avformat_close_input(&fmt_ctx);
 av_frame_free(&frame);
 av_frame_free(&filt_frame);
 av_packet_free(&packet);

 if (ret < 0 && ret != AVERROR_EOF) {
 char errBuf[AV_ERROR_MAX_STRING_SIZE]{0};
 int res = av_strerror(ret, errBuf, AV_ERROR_MAX_STRING_SIZE);
 fprintf(stderr, "Error: %s\n", errBuf);
 exit(1);
 }

 exit(0);
}
</thread></chrono></iostream></cstdio>


-
Ffmpeg in Android Studio
7 décembre 2016, par Ahmed Abd-Elmegedi’am trying to add Ffmpeg library to use it in Live Streaming app based in Youtube APi when i add it and i use Cmake Build tool the header files only shown in the c native class which i create and i want it to be included in the other header files
which came with library how can i do it in cmake script or onther way ?This my cmake build script
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
ffmpeg-jni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/ffmpeg-jni.c )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
ffmpeg-jni
# Links the target library to the log library
# included in the NDK.
${log-lib} )
include_directories(src/main/cpp/include/ffmpeglib)
include_directories(src/main/cpp/include/libavcodec)
include_directories(src/main/cpp/include/libavformat)
include_directories(src/main/cpp/include/libavutil)This my native class i create as native file i android studio and i also have an error in jintJNIcall not found
#include <android></android>log.h>
#include
#include
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/opt.h"
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jboolean
JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_init(JNIEnv *env, jobject thiz,
jint width, jint height,
jint audio_sample_rate,
jstring rtmp_url);
JNIEXPORT void JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_shutdown(JNIEnv
*env,
jobject thiz
);
JNIEXPORT jintJNICALL
Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeVideoFrame(JNIEnv
*env,
jobject thiz,
jbyteArray
yuv_image);
JNIEXPORT jint
JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeAudioFrame(JNIEnv *env,
jobject thiz,
jshortArray audio_data,
jint length);
#ifdef __cplusplus
}
#endif
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "ffmpeg-jni", __VA_ARGS__)
#define URL_WRONLY 2
static AVFormatContext *fmt_context;
static AVStream *video_stream;
static AVStream *audio_stream;
static int pts
= 0;
static int last_audio_pts = 0;
// Buffers for UV format conversion
static unsigned char *u_buf;
static unsigned char *v_buf;
static int enable_audio = 1;
static int64_t audio_samples_written = 0;
static int audio_sample_rate = 0;
// Stupid buffer for audio samples. Not even a proper ring buffer
#define AUDIO_MAX_BUF_SIZE 16384 // 2x what we get from Java
static short audio_buf[AUDIO_MAX_BUF_SIZE];
static int audio_buf_size = 0;
void AudioBuffer_Push(const short *audio, int num_samples) {
if (audio_buf_size >= AUDIO_MAX_BUF_SIZE - num_samples) {
LOGI("AUDIO BUFFER OVERFLOW: %i + %i > %i", audio_buf_size, num_samples,
AUDIO_MAX_BUF_SIZE);
return;
}
for (int i = 0; i < num_samples; i++) {
audio_buf[audio_buf_size++] = audio[i];
}
}
int AudioBuffer_Size() { return audio_buf_size; }
short *AudioBuffer_Get() { return audio_buf; }
void AudioBuffer_Pop(int num_samples) {
if (num_samples > audio_buf_size) {
LOGI("Audio buffer Pop WTF: %i vs %i", num_samples, audio_buf_size);
return;
}
memmove(audio_buf, audio_buf + num_samples, num_samples * sizeof(short));
audio_buf_size -= num_samples;
}
void AudioBuffer_Clear() {
memset(audio_buf, 0, sizeof(audio_buf));
audio_buf_size = 0;
}
static void log_callback(void *ptr, int level, const char *fmt, va_list vl) {
char x[2048];
vsnprintf(x, 2048, fmt, vl);
LOGI(x);
}
JNIEXPORT jboolean
JNICALL Java_com_example_venrto_ffmpegtest_Ffmpeg_init(JNIEnv *env, jobject thiz,
jint width, jint height,
jint audio_sample_rate_param,
jstring rtmp_url) {
avcodec_register_all();
av_register_all();
av_log_set_callback(log_callback);
fmt_context = avformat_alloc_context();
AVOutputFormat *ofmt = av_guess_format("flv", NULL, NULL);
if (ofmt) {
LOGI("av_guess_format returned %s", ofmt->long_name);
} else {
LOGI("av_guess_format fail");
return JNI_FALSE;
}
fmt_context->oformat = ofmt;
LOGI("creating video stream");
video_stream = av_new_stream(fmt_context, 0);
if (enable_audio) {
LOGI("creating audio stream");
audio_stream = av_new_stream(fmt_context, 1);
}
// Open Video Codec.
// ======================
AVCodec *video_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (!video_codec) {
LOGI("Did not find the video codec");
return JNI_FALSE; // leak!
} else {
LOGI("Video codec found!");
}
AVCodecContext *video_codec_ctx = video_stream->codec;
video_codec_ctx->codec_id = video_codec->id;
video_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
video_codec_ctx->level = 31;
video_codec_ctx->width = width;
video_codec_ctx->height = height;
video_codec_ctx->pix_fmt = PIX_FMT_YUV420P;
video_codec_ctx->rc_max_rate = 0;
video_codec_ctx->rc_buffer_size = 0;
video_codec_ctx->gop_size = 12;
video_codec_ctx->max_b_frames = 0;
video_codec_ctx->slices = 8;
video_codec_ctx->b_frame_strategy = 1;
video_codec_ctx->coder_type = 0;
video_codec_ctx->me_cmp = 1;
video_codec_ctx->me_range = 16;
video_codec_ctx->qmin = 10;
video_codec_ctx->qmax = 51;
video_codec_ctx->keyint_min = 25;
video_codec_ctx->refs = 3;
video_codec_ctx->trellis = 0;
video_codec_ctx->scenechange_threshold = 40;
video_codec_ctx->flags |= CODEC_FLAG_LOOP_FILTER;
video_codec_ctx->me_method = ME_HEX;
video_codec_ctx->me_subpel_quality = 6;
video_codec_ctx->i_quant_factor = 0.71;
video_codec_ctx->qcompress = 0.6;
video_codec_ctx->max_qdiff = 4;
video_codec_ctx->time_base.den = 10;
video_codec_ctx->time_base.num = 1;
video_codec_ctx->bit_rate = 3200 * 1000;
video_codec_ctx->bit_rate_tolerance = 0;
video_codec_ctx->flags2 |= 0x00000100;
fmt_context->bit_rate = 4000 * 1000;
av_opt_set(video_codec_ctx, "partitions", "i8x8,i4x4,p8x8,b8x8", 0);
av_opt_set_int(video_codec_ctx, "direct-pred", 1, 0);
av_opt_set_int(video_codec_ctx, "rc-lookahead", 0, 0);
av_opt_set_int(video_codec_ctx, "fast-pskip", 1, 0);
av_opt_set_int(video_codec_ctx, "mixed-refs", 1, 0);
av_opt_set_int(video_codec_ctx, "8x8dct", 0, 0);
av_opt_set_int(video_codec_ctx, "weightb", 0, 0);
if (fmt_context->oformat->flags & AVFMT_GLOBALHEADER)
video_codec_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
LOGI("Opening video codec");
AVDictionary *vopts = NULL;
av_dict_set(&vopts, "profile", "main", 0);
//av_dict_set(&vopts, "vprofile", "main", 0);
av_dict_set(&vopts, "rc-lookahead", 0, 0);
av_dict_set(&vopts, "tune", "film", 0);
av_dict_set(&vopts, "preset", "ultrafast", 0);
av_opt_set(video_codec_ctx->priv_data, "tune", "film", 0);
av_opt_set(video_codec_ctx->priv_data, "preset", "ultrafast", 0);
av_opt_set(video_codec_ctx->priv_data, "tune", "film", 0);
int open_res = avcodec_open2(video_codec_ctx, video_codec, &vopts);
if (open_res < 0) {
LOGI("Error opening video codec: %i", open_res);
return JNI_FALSE; // leak!
}
// Open Audio Codec.
// ======================
if (enable_audio) {
AudioBuffer_Clear();
audio_sample_rate = audio_sample_rate_param;
AVCodec *audio_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
if (!audio_codec) {
LOGI("Did not find the audio codec");
return JNI_FALSE; // leak!
} else {
LOGI("Audio codec found!");
}
AVCodecContext *audio_codec_ctx = audio_stream->codec;
audio_codec_ctx->codec_id = audio_codec->id;
audio_codec_ctx->codec_type = AVMEDIA_TYPE_AUDIO;
audio_codec_ctx->bit_rate = 128000;
audio_codec_ctx->bit_rate_tolerance = 16000;
audio_codec_ctx->channels = 1;
audio_codec_ctx->profile = FF_PROFILE_AAC_LOW;
audio_codec_ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
audio_codec_ctx->sample_rate = 44100;
LOGI("Opening audio codec");
AVDictionary *opts = NULL;
av_dict_set(&opts, "strict", "experimental", 0);
open_res = avcodec_open2(audio_codec_ctx, audio_codec, &opts);
LOGI("audio frame size: %i", audio_codec_ctx->frame_size);
if (open_res < 0) {
LOGI("Error opening audio codec: %i", open_res);
return JNI_FALSE; // leak!
}
}
const jbyte *url = (*env)->GetStringUTFChars(env, rtmp_url, NULL);
// Point to an output file
if (!(ofmt->flags & AVFMT_NOFILE)) {
if (avio_open(&fmt_context->pb, url, URL_WRONLY) < 0) {
LOGI("ERROR: Could not open file %s", url);
return JNI_FALSE; // leak!
}
}
(*env)->ReleaseStringUTFChars(env, rtmp_url, url);
LOGI("Writing output header.");
// Write file header
if (avformat_write_header(fmt_context, NULL) != 0) {
LOGI("ERROR: av_write_header failed");
return JNI_FALSE;
}
pts = 0;
last_audio_pts = 0;
audio_samples_written = 0;
// Initialize buffers for UV format conversion
int frame_size = video_codec_ctx->width * video_codec_ctx->height;
u_buf = (unsigned char *) av_malloc(frame_size / 4);
v_buf = (unsigned char *) av_malloc(frame_size / 4);
LOGI("ffmpeg encoding init done");
return JNI_TRUE;
}
JNIEXPORT void JNICALL
Java_com_example_venrto_ffmpegtest_Ffmpeg_shutdown(JNIEnv
*env,
jobject thiz
) {
av_write_trailer(fmt_context);
avio_close(fmt_context
->pb);
avcodec_close(video_stream
->codec);
if (enable_audio) {
avcodec_close(audio_stream
->codec);
}
av_free(fmt_context);
av_free(u_buf);
av_free(v_buf);
fmt_context = NULL;
u_buf = NULL;
v_buf = NULL;
}
JNIEXPORT jintJNICALL
Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeVideoFrame(JNIEnv
*env,
jobject thiz,
jbyteArray
yuv_image) {
int yuv_length = (*env)->GetArrayLength(env, yuv_image);
unsigned char *yuv_data = (*env)->GetByteArrayElements(env, yuv_image, 0);
AVCodecContext *video_codec_ctx = video_stream->codec;
//LOGI("Yuv size: %i w: %i h: %i", yuv_length, video_codec_ctx->width, video_codec_ctx->height);
int frame_size = video_codec_ctx->width * video_codec_ctx->height;
const unsigned char *uv = yuv_data + frame_size;
// Convert YUV from NV12 to I420. Y channel is the same so we don't touch it,
// we just have to deinterleave UV.
for (
int i = 0;
i < frame_size / 4; i++) {
v_buf[i] = uv[i * 2];
u_buf[i] = uv[i * 2 + 1];
}
AVFrame source;
memset(&source, 0, sizeof(AVFrame));
source.data[0] =
yuv_data;
source.data[1] =
u_buf;
source.data[2] =
v_buf;
source.linesize[0] = video_codec_ctx->
width;
source.linesize[1] = video_codec_ctx->width / 2;
source.linesize[2] = video_codec_ctx->width / 2;
// only for bitrate regulation. irrelevant for sync.
source.
pts = pts;
pts++;
int out_length = frame_size + (frame_size / 2);
unsigned char *out = (unsigned char *) av_malloc(out_length);
int compressed_length = avcodec_encode_video(video_codec_ctx, out, out_length, &source);
(*env)->
ReleaseByteArrayElements(env, yuv_image, yuv_data,
0);
// Write to file too
if (compressed_length > 0) {
AVPacket pkt;
av_init_packet(&pkt);
pkt.
pts = last_audio_pts;
if (video_codec_ctx->coded_frame && video_codec_ctx->coded_frame->key_frame) {
pkt.flags |= 0x0001;
}
pkt.
stream_index = video_stream->index;
pkt.
data = out;
pkt.
size = compressed_length;
if (
av_interleaved_write_frame(fmt_context,
&pkt) != 0) {
LOGI("Error writing video frame");
}
} else {
LOGI("??? compressed_length <= 0");
}
last_audio_pts++;
av_free(out);
return
compressed_length;
}
JNIEXPORT jintJNICALL
Java_com_example_venrto_ffmpegtest_Ffmpeg_encodeAudioFrame(JNIEnv
*env,
jobject thiz,
jshortArray
audio_data,
jint length
) {
if (!enable_audio) {
return 0;
}
short *audio = (*env)->GetShortArrayElements(env, audio_data, 0);
//LOGI("java audio buffer size: %i", length);
AVCodecContext *audio_codec_ctx = audio_stream->codec;
unsigned char *out = av_malloc(128000);
AudioBuffer_Push(audio, length
);
int total_compressed = 0;
while (
AudioBuffer_Size()
>= audio_codec_ctx->frame_size) {
AVPacket pkt;
av_init_packet(&pkt);
int compressed_length = avcodec_encode_audio(audio_codec_ctx, out, 128000,
AudioBuffer_Get());
total_compressed +=
compressed_length;
audio_samples_written += audio_codec_ctx->
frame_size;
int new_pts = (audio_samples_written * 1000) / audio_sample_rate;
if (compressed_length > 0) {
pkt.
size = compressed_length;
pkt.
pts = new_pts;
last_audio_pts = new_pts;
//LOGI("audio_samples_written: %i comp_length: %i pts: %i", (int)audio_samples_written, (int)compressed_length, (int)new_pts);
pkt.flags |= 0x0001;
pkt.
stream_index = audio_stream->index;
pkt.
data = out;
if (
av_interleaved_write_frame(fmt_context,
&pkt) != 0) {
LOGI("Error writing audio frame");
}
}
AudioBuffer_Pop(audio_codec_ctx
->frame_size);
}
(*env)->
ReleaseShortArrayElements(env, audio_data, audio,
0);
av_free(out);
return
total_compressed;
}this an example for a header file which i have an error include
#include "libavutil/samplefmt.h"
#include "libavutil/avutil.h"
#include "libavutil/cpu.h"
#include "libavutil/dict.h"
#include "libavutil/log.h"
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
#include "libavutil/version.h"in the libavcodec/avcodec.h
This code based in this example :
https://github.com/youtube/yt-watchme -
How do I use native C libraries in Android Studio
11 mars 2015, par NicholasI created a problem some years back based on https://ikaruga2.wordpress.com/2011/06/15/video-live-wallpaper-part-1/. My project was built in the version of Eclipse provided directly by Google at the time and worked fine with a copy of the compiled ffmpeg libraries created with my app name.
Now I’m trying to create a new app based on my old app. As Google no longer supports Eclipse I downloaded Android Studio and imported my project. With a few tweaks, I was able to successfully compile the old version of the project. So I modified the name, copied a new set of ".so" files into app\src\main\jniLibs\armeabi (where I assumed they should go) and tried running the application on my phone again with absolutely no other changes.
The NDK throws no errors. Gradle compiles the file without errors and installs it on my phone. The app appears in my live wallpapers list and I can click it to bring up the preview. But instead of a video appearing I receive and error and logCat reports :
02-26 21:50:31.164 18757-18757/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.nightscapecreations.anim3free.VideoLiveWallpaper.onSharedPreferenceChanged(VideoLiveWallpaper.java:165)
at com.nightscapecreations.anim3free.VideoLiveWallpaper.onCreate(VideoLiveWallpaper.java:81)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2273)
at android.app.ActivityThread.access$1600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 144 could not load needed library '/data/data/com.nightscapecreations.anim1free/lib/libavutil.so' for 'libavcore.so' (load_library[1091]: Library '/data/data/com.nightscapecreations.anim1free/lib/libavutil.so' not found)
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at com.nightscapecreations.anim3free.NativeCalls.<clinit>(NativeCalls.java:64)
at com.nightscapecreations.anim3free.VideoLiveWallpaper.onSharedPreferenceChanged(VideoLiveWallpaper.java:165)
at com.nightscapecreations.anim3free.VideoLiveWallpaper.onCreate(VideoLiveWallpaper.java:81)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2273)
at android.app.ActivityThread.access$1600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
</clinit>I’m a novice Android/Java/C++ developer and am not sure what this error means, but Google leads me to believe that my new libraries are not being found. In my Eclipse project I had this set of libraries in "libs\armeabi", and another copy of them in a more complicated folder structure at "jni\ffmpeg-android\build\ffmpeg\armeabi\lib". Android Studio appears to have kept everything the same, other than renaming "libs" to "jniLibs", but I’m hitting a brick wall with this error and am unsure how to proceed.
How can I compile this new app with the new name using Android Studio ?
In case it helps here is my Android.mk file :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MY_LIB_PATH := ffmpeg-android/build/ffmpeg/armeabi/lib
LOCAL_MODULE := bambuser-libavcore
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcore.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavformat
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavformat.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavcodec
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavcodec.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavfilter
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavfilter.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libavutil
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libavutil.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bambuser-libswscale
LOCAL_SRC_FILES := $(MY_LIB_PATH)/libswscale.so
include $(PREBUILT_SHARED_LIBRARY)
#local_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -DANDROID_NDK \
-DDISABLE_IMPORTGL
LOCAL_MODULE := video
LOCAL_SRC_FILES := video.c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/ffmpeg-android/ffmpeg \
$(LOCAL_PATH)/freetype/include/freetype2 \
$(LOCAL_PATH)/freetype/include \
$(LOCAL_PATH)/ftgl/src \
$(LOCAL_PATH)/ftgl
LOCAL_LDLIBS := -L$(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-arm/usr/lib -L$(LOCAL_PATH) -L$(LOCAL_PATH)/ffmpeg-android/build/ffmpeg/armeabi/lib/ -lGLESv1_CM -ldl -lavformat -lavcodec -lavfilter -lavutil -lswscale -llog -lz -lm
include $(BUILD_SHARED_LIBRARY)And here is my NativeCalls.java :
package com.nightscapecreations.anim3free;
public class NativeCalls {
//ffmpeg
public static native void initVideo();
public static native void loadVideo(String fileName); //
public static native void prepareStorageFrame();
public static native void getFrame(); //
public static native void freeConversionStorage();
public static native void closeVideo();//
public static native void freeVideo();//
//opengl
public static native void initPreOpenGL(); //
public static native void initOpenGL(); //
public static native void drawFrame(); //
public static native void closeOpenGL(); //
public static native void closePostOpenGL();//
//wallpaper
public static native void updateVideoPosition();
public static native void setSpanVideo(boolean b);
//getters
public static native int getVideoHeight();
public static native int getVideoWidth();
//setters
public static native void setWallVideoDimensions(int w,int h);
public static native void setWallDimensions(int w,int h);
public static native void setScreenPadding(int w,int h);
public static native void setVideoMargins(int w,int h);
public static native void setDrawDimensions(int drawWidth,int drawHeight);
public static native void setOffsets(int x,int y);
public static native void setSteps(int xs,int ys);
public static native void setScreenDimensions(int w, int h);
public static native void setTextureDimensions(int tx,
int ty );
public static native void setOrientation(boolean b);
public static native void setPreviewMode(boolean b);
public static native void setTonality(int t);
public static native void toggleGetFrame(boolean b);
//fps
public static native void setLoopVideo(boolean b);
static {
System.loadLibrary("avcore");
System.loadLibrary("avformat");
System.loadLibrary("avcodec");
//System.loadLibrary("avdevice");
System.loadLibrary("avfilter");
System.loadLibrary("avutil");
System.loadLibrary("swscale");
System.loadLibrary("video");
}
}EDIT
This is the first part of my video.c file :
#include <gles></gles>gl.h>
#include <gles></gles>glext.h>
#include <gles2></gles2>gl2.h>
#include <gles2></gles2>gl2ext.h>
#include
#include
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>
#include
#include
#include
#include <android></android>log.h>
//#include <ftgl></ftgl>ftgl.h>
//ffmpeg video variables
int initializedVideo=0;
int initializedFrame=0;
AVFormatContext *pFormatCtx=NULL;
int videoStream;
AVCodecContext *pCodecCtx=NULL;
AVCodec *pCodec=NULL;
AVFrame *pFrame=NULL;
AVPacket packet;
int frameFinished;
float aspect_ratio;
//ffmpeg video conversion variables
AVFrame *pFrameConverted=NULL;
int numBytes;
uint8_t *bufferConverted=NULL;
//opengl
int textureFormat=PIX_FMT_RGBA; // PIX_FMT_RGBA PIX_FMT_RGB24
int GL_colorFormat=GL_RGBA; // Must match the colorspace specified for textureFormat
int textureWidth=256;
int textureHeight=256;
int nTextureHeight=-256;
int textureL=0, textureR=0, textureW=0;
int frameTonality;
//GLuint textureConverted=0;
GLuint texturesConverted[2] = { 0,1 };
GLuint dummyTex = 2;
static int len=0;
static const char* BWVertexSrc =
"attribute vec4 InVertex;\n"
"attribute vec2 InTexCoord0;\n"
"attribute vec2 InTexCoord1;\n"
"uniform mat4 ProjectionModelviewMatrix;\n"
"varying vec2 TexCoord0;\n"
"varying vec2 TexCoord1;\n"
"void main()\n"
"{\n"
" gl_Position = ProjectionModelviewMatrix * InVertex;\n"
" TexCoord0 = InTexCoord0;\n"
" TexCoord1 = InTexCoord1;\n"
"}\n";
static const char* BWFragmentSrc =
"#version 110\n"
"uniform sampler2D Texture0;\n"
"uniform sampler2D Texture1;\n"
"varying vec2 TexCoord0;\n"
"varying vec2 TexCoord1;\n"
"void main()\n"
"{\n"
" vec3 color = texture2D(m_Texture, texCoord).rgb;\n"
" float gray = (color.r + color.g + color.b) / 3.0;\n"
" vec3 grayscale = vec3(gray);\n"
" gl_FragColor = vec4(grayscale, 1.0);\n"
"}";
static GLuint shaderProgram;
//// Create a pixmap font from a TrueType file.
//FTGLPixmapFont font("/home/user/Arial.ttf");
//// Set the font size and render a small text.
//font.FaceSize(72);
//font.Render("Hello World!");
//screen dimensions
int screenWidth = 50;
int screenHeight= 50;
int screenL=0, screenR=0, screenW=0;
int dPaddingX=0,dPaddingY=0;
int drawWidth=50,drawHeight=50;
//wallpaper
int wallWidth = 50;
int wallHeight = 50;
int xOffSet, yOffSet;
int xStep, yStep;
jboolean spanVideo = JNI_TRUE;
//video dimensions
int wallVideoWidth = 0;
int wallVideoHeight = 0;
int marginX, marginY;
jboolean isScreenPortrait = JNI_TRUE;
jboolean isPreview = JNI_TRUE;
jboolean loopVideo = JNI_TRUE;
jboolean isGetFrame = JNI_TRUE;
//file
const char * szFileName;
#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
#define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
//test variables
#define RGBA8(r, g, b) (((r) << (24)) | ((g) << (16)) | ((b) << (8)) | 255)
int sPixelsInited=JNI_FALSE;
uint32_t *s_pixels=NULL;
int s_pixels_size() {
return (sizeof(uint32_t) * textureWidth * textureHeight * 5);
}
void render_pixels1(uint32_t *pixels, uint32_t c) {
int x, y;
/* fill in a square of 5 x 5 at s_x, s_y */
for (y = 0; y < textureHeight; y++) {
for (x = 0; x < textureWidth; x++) {
int idx = x + y * textureWidth;
pixels[idx++] = RGBA8(255, 255, 0);
}
}
}
void render_pixels2(uint32_t *pixels, uint32_t c) {
int x, y;
/* fill in a square of 5 x 5 at s_x, s_y */
for (y = 0; y < textureHeight; y++) {
for (x = 0; x < textureWidth; x++) {
int idx = x + y * textureWidth;
pixels[idx++] = RGBA8(0, 0, 255);
}
}
}
void Java_com_nightscapecreations_anim3free_NativeCalls_initVideo (JNIEnv * env, jobject this) {
initializedVideo = 0;
initializedFrame = 0;
}
/* list of things that get loaded: */
/* buffer */
/* pFrameConverted */
/* pFrame */
/* pCodecCtx */
/* pFormatCtx */
void Java_com_nightscapecreations_anim3free_NativeCalls_loadVideo (JNIEnv * env, jobject this, jstring fileName) {
jboolean isCopy;
szFileName = (*env)->GetStringUTFChars(env, fileName, &isCopy);
//debug
__android_log_print(ANDROID_LOG_DEBUG, "NDK: ", "NDK:LC: [%s]", szFileName);
// Register all formats and codecs
av_register_all();
// Open video file
if(av_open_input_file(&pFormatCtx, szFileName, NULL, 0, NULL)!=0) {
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Couldn't open file");
return;
}
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Succesfully loaded file");
// Retrieve stream information */
if(av_find_stream_info(pFormatCtx)<0) {
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Couldn't find stream information");
return;
}
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Found stream info");
// Find the first video stream
videoStream=-1;
int i;
for(i=0; inb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
videoStream=i;
break;
}
if(videoStream==-1) {
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Didn't find a video stream");
return;
}
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Found video stream");
// Get a pointer to the codec contetx for the video stream
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL) {
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Unsupported codec");
return;
}
// Open codec
if(avcodec_open(pCodecCtx, pCodec)<0) {
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Could not open codec");
return;
}
// Allocate video frame (decoded pre-conversion frame)
pFrame=avcodec_alloc_frame();
// keep track of initialization
initializedVideo = 1;
__android_log_print(ANDROID_LOG_DEBUG, "video.c", "NDK: Finished loading video");
}
//for this to work, you need to set the scaled video dimensions first
void Java_com_nightscapecreations_anim3free_NativeCalls_prepareStorageFrame (JNIEnv * env, jobject this) {
// Allocate an AVFrame structure
pFrameConverted=avcodec_alloc_frame();
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(textureFormat, textureWidth, textureHeight);
bufferConverted=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
if ( pFrameConverted == NULL || bufferConverted == NULL )
__android_log_print(ANDROID_LOG_DEBUG, "prepareStorage>>>>", "Out of memory");
// Assign appropriate parts of buffer to image planes in pFrameRGB
// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
// of AVPicture
avpicture_fill((AVPicture *)pFrameConverted, bufferConverted, textureFormat, textureWidth, textureHeight);
__android_log_print(ANDROID_LOG_DEBUG, "prepareStorage>>>>", "Created frame");
__android_log_print(ANDROID_LOG_DEBUG, "prepareStorage>>>>", "texture dimensions: %dx%d", textureWidth, textureHeight);
initializedFrame = 1;
}
jint Java_com_nightscapecreations_anim3free_NativeCalls_getVideoWidth (JNIEnv * env, jobject this) {
return pCodecCtx->width;
}
jint Java_com_nightscapecreations_anim3free_NativeCalls_getVideoHeight (JNIEnv * env, jobject this) {
return pCodecCtx->height;
}
void Java_com_nightscapecreations_anim3free_NativeCalls_getFrame (JNIEnv * env, jobject this) {
// keep reading packets until we hit the end or find a video packet
while(av_read_frame(pFormatCtx, &packet)>=0) {
static struct SwsContext *img_convert_ctx;
// Is this a packet from the video stream?
if(packet.stream_index==videoStream) {
// Decode video frame
/* __android_log_print(ANDROID_LOG_DEBUG, */
/* "video.c", */
/* "getFrame: Try to decode frame" */
/* ); */
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data, packet.size);
// Did we get a video frame?
if(frameFinished) {
if(img_convert_ctx == NULL) {
/* get/set the scaling context */
int w = pCodecCtx->width;
int h = pCodecCtx->height;
img_convert_ctx = sws_getContext(w, h, pCodecCtx->pix_fmt, textureWidth,textureHeight, textureFormat, SWS_FAST_BILINEAR, NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
return;
}
}
/* if img convert null */
/* finally scale the image */
/* __android_log_print(ANDROID_LOG_DEBUG, */
/* "video.c", */
/* "getFrame: Try to scale the image" */
/* ); */
//pFrameConverted = pFrame;
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameConverted->data, pFrameConverted->linesize);
//av_picture_crop(pFrameConverted->data, pFrame->data, 1, pCodecCtx->height, pCodecCtx->width);
//av_picture_crop();
//avfilter_vf_crop();
/* do something with pFrameConverted */
/* ... see drawFrame() */
/* We found a video frame, did something with it, now free up
packet and return */
av_free_packet(&packet);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.age: %d", pFrame->age);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.buffer_hints: %d", pFrame->buffer_hints);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.display_picture_number: %d", pFrame->display_picture_number);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.hwaccel_picture_private: %d", pFrame->hwaccel_picture_private);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.key_frame: %d", pFrame->key_frame);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.palette_has_changed: %d", pFrame->palette_has_changed);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.pict_type: %d", pFrame->pict_type);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrame.qscale_type: %d", pFrame->qscale_type);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.age: %d", pFrameConverted->age);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.buffer_hints: %d", pFrameConverted->buffer_hints);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.display_picture_number: %d", pFrameConverted->display_picture_number);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.hwaccel_picture_private: %d", pFrameConverted->hwaccel_picture_private);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.key_frame: %d", pFrameConverted->key_frame);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.palette_has_changed: %d", pFrameConverted->palette_has_changed);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.pict_type: %d", pFrameConverted->pict_type);
// __android_log_print(ANDROID_LOG_INFO, "Droid Debug", "pFrameConverted.qscale_type: %d", pFrameConverted->qscale_type);
return;
} /* if frame finished */
} /* if packet video stream */
// Free the packet that was allocated by av_read_frame
av_free_packet(&packet);
} /* while */
//reload video when you get to the end
av_seek_frame(pFormatCtx,videoStream,0,AVSEEK_FLAG_ANY);
}
void Java_com_nightscapecreations_anim3free_NativeCalls_setLoopVideo (JNIEnv * env, jobject this, jboolean b) {
loopVideo = b;
}
void Java_com_nightscapecreations_anim3free_NativeCalls_closeVideo (JNIEnv * env, jobject this) {
if ( initializedFrame == 1 ) {
// Free the converted image
av_free(bufferConverted);
av_free(pFrameConverted);
initializedFrame = 0;
__android_log_print(ANDROID_LOG_DEBUG, "closeVideo>>>>", "Freed converted image");
}
if ( initializedVideo == 1 ) {
/* // Free the YUV frame */
av_free(pFrame);
/* // Close the codec */
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
initializedVideo = 0;
__android_log_print(ANDROID_LOG_DEBUG, "closeVideo>>>>", "Freed video structures");
}
}
void Java_com_nightscapecreations_anim3free_NativeCalls_freeVideo (JNIEnv * env, jobject this) {
if ( initializedVideo == 1 ) {
/* // Free the YUV frame */
av_free(pFrame);
/* // Close the codec */
avcodec_close(pCodecCtx);
// Close the video file
av_close_input_file(pFormatCtx);
__android_log_print(ANDROID_LOG_DEBUG, "closeVideo>>>>", "Freed video structures");
initializedVideo = 0;
}
}
void Java_com_nightscapecreations_anim3free_NativeCalls_freeConversionStorage (JNIEnv * env, jobject this) {
if ( initializedFrame == 1 ) {
// Free the converted image
av_free(bufferConverted);
av_freep(pFrameConverted);
initializedFrame = 0;
}
}
/*--- END OF VIDEO ----*/
/* disable these capabilities. */
static GLuint s_disable_options[] = {
GL_FOG,
GL_LIGHTING,
GL_CULL_FACE,
GL_ALPHA_TEST,
GL_BLEND,
GL_COLOR_LOGIC_OP,
GL_DITHER,
GL_STENCIL_TEST,
GL_DEPTH_TEST,
GL_COLOR_MATERIAL,
0
};
// For stuff that opengl needs to work with,
// like the bitmap containing the texture
void Java_com_nightscapecreations_anim3free_NativeCalls_initPreOpenGL (JNIEnv * env, jobject this) {
}
...