├── .gitignore ├── .gitmodules ├── Project ├── .classpath ├── .gitignore ├── .project ├── AndroidManifest.xml ├── build.properties ├── build.xml ├── default.properties ├── jni │ ├── .gitignore │ ├── Android.mk │ ├── config_make_everything.sh │ ├── configure_ffmpeg.sh │ ├── configure_x264.sh │ ├── create_toolchain.sh │ ├── make_ffmpeg.sh │ ├── make_x264.sh │ ├── settings.sh │ └── videokit │ │ ├── cmdutils.c │ │ ├── ffmpeg.c │ │ ├── logjam.h │ │ ├── uk_co_halfninja_videokit_Videokit.c │ │ └── uk_co_halfninja_videokit_Videokit.h ├── proguard.cfg ├── res │ ├── drawable-hdpi │ │ └── icon.png │ ├── drawable-ldpi │ │ └── icon.png │ ├── drawable-mdpi │ │ └── icon.png │ ├── layout │ │ └── main.xml │ └── values │ │ └── strings.xml └── src │ └── uk │ └── co │ └── halfninja │ └── videokit │ └── Videokit.java ├── ProjectTest ├── .classpath ├── .gitignore ├── .project ├── AndroidManifest.xml ├── assets │ └── image.jpg ├── build.properties ├── build.xml ├── default.properties ├── proguard.cfg └── src │ └── uk │ └── co │ └── halfninja │ └── videokit │ └── VideokitTest.java ├── README.textile └── init-submodules.sh /.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | toolchain 3 | .*.swp 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "x264"] 2 | path = Project/jni/x264 3 | url = git://git.videolan.org/x264.git 4 | [submodule "ffmpeg"] 5 | path = Project/jni/ffmpeg 6 | url = git://git.videolan.org/ffmpeg.git 7 | -------------------------------------------------------------------------------- /Project/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Project/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | libs 4 | obj 5 | local.properties 6 | -------------------------------------------------------------------------------- /Project/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Project 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /Project/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Project/build.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked in Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /Project/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 54 | 55 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /Project/default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-8 12 | -------------------------------------------------------------------------------- /Project/jni/.gitignore: -------------------------------------------------------------------------------- 1 | output 2 | -------------------------------------------------------------------------------- /Project/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | LOCAL_MODULE := videokit 5 | # These need to be in the right order 6 | FFMPEG_LIBS := $(addprefix ffmpeg/, \ 7 | libavdevice/libavdevice.a \ 8 | libavformat/libavformat.a \ 9 | libavfilter/libavfilter.a \ 10 | libavcodec/libavcodec.a \ 11 | libswscale/libswscale.a \ 12 | libavutil/libavutil.a \ 13 | libswresample/libswresample.a \ 14 | libpostproc/libpostproc.a ) 15 | # ffmpeg uses its own deprecated functions liberally, so turn off that annoying noise 16 | LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations 17 | LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) x264/libx264.a 18 | LOCAL_SRC_FILES := videokit/uk_co_halfninja_videokit_Videokit.c videokit/ffmpeg.c videokit/cmdutils.c 19 | include $(BUILD_SHARED_LIBRARY) 20 | 21 | 22 | include $(CLEAR_VARS) 23 | LOCAL_MODULE := ffmpeg 24 | FFMPEG_LIBS := $(addprefix ffmpeg/, \ 25 | libavdevice/libavdevice.a \ 26 | libavformat/libavformat.a \ 27 | libavfilter/libavfilter.a \ 28 | libavcodec/libavcodec.a \ 29 | libswscale/libswscale.a \ 30 | libavutil/libavutil.a \ 31 | libswresample/libswresample.a \ 32 | libpostproc/libpostproc.a ) 33 | LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations 34 | LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) x264/libx264.a 35 | LOCAL_SRC_FILES := ffmpeg/ffmpeg.c ffmpeg/cmdutils.c 36 | include $(BUILD_EXECUTABLE) 37 | 38 | -------------------------------------------------------------------------------- /Project/jni/config_make_everything.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function die { 4 | echo "$1 failed" && exit 1 5 | } 6 | 7 | ./configure_x264.sh || die "X264 configure" 8 | ./make_x264.sh || die "X264 make" 9 | ./configure_ffmpeg.sh || die "FFMPEG configure" 10 | ./make_ffmpeg.sh || die "FFMPEG make" 11 | -------------------------------------------------------------------------------- /Project/jni/configure_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd `dirname $0` 3 | . settings.sh 4 | 5 | if [[ $minimal_featureset == 1 ]]; then 6 | echo "Using minimal featureset" 7 | featureflags="--disable-everything \ 8 | --enable-decoder=mjpeg --enable-demuxer=mjpeg --enable-parser=mjpeg \ 9 | --enable-demuxer=image2 --enable-muxer=mp4 --enable-encoder=libx264 --enable-libx264 \ 10 | --enable-decoder=rawvideo \ 11 | --enable-protocol=file \ 12 | --enable-hwaccels" 13 | fi 14 | 15 | if [[ $DEBUG == 1 ]]; then 16 | echo "DEBUG = 1" 17 | DEBUG_FLAG="--disable-stripping" 18 | fi 19 | 20 | pushd ffmpeg 21 | 22 | ./configure $DEBUG_FLAG --enable-cross-compile \ 23 | --arch=arm5te \ 24 | --enable-armv5te \ 25 | --target-os=linux \ 26 | --disable-stripping \ 27 | --prefix=../output \ 28 | --disable-neon \ 29 | --enable-version3 --ar=arm-linux-androideabi-ar \ 30 | --disable-shared \ 31 | --enable-static \ 32 | --enable-gpl \ 33 | --enable-memalign-hack \ 34 | --cc=arm-linux-androideabi-gcc \ 35 | --ld=arm-linux-androideabi-ld \ 36 | --extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated" \ 37 | $featureflags \ 38 | --disable-ffmpeg \ 39 | --disable-ffplay \ 40 | --disable-ffprobe \ 41 | --disable-ffserver \ 42 | --disable-network \ 43 | --enable-filter=buffer \ 44 | --enable-filter=buffersink \ 45 | --disable-demuxer=v4l \ 46 | --disable-demuxer=v4l2 \ 47 | --disable-indev=v4l \ 48 | --disable-indev=v4l2 \ 49 | --extra-cflags="-I../x264 -Ivideokit" \ 50 | --extra-ldflags="-L../x264" 51 | 52 | popd; popd 53 | -------------------------------------------------------------------------------- /Project/jni/configure_x264.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd `dirname $0` 3 | . settings.sh 4 | 5 | pushd x264 6 | 7 | ./configure --cross-prefix=arm-linux-androideabi- \ 8 | --enable-pic \ 9 | --host=arm-linux 10 | 11 | popd;popd 12 | -------------------------------------------------------------------------------- /Project/jni/create_toolchain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd `dirname $0` 3 | . settings.sh 4 | 5 | $NDK/build/tools/make-standalone-toolchain.sh --install-dir=./toolchain 6 | -------------------------------------------------------------------------------- /Project/jni/make_ffmpeg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd `dirname $0` 3 | . settings.sh 4 | pushd ffmpeg 5 | make 6 | popd; popd 7 | -------------------------------------------------------------------------------- /Project/jni/make_x264.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd `dirname $0` 3 | . settings.sh 4 | pushd x264 5 | make 6 | popd;popd 7 | -------------------------------------------------------------------------------- /Project/jni/settings.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # set to path of your NDK (or export NDK to environment) 4 | 5 | if [[ "x$NDK" == "x" ]]; then 6 | NDK=~/apps/android-ndk-r5c 7 | fi 8 | # i use only a small number of formats - set this to 0 if you want everything. 9 | # changed 0 to the default, so it'll compile shitloads of codecs normally 10 | if [[ "x$minimal_featureset" == "x" ]]; then 11 | minimal_featureset=1 12 | fi 13 | 14 | ## stop editing 15 | 16 | if [[ ! -d $NDK ]]; then 17 | echo "$NDK is not a directory. Exiting." 18 | exit 1 19 | fi 20 | 21 | function current_dir { 22 | echo "$(cd "$(dirname $0)"; pwd)" 23 | } 24 | 25 | export PATH=$PATH:$NDK:$(current_dir)/toolchain/bin 26 | 27 | echo $PATH 28 | 29 | -------------------------------------------------------------------------------- /Project/jni/videokit/cmdutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Various utilities for command line tools 3 | * Copyright (c) 2000-2003 Fabrice Bellard 4 | * 5 | * This file is part of FFmpeg. 6 | * 7 | * FFmpeg is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * FFmpeg is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with FFmpeg; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | /* Include only the enabled headers since some compilers (namely, Sun 28 | Studio) will not omit unused inline functions and create undefined 29 | references to libraries that are not being built. */ 30 | 31 | #include "logjam.h" 32 | #include "config.h" 33 | #include "libavformat/avformat.h" 34 | #include "libavfilter/avfilter.h" 35 | #include "libavdevice/avdevice.h" 36 | #include "libswscale/swscale.h" 37 | #include "libpostproc/postprocess.h" 38 | #include "libavutil/avstring.h" 39 | #include "libavutil/mathematics.h" 40 | #include "libavutil/parseutils.h" 41 | #include "libavutil/pixdesc.h" 42 | #include "libavutil/eval.h" 43 | #include "libavutil/dict.h" 44 | #include "libavutil/opt.h" 45 | #include "cmdutils.h" 46 | #include "version.h" 47 | #if CONFIG_NETWORK 48 | #include "libavformat/network.h" 49 | #endif 50 | #if HAVE_SYS_RESOURCE_H 51 | #include 52 | #endif 53 | 54 | struct SwsContext *sws_opts; 55 | AVDictionary *format_opts, *codec_opts; 56 | 57 | static const int this_year = 2012; 58 | 59 | static FILE *report_file; 60 | 61 | void init_opts(void) 62 | { 63 | #if CONFIG_SWSCALE 64 | sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); 65 | #endif 66 | } 67 | 68 | void uninit_opts(void) 69 | { 70 | #if CONFIG_SWSCALE 71 | sws_freeContext(sws_opts); 72 | sws_opts = NULL; 73 | #endif 74 | av_dict_free(&format_opts); 75 | av_dict_free(&codec_opts); 76 | } 77 | 78 | void log_callback_help(void* ptr, int level, const char* fmt, va_list vl) 79 | { 80 | vfprintf(stdout, fmt, vl); 81 | } 82 | 83 | static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl) 84 | { 85 | va_list vl2; 86 | char line[1024]; 87 | static int print_prefix = 1; 88 | 89 | va_copy(vl2, vl); 90 | av_log_default_callback(ptr, level, fmt, vl); 91 | av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix); 92 | va_end(vl2); 93 | fputs(line, report_file); 94 | fflush(report_file); 95 | } 96 | 97 | double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max) 98 | { 99 | char *tail; 100 | const char *error; 101 | double d = av_strtod(numstr, &tail); 102 | if (*tail) 103 | error= "Expected number for %s but found: %s\n"; 104 | else if (d < min || d > max) 105 | error= "The value for %s was %s which is not within %f - %f\n"; 106 | else if(type == OPT_INT64 && (int64_t)d != d) 107 | error= "Expected int64 for %s but found %s\n"; 108 | else if (type == OPT_INT && (int)d != d) 109 | error= "Expected int for %s but found %s\n"; 110 | else 111 | return d; 112 | LOGE( error, context, numstr, min, max); 113 | exit_program(1); 114 | return 0; 115 | } 116 | 117 | int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration) 118 | { 119 | int64_t us; 120 | if (av_parse_time(&us, timestr, is_duration) < 0) { 121 | LOGE( "Invalid %s specification for %s: %s\n", 122 | is_duration ? "duration" : "date", context, timestr); 123 | exit_program(1); 124 | } 125 | return us; 126 | } 127 | 128 | void show_help_options(const OptionDef *options, const char *msg, int mask, int value) 129 | { 130 | const OptionDef *po; 131 | int first; 132 | 133 | first = 1; 134 | for(po = options; po->name != NULL; po++) { 135 | char buf[64]; 136 | if ((po->flags & mask) == value) { 137 | if (first) { 138 | printf("%s", msg); 139 | first = 0; 140 | } 141 | av_strlcpy(buf, po->name, sizeof(buf)); 142 | if (po->flags & HAS_ARG) { 143 | av_strlcat(buf, " ", sizeof(buf)); 144 | av_strlcat(buf, po->argname, sizeof(buf)); 145 | } 146 | printf("-%-17s %s\n", buf, po->help); 147 | } 148 | } 149 | } 150 | 151 | void show_help_children(const AVClass *class, int flags) 152 | { 153 | const AVClass *child = NULL; 154 | av_opt_show2(&class, NULL, flags, 0); 155 | printf("\n"); 156 | 157 | while (child = av_opt_child_class_next(class, child)) 158 | show_help_children(child, flags); 159 | } 160 | 161 | static const OptionDef* find_option(const OptionDef *po, const char *name){ 162 | const char *p = strchr(name, ':'); 163 | int len = p ? p - name : strlen(name); 164 | 165 | while (po->name != NULL) { 166 | if (!strncmp(name, po->name, len) && strlen(po->name) == len) 167 | break; 168 | po++; 169 | } 170 | return po; 171 | } 172 | 173 | #if defined(_WIN32) && !defined(__MINGW32CE__) 174 | #include 175 | /* Will be leaked on exit */ 176 | static char** win32_argv_utf8 = NULL; 177 | static int win32_argc = 0; 178 | 179 | /** 180 | * Prepare command line arguments for executable. 181 | * For Windows - perform wide-char to UTF-8 conversion. 182 | * Input arguments should be main() function arguments. 183 | * @param argc_ptr Arguments number (including executable) 184 | * @param argv_ptr Arguments list. 185 | */ 186 | static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) 187 | { 188 | char *argstr_flat; 189 | wchar_t **argv_w; 190 | int i, buffsize = 0, offset = 0; 191 | 192 | if (win32_argv_utf8) { 193 | *argc_ptr = win32_argc; 194 | *argv_ptr = win32_argv_utf8; 195 | return; 196 | } 197 | 198 | win32_argc = 0; 199 | argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc); 200 | if (win32_argc <= 0 || !argv_w) 201 | return; 202 | 203 | /* determine the UTF-8 buffer size (including NULL-termination symbols) */ 204 | for (i = 0; i < win32_argc; i++) 205 | buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, 206 | NULL, 0, NULL, NULL); 207 | 208 | win32_argv_utf8 = av_mallocz(sizeof(char*) * (win32_argc + 1) + buffsize); 209 | argstr_flat = (char*)win32_argv_utf8 + sizeof(char*) * (win32_argc + 1); 210 | if (win32_argv_utf8 == NULL) { 211 | LocalFree(argv_w); 212 | return; 213 | } 214 | 215 | for (i = 0; i < win32_argc; i++) { 216 | win32_argv_utf8[i] = &argstr_flat[offset]; 217 | offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, 218 | &argstr_flat[offset], 219 | buffsize - offset, NULL, NULL); 220 | } 221 | win32_argv_utf8[i] = NULL; 222 | LocalFree(argv_w); 223 | 224 | *argc_ptr = win32_argc; 225 | *argv_ptr = win32_argv_utf8; 226 | } 227 | #else 228 | static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) 229 | { 230 | /* nothing to do */ 231 | } 232 | #endif /* WIN32 && !__MINGW32CE__ */ 233 | 234 | 235 | int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options) 236 | { 237 | const OptionDef *po; 238 | int bool_val = 1; 239 | int *dstcount; 240 | void *dst; 241 | 242 | po = find_option(options, opt); 243 | if (!po->name && opt[0] == 'n' && opt[1] == 'o') { 244 | /* handle 'no' bool option */ 245 | po = find_option(options, opt + 2); 246 | if (!(po->name && (po->flags & OPT_BOOL))) 247 | goto unknown_opt; 248 | bool_val = 0; 249 | } 250 | if (!po->name) 251 | po = find_option(options, "default"); 252 | if (!po->name) { 253 | unknown_opt: 254 | LOGE( "Unrecognized option '%s'\n", opt); 255 | return AVERROR(EINVAL); 256 | } 257 | if (po->flags & HAS_ARG && !arg) { 258 | LOGE( "Missing argument for option '%s'\n", opt); 259 | return AVERROR(EINVAL); 260 | } 261 | 262 | /* new-style options contain an offset into optctx, old-style address of 263 | * a global var*/ 264 | dst = po->flags & (OPT_OFFSET|OPT_SPEC) ? (uint8_t*)optctx + po->u.off : po->u.dst_ptr; 265 | 266 | if (po->flags & OPT_SPEC) { 267 | SpecifierOpt **so = dst; 268 | char *p = strchr(opt, ':'); 269 | 270 | dstcount = (int*)(so + 1); 271 | *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1); 272 | (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : ""); 273 | dst = &(*so)[*dstcount - 1].u; 274 | } 275 | 276 | if (po->flags & OPT_STRING) { 277 | char *str; 278 | str = av_strdup(arg); 279 | *(char**)dst = str; 280 | } else if (po->flags & OPT_BOOL) { 281 | *(int*)dst = bool_val; 282 | } else if (po->flags & OPT_INT) { 283 | *(int*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); 284 | } else if (po->flags & OPT_INT64) { 285 | *(int64_t*)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); 286 | } else if (po->flags & OPT_TIME) { 287 | *(int64_t*)dst = parse_time_or_die(opt, arg, 1); 288 | } else if (po->flags & OPT_FLOAT) { 289 | *(float*)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); 290 | } else if (po->flags & OPT_DOUBLE) { 291 | *(double*)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY); 292 | } else if (po->u.func_arg) { 293 | int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) : 294 | po->u.func_arg(opt, arg); 295 | if (ret < 0) { 296 | LOGE( "Failed to set value '%s' for option '%s'\n", arg, opt); 297 | return ret; 298 | } 299 | } 300 | if (po->flags & OPT_EXIT) 301 | exit_program(0); 302 | return !!(po->flags & HAS_ARG); 303 | } 304 | 305 | void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, 306 | void (* parse_arg_function)(void *, const char*)) 307 | { 308 | const char *opt; 309 | int optindex, handleoptions = 1, ret; 310 | 311 | /* perform system-dependent conversions for arguments list */ 312 | prepare_app_arguments(&argc, &argv); 313 | 314 | /* parse options */ 315 | optindex = 1; 316 | while (optindex < argc) { 317 | opt = argv[optindex++]; 318 | 319 | if (handleoptions && opt[0] == '-' && opt[1] != '\0') { 320 | if (opt[1] == '-' && opt[2] == '\0') { 321 | handleoptions = 0; 322 | continue; 323 | } 324 | opt++; 325 | 326 | if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) 327 | exit_program(1); 328 | optindex += ret; 329 | } else { 330 | if (parse_arg_function) 331 | parse_arg_function(optctx, opt); 332 | } 333 | } 334 | } 335 | 336 | /* 337 | * Return index of option opt in argv or 0 if not found. 338 | */ 339 | static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname) 340 | { 341 | const OptionDef *po; 342 | int i; 343 | 344 | for (i = 1; i < argc; i++) { 345 | const char *cur_opt = argv[i]; 346 | 347 | if (*cur_opt++ != '-') 348 | continue; 349 | 350 | po = find_option(options, cur_opt); 351 | if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o') 352 | po = find_option(options, cur_opt + 2); 353 | 354 | if ((!po->name && !strcmp(cur_opt, optname)) || 355 | (po->name && !strcmp(optname, po->name))) 356 | return i; 357 | 358 | if (!po || po->flags & HAS_ARG) 359 | i++; 360 | } 361 | return 0; 362 | } 363 | 364 | static void dump_argument(const char *a) 365 | { 366 | const unsigned char *p; 367 | 368 | for (p = a; *p; p++) 369 | if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') || 370 | *p == '_' || (*p >= 'a' && *p <= 'z'))) 371 | break; 372 | if (!*p) { 373 | fputs(a, report_file); 374 | return; 375 | } 376 | fputc('"', report_file); 377 | for (p = a; *p; p++) { 378 | if (*p == '\\' || *p == '"' || *p == '$' || *p == '`') 379 | fprintf(report_file, "\\%c", *p); 380 | else if (*p < ' ' || *p > '~') 381 | fprintf(report_file, "\\x%02x", *p); 382 | else 383 | fputc(*p, report_file); 384 | } 385 | fputc('"', report_file); 386 | } 387 | 388 | void parse_loglevel(int argc, char **argv, const OptionDef *options) 389 | { 390 | int idx = locate_option(argc, argv, options, "loglevel"); 391 | if (!idx) 392 | idx = locate_option(argc, argv, options, "v"); 393 | if (idx && argv[idx + 1]) 394 | opt_loglevel("loglevel", argv[idx + 1]); 395 | idx = locate_option(argc, argv, options, "report"); 396 | if (idx || getenv("FFREPORT")) { 397 | opt_report("report"); 398 | if (report_file) { 399 | int i; 400 | fprintf(report_file, "Command line:\n"); 401 | for (i = 0; i < argc; i++) { 402 | dump_argument(argv[i]); 403 | fputc(i < argc - 1 ? ' ' : '\n', report_file); 404 | } 405 | fflush(report_file); 406 | } 407 | } 408 | } 409 | 410 | #define FLAGS(o) ((o)->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 411 | int opt_default(const char *opt, const char *arg) 412 | { 413 | const AVOption *oc, *of, *os; 414 | char opt_stripped[128]; 415 | const char *p; 416 | const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc; 417 | 418 | if (!(p = strchr(opt, ':'))) 419 | p = opt + strlen(opt); 420 | av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1)); 421 | 422 | if ((oc = av_opt_find(&cc, opt_stripped, NULL, 0, AV_OPT_SEARCH_CHILDREN|AV_OPT_SEARCH_FAKE_OBJ)) || 423 | ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && 424 | (oc = av_opt_find(&cc, opt+1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) 425 | av_dict_set(&codec_opts, opt, arg, FLAGS(oc)); 426 | if ((of = av_opt_find(&fc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) 427 | av_dict_set(&format_opts, opt, arg, FLAGS(of)); 428 | #if CONFIG_SWSCALE 429 | sc = sws_get_class(); 430 | if ((os = av_opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { 431 | // XXX we only support sws_flags, not arbitrary sws options 432 | int ret = av_opt_set(sws_opts, opt, arg, 0); 433 | if (ret < 0) { 434 | LOGE( "Error setting option %s.\n", opt); 435 | return ret; 436 | } 437 | } 438 | #endif 439 | 440 | if (oc || of || os) 441 | return 0; 442 | LOGE( "Unrecognized option '%s'\n", opt); 443 | return AVERROR_OPTION_NOT_FOUND; 444 | } 445 | 446 | int opt_loglevel(const char *opt, const char *arg) 447 | { 448 | const struct { const char *name; int level; } log_levels[] = { 449 | { "quiet" , AV_LOG_QUIET }, 450 | { "panic" , AV_LOG_PANIC }, 451 | { "fatal" , AV_LOG_FATAL }, 452 | { "error" , AV_LOG_ERROR }, 453 | { "warning", AV_LOG_WARNING }, 454 | { "info" , AV_LOG_INFO }, 455 | { "verbose", AV_LOG_VERBOSE }, 456 | { "debug" , AV_LOG_DEBUG }, 457 | }; 458 | char *tail; 459 | int level; 460 | int i; 461 | 462 | for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) { 463 | if (!strcmp(log_levels[i].name, arg)) { 464 | av_log_set_level(log_levels[i].level); 465 | return 0; 466 | } 467 | } 468 | 469 | level = strtol(arg, &tail, 10); 470 | if (*tail) { 471 | LOGE( "Invalid loglevel \"%s\". " 472 | "Possible levels are numbers or:\n", arg); 473 | for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) 474 | LOGE( "\"%s\"\n", log_levels[i].name); 475 | exit_program(1); 476 | } 477 | av_log_set_level(level); 478 | return 0; 479 | } 480 | 481 | int opt_report(const char *opt) 482 | { 483 | char filename[64]; 484 | time_t now; 485 | struct tm *tm; 486 | 487 | if (report_file) /* already opened */ 488 | return 0; 489 | time(&now); 490 | tm = localtime(&now); 491 | snprintf(filename, sizeof(filename), "%s-%04d%02d%02d-%02d%02d%02d.log", 492 | program_name, 493 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 494 | tm->tm_hour, tm->tm_min, tm->tm_sec); 495 | report_file = fopen(filename, "w"); 496 | if (!report_file) { 497 | LOGE( "Failed to open report \"%s\": %s\n", 498 | filename, strerror(errno)); 499 | return AVERROR(errno); 500 | } 501 | av_log_set_callback(log_callback_report); 502 | LOGI( 503 | "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n" 504 | "Report written to \"%s\"\n", 505 | program_name, 506 | tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 507 | tm->tm_hour, tm->tm_min, tm->tm_sec, 508 | filename); 509 | av_log_set_level(FFMAX(av_log_get_level(), AV_LOG_VERBOSE)); 510 | return 0; 511 | } 512 | 513 | int opt_codec_debug(const char *opt, const char *arg) 514 | { 515 | av_log_set_level(AV_LOG_DEBUG); 516 | return opt_default(opt, arg); 517 | } 518 | 519 | int opt_timelimit(const char *opt, const char *arg) 520 | { 521 | #if HAVE_SETRLIMIT 522 | int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX); 523 | struct rlimit rl = { lim, lim + 1 }; 524 | if (setrlimit(RLIMIT_CPU, &rl)) 525 | perror("setrlimit"); 526 | #else 527 | LOGW( "-%s not implemented on this OS\n", opt); 528 | #endif 529 | return 0; 530 | } 531 | 532 | void print_error(const char *filename, int err) 533 | { 534 | char errbuf[128]; 535 | const char *errbuf_ptr = errbuf; 536 | 537 | if (av_strerror(err, errbuf, sizeof(errbuf)) < 0) 538 | errbuf_ptr = strerror(AVUNERROR(err)); 539 | LOGE( "%s: %s\n", filename, errbuf_ptr); 540 | } 541 | 542 | static int warned_cfg = 0; 543 | 544 | #define INDENT 1 545 | #define SHOW_VERSION 2 546 | #define SHOW_CONFIG 4 547 | 548 | #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \ 549 | if (CONFIG_##LIBNAME) { \ 550 | const char *indent = flags & INDENT? " " : ""; \ 551 | if (flags & SHOW_VERSION) { \ 552 | unsigned int version = libname##_version(); \ 553 | LOGI( "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n",\ 554 | indent, #libname, \ 555 | LIB##LIBNAME##_VERSION_MAJOR, \ 556 | LIB##LIBNAME##_VERSION_MINOR, \ 557 | LIB##LIBNAME##_VERSION_MICRO, \ 558 | version >> 16, version >> 8 & 0xff, version & 0xff); \ 559 | } \ 560 | if (flags & SHOW_CONFIG) { \ 561 | const char *cfg = libname##_configuration(); \ 562 | if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \ 563 | if (!warned_cfg) { \ 564 | LOGI( \ 565 | "%sWARNING: library configuration mismatch\n", \ 566 | indent); \ 567 | warned_cfg = 1; \ 568 | } \ 569 | LOGI( "%s%-11s configuration: %s\n", \ 570 | indent, #libname, cfg); \ 571 | } \ 572 | } \ 573 | } \ 574 | 575 | static void print_all_libs_info(int flags, int level) 576 | { 577 | PRINT_LIB_INFO(avutil, AVUTIL, flags, level); 578 | PRINT_LIB_INFO(avcodec, AVCODEC, flags, level); 579 | PRINT_LIB_INFO(avformat, AVFORMAT, flags, level); 580 | PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level); 581 | PRINT_LIB_INFO(avfilter, AVFILTER, flags, level); 582 | PRINT_LIB_INFO(swscale, SWSCALE, flags, level); 583 | PRINT_LIB_INFO(postproc, POSTPROC, flags, level); 584 | } 585 | 586 | void show_banner(int argc, char **argv, const OptionDef *options) 587 | { 588 | int idx = locate_option(argc, argv, options, "version"); 589 | if (idx) 590 | return; 591 | 592 | LOGI( "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n", 593 | program_name, program_birth_year, this_year); 594 | LOGI( " built on %s %s with %s %s\n", 595 | __DATE__, __TIME__, CC_TYPE, CC_VERSION); 596 | LOGI( " configuration: " FFMPEG_CONFIGURATION "\n"); 597 | print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO); 598 | print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO); 599 | } 600 | 601 | int opt_version(const char *opt, const char *arg) { 602 | av_log_set_callback(log_callback_help); 603 | printf("%s " FFMPEG_VERSION "\n", program_name); 604 | print_all_libs_info(SHOW_VERSION, AV_LOG_INFO); 605 | return 0; 606 | } 607 | 608 | int opt_license(const char *opt, const char *arg) 609 | { 610 | printf( 611 | #if CONFIG_NONFREE 612 | "This version of %s has nonfree parts compiled in.\n" 613 | "Therefore it is not legally redistributable.\n", 614 | program_name 615 | #elif CONFIG_GPLV3 616 | "%s is free software; you can redistribute it and/or modify\n" 617 | "it under the terms of the GNU General Public License as published by\n" 618 | "the Free Software Foundation; either version 3 of the License, or\n" 619 | "(at your option) any later version.\n" 620 | "\n" 621 | "%s is distributed in the hope that it will be useful,\n" 622 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 623 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 624 | "GNU General Public License for more details.\n" 625 | "\n" 626 | "You should have received a copy of the GNU General Public License\n" 627 | "along with %s. If not, see .\n", 628 | program_name, program_name, program_name 629 | #elif CONFIG_GPL 630 | "%s is free software; you can redistribute it and/or modify\n" 631 | "it under the terms of the GNU General Public License as published by\n" 632 | "the Free Software Foundation; either version 2 of the License, or\n" 633 | "(at your option) any later version.\n" 634 | "\n" 635 | "%s is distributed in the hope that it will be useful,\n" 636 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 637 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 638 | "GNU General Public License for more details.\n" 639 | "\n" 640 | "You should have received a copy of the GNU General Public License\n" 641 | "along with %s; if not, write to the Free Software\n" 642 | "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", 643 | program_name, program_name, program_name 644 | #elif CONFIG_LGPLV3 645 | "%s is free software; you can redistribute it and/or modify\n" 646 | "it under the terms of the GNU Lesser General Public License as published by\n" 647 | "the Free Software Foundation; either version 3 of the License, or\n" 648 | "(at your option) any later version.\n" 649 | "\n" 650 | "%s is distributed in the hope that it will be useful,\n" 651 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 652 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 653 | "GNU Lesser General Public License for more details.\n" 654 | "\n" 655 | "You should have received a copy of the GNU Lesser General Public License\n" 656 | "along with %s. If not, see .\n", 657 | program_name, program_name, program_name 658 | #else 659 | "%s is free software; you can redistribute it and/or\n" 660 | "modify it under the terms of the GNU Lesser General Public\n" 661 | "License as published by the Free Software Foundation; either\n" 662 | "version 2.1 of the License, or (at your option) any later version.\n" 663 | "\n" 664 | "%s is distributed in the hope that it will be useful,\n" 665 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 666 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" 667 | "Lesser General Public License for more details.\n" 668 | "\n" 669 | "You should have received a copy of the GNU Lesser General Public\n" 670 | "License along with %s; if not, write to the Free Software\n" 671 | "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n", 672 | program_name, program_name, program_name 673 | #endif 674 | ); 675 | return 0; 676 | } 677 | 678 | int opt_formats(const char *opt, const char *arg) 679 | { 680 | AVInputFormat *ifmt=NULL; 681 | AVOutputFormat *ofmt=NULL; 682 | const char *last_name; 683 | 684 | printf( 685 | "File formats:\n" 686 | " D. = Demuxing supported\n" 687 | " .E = Muxing supported\n" 688 | " --\n"); 689 | last_name= "000"; 690 | for(;;){ 691 | int decode=0; 692 | int encode=0; 693 | const char *name=NULL; 694 | const char *long_name=NULL; 695 | 696 | while((ofmt= av_oformat_next(ofmt))) { 697 | if((name == NULL || strcmp(ofmt->name, name)<0) && 698 | strcmp(ofmt->name, last_name)>0){ 699 | name= ofmt->name; 700 | long_name= ofmt->long_name; 701 | encode=1; 702 | } 703 | } 704 | while((ifmt= av_iformat_next(ifmt))) { 705 | if((name == NULL || strcmp(ifmt->name, name)<0) && 706 | strcmp(ifmt->name, last_name)>0){ 707 | name= ifmt->name; 708 | long_name= ifmt->long_name; 709 | encode=0; 710 | } 711 | if(name && strcmp(ifmt->name, name)==0) 712 | decode=1; 713 | } 714 | if(name==NULL) 715 | break; 716 | last_name= name; 717 | 718 | printf( 719 | " %s%s %-15s %s\n", 720 | decode ? "D":" ", 721 | encode ? "E":" ", 722 | name, 723 | long_name ? long_name:" "); 724 | } 725 | return 0; 726 | } 727 | 728 | int opt_codecs(const char *opt, const char *arg) 729 | { 730 | AVCodec *p=NULL, *p2; 731 | const char *last_name; 732 | printf( 733 | "Codecs:\n" 734 | " D..... = Decoding supported\n" 735 | " .E.... = Encoding supported\n" 736 | " ..V... = Video codec\n" 737 | " ..A... = Audio codec\n" 738 | " ..S... = Subtitle codec\n" 739 | " ...S.. = Supports draw_horiz_band\n" 740 | " ....D. = Supports direct rendering method 1\n" 741 | " .....T = Supports weird frame truncation\n" 742 | " ------\n"); 743 | last_name= "000"; 744 | for(;;){ 745 | int decode=0; 746 | int encode=0; 747 | int cap=0; 748 | const char *type_str; 749 | 750 | p2=NULL; 751 | while((p= av_codec_next(p))) { 752 | if((p2==NULL || strcmp(p->name, p2->name)<0) && 753 | strcmp(p->name, last_name)>0){ 754 | p2= p; 755 | decode= encode= cap=0; 756 | } 757 | if(p2 && strcmp(p->name, p2->name)==0){ 758 | if(p->decode) decode=1; 759 | if(p->encode) encode=1; 760 | cap |= p->capabilities; 761 | } 762 | } 763 | if(p2==NULL) 764 | break; 765 | last_name= p2->name; 766 | 767 | switch(p2->type) { 768 | case AVMEDIA_TYPE_VIDEO: 769 | type_str = "V"; 770 | break; 771 | case AVMEDIA_TYPE_AUDIO: 772 | type_str = "A"; 773 | break; 774 | case AVMEDIA_TYPE_SUBTITLE: 775 | type_str = "S"; 776 | break; 777 | default: 778 | type_str = "?"; 779 | break; 780 | } 781 | printf( 782 | " %s%s%s%s%s%s %-15s %s", 783 | decode ? "D": (/*p2->decoder ? "d":*/" "), 784 | encode ? "E":" ", 785 | type_str, 786 | cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ", 787 | cap & CODEC_CAP_DR1 ? "D":" ", 788 | cap & CODEC_CAP_TRUNCATED ? "T":" ", 789 | p2->name, 790 | p2->long_name ? p2->long_name : ""); 791 | /* if(p2->decoder && decode==0) 792 | printf(" use %s for decoding", p2->decoder->name);*/ 793 | printf("\n"); 794 | } 795 | printf("\n"); 796 | printf( 797 | "Note, the names of encoders and decoders do not always match, so there are\n" 798 | "several cases where the above table shows encoder only or decoder only entries\n" 799 | "even though both encoding and decoding are supported. For example, the h263\n" 800 | "decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" 801 | "worse.\n"); 802 | return 0; 803 | } 804 | 805 | int opt_bsfs(const char *opt, const char *arg) 806 | { 807 | AVBitStreamFilter *bsf=NULL; 808 | 809 | printf("Bitstream filters:\n"); 810 | while((bsf = av_bitstream_filter_next(bsf))) 811 | printf("%s\n", bsf->name); 812 | printf("\n"); 813 | return 0; 814 | } 815 | 816 | int opt_protocols(const char *opt, const char *arg) 817 | { 818 | URLProtocol *up=NULL; 819 | 820 | printf("Supported file protocols:\n" 821 | "I.. = Input supported\n" 822 | ".O. = Output supported\n" 823 | "..S = Seek supported\n" 824 | "FLAGS NAME\n" 825 | "----- \n"); 826 | while((up = av_protocol_next(up))) 827 | printf("%c%c%c %s\n", 828 | up->url_read ? 'I' : '.', 829 | up->url_write ? 'O' : '.', 830 | up->url_seek ? 'S' : '.', 831 | up->name); 832 | return 0; 833 | } 834 | 835 | int opt_filters(const char *opt, const char *arg) 836 | { 837 | AVFilter av_unused(**filter) = NULL; 838 | 839 | printf("Filters:\n"); 840 | #if CONFIG_AVFILTER 841 | while ((filter = av_filter_next(filter)) && *filter) 842 | printf("%-16s %s\n", (*filter)->name, (*filter)->description); 843 | #endif 844 | return 0; 845 | } 846 | 847 | int opt_pix_fmts(const char *opt, const char *arg) 848 | { 849 | enum PixelFormat pix_fmt; 850 | 851 | printf( 852 | "Pixel formats:\n" 853 | "I.... = Supported Input format for conversion\n" 854 | ".O... = Supported Output format for conversion\n" 855 | "..H.. = Hardware accelerated format\n" 856 | "...P. = Paletted format\n" 857 | "....B = Bitstream format\n" 858 | "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n" 859 | "-----\n"); 860 | 861 | #if !CONFIG_SWSCALE 862 | # define sws_isSupportedInput(x) 0 863 | # define sws_isSupportedOutput(x) 0 864 | #endif 865 | 866 | for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) { 867 | const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; 868 | if(!pix_desc->name) 869 | continue; 870 | printf("%c%c%c%c%c %-16s %d %2d\n", 871 | sws_isSupportedInput (pix_fmt) ? 'I' : '.', 872 | sws_isSupportedOutput(pix_fmt) ? 'O' : '.', 873 | pix_desc->flags & PIX_FMT_HWACCEL ? 'H' : '.', 874 | pix_desc->flags & PIX_FMT_PAL ? 'P' : '.', 875 | pix_desc->flags & PIX_FMT_BITSTREAM ? 'B' : '.', 876 | pix_desc->name, 877 | pix_desc->nb_components, 878 | av_get_bits_per_pixel(pix_desc)); 879 | } 880 | return 0; 881 | } 882 | 883 | int show_sample_fmts(const char *opt, const char *arg) 884 | { 885 | int i; 886 | char fmt_str[128]; 887 | for (i = -1; i < AV_SAMPLE_FMT_NB; i++) 888 | printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); 889 | return 0; 890 | } 891 | 892 | int read_yesno(void) 893 | { 894 | int c = getchar(); 895 | int yesno = (toupper(c) == 'Y'); 896 | 897 | while (c != '\n' && c != EOF) 898 | c = getchar(); 899 | 900 | return yesno; 901 | } 902 | 903 | int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) 904 | { 905 | int ret; 906 | FILE *f = fopen(filename, "rb"); 907 | 908 | if (!f) { 909 | LOGE( "Cannot read file '%s': %s\n", filename, strerror(errno)); 910 | return AVERROR(errno); 911 | } 912 | fseek(f, 0, SEEK_END); 913 | *size = ftell(f); 914 | fseek(f, 0, SEEK_SET); 915 | *bufptr = av_malloc(*size + 1); 916 | if (!*bufptr) { 917 | LOGE( "Could not allocate file buffer\n"); 918 | fclose(f); 919 | return AVERROR(ENOMEM); 920 | } 921 | ret = fread(*bufptr, 1, *size, f); 922 | if (ret < *size) { 923 | av_free(*bufptr); 924 | if (ferror(f)) { 925 | LOGE( "Error while reading file '%s': %s\n", 926 | filename, strerror(errno)); 927 | ret = AVERROR(errno); 928 | } else 929 | ret = AVERROR_EOF; 930 | } else { 931 | ret = 0; 932 | (*bufptr)[*size++] = '\0'; 933 | } 934 | 935 | fclose(f); 936 | return ret; 937 | } 938 | 939 | FILE *get_preset_file(char *filename, size_t filename_size, 940 | const char *preset_name, int is_path, const char *codec_name) 941 | { 942 | FILE *f = NULL; 943 | int i; 944 | const char *base[3]= { getenv("FFMPEG_DATADIR"), 945 | getenv("HOME"), 946 | FFMPEG_DATADIR, 947 | }; 948 | 949 | if (is_path) { 950 | av_strlcpy(filename, preset_name, filename_size); 951 | f = fopen(filename, "r"); 952 | } else { 953 | #ifdef _WIN32 954 | char datadir[MAX_PATH], *ls; 955 | base[2] = NULL; 956 | 957 | if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1)) 958 | { 959 | for (ls = datadir; ls < datadir + strlen(datadir); ls++) 960 | if (*ls == '\\') *ls = '/'; 961 | 962 | if (ls = strrchr(datadir, '/')) 963 | { 964 | *ls = 0; 965 | strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir)); 966 | base[2] = datadir; 967 | } 968 | } 969 | #endif 970 | for (i = 0; i < 3 && !f; i++) { 971 | if (!base[i]) 972 | continue; 973 | snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name); 974 | f = fopen(filename, "r"); 975 | if (!f && codec_name) { 976 | snprintf(filename, filename_size, 977 | "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name); 978 | f = fopen(filename, "r"); 979 | } 980 | } 981 | } 982 | 983 | return f; 984 | } 985 | 986 | int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) 987 | { 988 | if (*spec <= '9' && *spec >= '0') /* opt:index */ 989 | return strtol(spec, NULL, 0) == st->index; 990 | else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') { /* opt:[vasdt] */ 991 | enum AVMediaType type; 992 | 993 | switch (*spec++) { 994 | case 'v': type = AVMEDIA_TYPE_VIDEO; break; 995 | case 'a': type = AVMEDIA_TYPE_AUDIO; break; 996 | case 's': type = AVMEDIA_TYPE_SUBTITLE; break; 997 | case 'd': type = AVMEDIA_TYPE_DATA; break; 998 | case 't': type = AVMEDIA_TYPE_ATTACHMENT; break; 999 | default: abort(); // never reached, silence warning 1000 | } 1001 | if (type != st->codec->codec_type) 1002 | return 0; 1003 | if (*spec++ == ':') { /* possibly followed by :index */ 1004 | int i, index = strtol(spec, NULL, 0); 1005 | for (i = 0; i < s->nb_streams; i++) 1006 | if (s->streams[i]->codec->codec_type == type && index-- == 0) 1007 | return i == st->index; 1008 | return 0; 1009 | } 1010 | return 1; 1011 | } else if (*spec == 'p' && *(spec + 1) == ':') { 1012 | int prog_id, i, j; 1013 | char *endptr; 1014 | spec += 2; 1015 | prog_id = strtol(spec, &endptr, 0); 1016 | for (i = 0; i < s->nb_programs; i++) { 1017 | if (s->programs[i]->id != prog_id) 1018 | continue; 1019 | 1020 | if (*endptr++ == ':') { 1021 | int stream_idx = strtol(endptr, NULL, 0); 1022 | return (stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes && 1023 | st->index == s->programs[i]->stream_index[stream_idx]); 1024 | } 1025 | 1026 | for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) 1027 | if (st->index == s->programs[i]->stream_index[j]) 1028 | return 1; 1029 | } 1030 | return 0; 1031 | } else if (!*spec) /* empty specifier, matches everything */ 1032 | return 1; 1033 | 1034 | av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec); 1035 | return AVERROR(EINVAL); 1036 | } 1037 | 1038 | AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, AVFormatContext *s, AVStream *st) 1039 | { 1040 | AVDictionary *ret = NULL; 1041 | AVDictionaryEntry *t = NULL; 1042 | int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM; 1043 | char prefix = 0; 1044 | const AVClass *cc = avcodec_get_class(); 1045 | 1046 | if (!codec) 1047 | return NULL; 1048 | 1049 | switch (codec->type) { 1050 | case AVMEDIA_TYPE_VIDEO: prefix = 'v'; flags |= AV_OPT_FLAG_VIDEO_PARAM; break; 1051 | case AVMEDIA_TYPE_AUDIO: prefix = 'a'; flags |= AV_OPT_FLAG_AUDIO_PARAM; break; 1052 | case AVMEDIA_TYPE_SUBTITLE: prefix = 's'; flags |= AV_OPT_FLAG_SUBTITLE_PARAM; break; 1053 | } 1054 | 1055 | while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) { 1056 | char *p = strchr(t->key, ':'); 1057 | 1058 | /* check stream specification in opt name */ 1059 | if (p) 1060 | switch (check_stream_specifier(s, st, p + 1)) { 1061 | case 1: *p = 0; break; 1062 | case 0: continue; 1063 | default: return NULL; 1064 | } 1065 | 1066 | if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || 1067 | (codec && codec->priv_class && av_opt_find(&codec->priv_class, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ))) 1068 | av_dict_set(&ret, t->key, t->value, 0); 1069 | else if (t->key[0] == prefix && av_opt_find(&cc, t->key+1, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ)) 1070 | av_dict_set(&ret, t->key+1, t->value, 0); 1071 | 1072 | if (p) 1073 | *p = ':'; 1074 | } 1075 | return ret; 1076 | } 1077 | 1078 | AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts) 1079 | { 1080 | int i; 1081 | AVDictionary **opts; 1082 | 1083 | if (!s->nb_streams) 1084 | return NULL; 1085 | opts = av_mallocz(s->nb_streams * sizeof(*opts)); 1086 | if (!opts) { 1087 | LOGE( "Could not alloc memory for stream options.\n"); 1088 | return NULL; 1089 | } 1090 | for (i = 0; i < s->nb_streams; i++) 1091 | opts[i] = filter_codec_opts(codec_opts, avcodec_find_decoder(s->streams[i]->codec->codec_id), s, s->streams[i]); 1092 | return opts; 1093 | } 1094 | 1095 | void *grow_array(void *array, int elem_size, int *size, int new_size) 1096 | { 1097 | if (new_size >= INT_MAX / elem_size) { 1098 | LOGE( "Array too big.\n"); 1099 | exit_program(1); 1100 | } 1101 | if (*size < new_size) { 1102 | uint8_t *tmp = av_realloc(array, new_size*elem_size); 1103 | if (!tmp) { 1104 | LOGE( "Could not alloc buffer.\n"); 1105 | exit_program(1); 1106 | } 1107 | memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); 1108 | *size = new_size; 1109 | return tmp; 1110 | } 1111 | return array; 1112 | } 1113 | -------------------------------------------------------------------------------- /Project/jni/videokit/logjam.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGJAM_H 2 | #define LOGJAM_H 3 | 4 | #include 5 | 6 | #define LOGTAG "Videokit" 7 | 8 | #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOGTAG, __VA_ARGS__) 9 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , LOGTAG, __VA_ARGS__) 10 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO , LOGTAG, __VA_ARGS__) 11 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN , LOGTAG, __VA_ARGS__) 12 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR , LOGTAG, __VA_ARGS__) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Project/jni/videokit/uk_co_halfninja_videokit_Videokit.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include "logjam.h" 5 | #include "uk_co_halfninja_videokit_Videokit.h" 6 | 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv); 11 | 12 | JavaVM *sVm = NULL; 13 | 14 | #define LOG_ERROR(message) __android_log_write(ANDROID_LOG_ERROR, "VideoKit", message) 15 | #define LOG_INFO(message) __android_log_write(ANDROID_LOG_INFO, "VideoKit", message) 16 | 17 | jint JNI_OnLoad( JavaVM* vm, void* reserved ) 18 | { 19 | LOG_INFO("Loading native library compiled at " __TIME__ " " __DATE__); 20 | sVm = vm; 21 | return JNI_VERSION_1_6; 22 | } 23 | 24 | JNIEXPORT void JNICALL Java_uk_co_halfninja_videokit_Videokit_run(JNIEnv *env, jobject obj, jobjectArray args) 25 | { 26 | int i = 0; 27 | int argc = 0; 28 | char **argv = NULL; 29 | jstring *strr = NULL; 30 | 31 | if (args != NULL) { 32 | argc = (*env)->GetArrayLength(env, args); 33 | argv = (char **) malloc(sizeof(char *) * argc); 34 | strr = (jstring *) malloc(sizeof(jstring) * argc); 35 | 36 | for(i=0;iGetObjectArrayElement(env, args, i); 39 | argv[i] = (char *)(*env)->GetStringUTFChars(env, strr[i], 0); 40 | } 41 | } 42 | 43 | main(argc, argv); 44 | 45 | for(i=0;iReleaseStringUTFChars(env, strr[i], argv[i]); 48 | } 49 | free(argv); 50 | free(strr); 51 | } 52 | -------------------------------------------------------------------------------- /Project/jni/videokit/uk_co_halfninja_videokit_Videokit.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class uk_co_halfninja_videokit_Videokit */ 4 | 5 | #ifndef _Included_uk_co_halfninja_videokit_Videokit 6 | #define _Included_uk_co_halfninja_videokit_Videokit 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: uk_co_halfninja_videokit_Videokit 12 | * Method: run 13 | * Signature: ([Ljava/lang/String;)V 14 | */ 15 | JNIEXPORT void JNICALL Java_uk_co_halfninja_videokit_Videokit_run 16 | (JNIEnv *, jobject, jobjectArray); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /Project/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /Project/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halfninja/android-ffmpeg-x264/1a4ea88cd9b20db75c29915cf9de56668987db49/Project/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /Project/res/drawable-ldpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halfninja/android-ffmpeg-x264/1a4ea88cd9b20db75c29915cf9de56668987db49/Project/res/drawable-ldpi/icon.png -------------------------------------------------------------------------------- /Project/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halfninja/android-ffmpeg-x264/1a4ea88cd9b20db75c29915cf9de56668987db49/Project/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /Project/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Project/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainActivity 4 | 5 | -------------------------------------------------------------------------------- /Project/src/uk/co/halfninja/videokit/Videokit.java: -------------------------------------------------------------------------------- 1 | package uk.co.halfninja.videokit; 2 | 3 | public final class Videokit { 4 | 5 | static { 6 | System.loadLibrary("videokit"); 7 | } 8 | 9 | public native void run(String[] args); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /ProjectTest/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ProjectTest/.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | libs 4 | obj 5 | local.properties 6 | -------------------------------------------------------------------------------- /ProjectTest/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ProjectTest 4 | 5 | 6 | Project 7 | 8 | 9 | 10 | com.android.ide.eclipse.adt.ResourceManagerBuilder 11 | 12 | 13 | 14 | 15 | com.android.ide.eclipse.adt.PreCompilerBuilder 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javabuilder 21 | 22 | 23 | 24 | 25 | com.android.ide.eclipse.adt.ApkBuilder 26 | 27 | 28 | 29 | 30 | 31 | com.android.ide.eclipse.adt.AndroidNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /ProjectTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | 13 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /ProjectTest/assets/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/halfninja/android-ffmpeg-x264/1a4ea88cd9b20db75c29915cf9de56668987db49/ProjectTest/assets/image.jpg -------------------------------------------------------------------------------- /ProjectTest/build.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked in Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | tested.project.dir=../Project 19 | -------------------------------------------------------------------------------- /ProjectTest/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 54 | 55 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /ProjectTest/default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-8 12 | -------------------------------------------------------------------------------- /ProjectTest/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /ProjectTest/src/uk/co/halfninja/videokit/VideokitTest.java: -------------------------------------------------------------------------------- 1 | package uk.co.halfninja.videokit; 2 | 3 | import java.io.BufferedOutputStream; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.InputStream; 7 | 8 | import android.os.Environment; 9 | import android.test.AndroidTestCase; 10 | import android.test.InstrumentationTestCase; 11 | import android.util.Log; 12 | 13 | public class VideokitTest extends InstrumentationTestCase { 14 | 15 | Videokit vk = new Videokit(); 16 | 17 | public VideokitTest() { 18 | } 19 | 20 | public void testHelpOutput() { 21 | vk.run(new String[]{ 22 | "ffmpeg", "-h" 23 | }); 24 | assertNotNull(vk); 25 | } 26 | 27 | public void testEncode() throws Exception { 28 | File images = new File(Environment.getExternalStorageDirectory(), "fun"); 29 | images.mkdirs(); 30 | for (int i=0; i<10; i++) { 31 | String filename = String.format("snap%04d.jpg", i); 32 | File dest = new File(images, filename); 33 | Log.i("Test", "Adding image at " + dest.getAbsolutePath()); 34 | InputStream is = getInstrumentation().getContext().getAssets().open("image.jpg"); 35 | BufferedOutputStream o = null; 36 | try { 37 | byte[] buff = new byte[10000]; 38 | int read = -1; 39 | o = new BufferedOutputStream(new FileOutputStream(dest), 10000); 40 | while ((read = is.read(buff)) > -1) { 41 | o.write(buff, 0, read); 42 | } 43 | } finally { 44 | is.close(); 45 | if (o != null) o.close(); 46 | 47 | } 48 | } 49 | //videokit.initialise(); 50 | 51 | File file = new File(images.getAbsolutePath(), "snap0000.jpg"); 52 | assertTrue("File exist", file.exists()); 53 | 54 | String input = file.getAbsolutePath(); 55 | Log.i("Test", "Let's set input to " + input); 56 | // videokit.setInputFile(input); 57 | String output = new File(Environment.getExternalStorageDirectory(), "video.mp4").getAbsolutePath(); 58 | Log.i("Test", "Let's set output to " + output); 59 | // videokit.setOutputFile(output); 60 | 61 | vk.run(new String[]{ 62 | "ffmpeg", 63 | "-i", 64 | input, 65 | output 66 | }); 67 | 68 | // videokit.setSize(640,480); 69 | // videokit.setFrameRate(5); 70 | // 71 | // videokit.encode(); 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. Read me first (that's why I'm at the top!) 2 | 3 | I'm not going to be working on this at all for the forseeable future, and I won't have time to answer questions about why it doesn't compile on your platform or has something missing. 4 | 5 | There are a few forks of this project on GitHub where a few people have updated it and improved on the scripts. Check them out! 6 | 7 | h1. Android Videokit 8 | 9 | This is a repository to make it relatively simple to fetch and build the latest FFMPEG and libx264 to run on Android, using the Android NDK. It differs from most of the other NDK FFMPEG building packages in that it uses configure and make to build the libraries, and only a very small Android.mk file to pack it into a shared library, rather than a large handful of custom @Android.mk@ scripts (there are still a few script files but most of them are pretty small or are lists of configure options). Big custom @Android.mk@ files tend to break as soon as any files move around in the FFMPEG project, whereas here it should keep working with the latest libraries. 10 | 11 | There is a skeletal JNI interface - the version here simply supplies run(String[]) which is passed to ffmpeg.c's origin main() function. Once I've got this properly encoding again, I'll make some more convenient methods. 12 | 13 | h2. How to build it 14 | 15 | You'll need to git clone in order to have access to the submodules. You might be able to use a ZIP download but then you'll have to skip the init-submodules step and acquire FFmpeg and x264 from elsewhere; if you do this and something doesn't work then I really can't help you. Use git, it's good! 16 | 17 | First time stuff: 18 | 19 | # Clone using the @--recursive@ switch. (Or clone normally and run @./init-submodules.sh@ to pull in the FFMPEG and libx264 submodules.) 20 | # @cd Project/jni@ 21 | # do @export NDK=~/apps/android-ndk-r5c@ using the actual path of your Android NDK. 22 | # Run @./create_toolchain.sh@ to install a local copy of the standalone toolchain 23 | 24 | Each time the 3rd party libraries change: 25 | 26 | # Run @./config_make_everything.sh@ to configure and make libx264 and FFMPEG. 27 | # @ndk-build@ (make sure the NDK is in your $PATH) 28 | # If all is well, you should find @libs/armeabi/videokit.so@. 29 | 30 | You can edit @jni/videokit/jni_interface.c@ to do whatever you want with the built libraries - if you make any changes to it, just run ndk-build to link it together with the static libraries. 31 | 32 | h2. Options 33 | 34 | * @minimal_featureset@ - on by default - only compiles in a small number of codecs (specifically, JPEG decoding and x264 encoding). Change to 0 in @settings.sh@ if you want everything, or just add whatever configure flags you like to pick the codecs and things that are useful to you. 35 | * If you have already created a standalone toolchain, just edit @settings.sh@ to make the PATH point at its bin directory. Then you don't need to run @create_toolchain.sh@. If you have compilation problems, it's worth making a fresh toolchain in case you're using a slightly older version. 36 | 37 | h2. Updating submodules 38 | 39 | The FFMPEG and X264 submodules will initially be fetched from a specific commit. If you want to try building with the latest, just go into each of those submodules and do a `git pull origin master`. FFMPEG tends to change quite a lot so don't be surprised if it fails to build. If you get it working again with the latest, I'll gladly patch my project with your changes. 40 | -------------------------------------------------------------------------------- /init-submodules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ls -A `dirname $0`/jni/ffmpeg/* 2>&1 1>/dev/null 4 | 5 | if [ $? == 0 ]; then 6 | echo "ffmpeg directory isn't empty. Have you already done this?" 7 | exit 1 8 | fi 9 | 10 | 11 | git submodule init 12 | git config -l 13 | git submodule update 14 | 15 | --------------------------------------------------------------------------------