Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
implement ffprobe, fixes #286
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Jan 8, 2020
1 parent ef03a31 commit 7d97477
Show file tree
Hide file tree
Showing 51 changed files with 9,105 additions and 1,250 deletions.
275 changes: 145 additions & 130 deletions android/app/src/main/cpp/fftools_cmdutils.c

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions android/app/src/main/cpp/fftools_cmdutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/

/*
* CHANGES 01.2020
* - ffprobe support changes
* - AV_LOG_STDERR introduced
*
* CHANGES 12.2019
* - Concurrent execution support
*
Expand Down Expand Up @@ -51,22 +55,28 @@
#undef main /* We don't want SDL to override our main() */
#endif

/**
* Defines logs printed to stderr by ffmpeg. They are not filtered and always redirected.
*/
#define AV_LOG_STDERR -16

/**
* program name, defined by the program for show_version().
*/
extern const char program_name[];
extern __thread char *program_name;

/**
* program birth year, defined by the program for show_banner()
*/
extern const int program_birth_year;
extern __thread int program_birth_year;

extern __thread AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
extern __thread AVFormatContext *avformat_opts;
extern __thread AVDictionary *sws_dict;
extern __thread AVDictionary *swr_opts;
extern __thread AVDictionary *format_opts, *codec_opts, *resample_opts;
extern __thread int hide_banner;
extern __thread int find_stream_info;

/**
* Register a program-specific cleanup routine.
Expand Down Expand Up @@ -225,10 +235,11 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags,
void show_help_children(const AVClass *class, int flags);

/**
* Per-fftool specific help handler. Implemented in each
* Per-fftool specific help handlers. Implemented in each
* fftool, called by show_help().
*/
void show_help_default(const char *opt, const char *arg);
void show_help_default_ffmpeg(const char *opt, const char *arg);
void show_help_default_ffprobe(const char *opt, const char *arg);

/**
* Generic -h handler common to all fftools.
Expand Down
39 changes: 21 additions & 18 deletions android/app/src/main/cpp/fftools_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/

/*
* CHANGES 01.2020
* - ffprobe support changes
*
* CHANGES 12.2019
* - Concurrent execution support
*
Expand All @@ -38,10 +41,10 @@
*
* CHANGES 07.2018
* --------------------------------------------------------
* - main() function renamed as execute()
* - main() function renamed as ffmpeg_execute()
* - exit_program() implemented with setjmp
* - extern longjmp_value added to access exit code stored in exit_program()
* - cleanup() method added
* - ffmpeg_var_cleanup() method added
*/

#include "config.h"
Expand Down Expand Up @@ -129,9 +132,6 @@

#include "libavutil/avassert.h"

const char program_name[] = "ffmpeg";
const int program_birth_year = 2000;

static FILE *vstats_file;

const char *const forced_keyframes_const_names[] = {
Expand Down Expand Up @@ -199,7 +199,6 @@ extern int opt_profile(void *optctx, const char *opt, const char *arg);
extern int opt_filter_complex(void *optctx, const char *opt, const char *arg);
extern int opt_filter_complex_script(void *optctx, const char *opt, const char *arg);
extern int opt_attach(void *optctx, const char *opt, const char *arg);
extern __thread int find_stream_info;
extern int opt_video_frames(void *optctx, const char *opt, const char *arg);
extern __thread int intra_only;
extern int opt_video_codec(void *optctx, const char *opt, const char *arg);
Expand Down Expand Up @@ -407,7 +406,7 @@ __thread volatile int received_sigterm = 0;
__thread volatile int received_nb_signals = 0;
__thread atomic_int transcode_init_done = ATOMIC_VAR_INIT(0);
__thread volatile int ffmpeg_exited = 0;
__thread int main_return_code = 0;
__thread int main_ffmpeg_return_code = 0;
extern __thread int longjmp_value;

static void
Expand Down Expand Up @@ -891,7 +890,7 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
ret = av_interleaved_write_frame(s, pkt);
if (ret < 0) {
print_error("av_interleaved_write_frame()", ret);
main_return_code = 1;
main_ffmpeg_return_code = 1;
close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED);
}
av_packet_unref(pkt);
Expand Down Expand Up @@ -2933,7 +2932,7 @@ static void print_sdp(void)
av_sdp_create(avc, j, sdp, sizeof(sdp));

if (!sdp_filename) {
av_log(NULL, AV_LOG_INFO, "SDP:\n%s\n", sdp);
av_log(NULL, AV_LOG_STDERR, "SDP:\n%s\n", sdp);
fflush(stdout);
} else {
if (avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL) < 0) {
Expand Down Expand Up @@ -4995,8 +4994,8 @@ static void log_callback_null(void *ptr, int level, const char *fmt, va_list vl)
{
}

void cleanup() {
main_return_code = 0;
void ffmpeg_var_cleanup() {
main_ffmpeg_return_code = 0;
longjmp_value = 0;
received_sigterm = 0;
received_nb_signals = 0;
Expand Down Expand Up @@ -5035,10 +5034,14 @@ void cancel_operation()
sigterm_handler(SIGINT);
}

__thread OptionDef *global_options = NULL;
__thread OptionDef *ffmpeg_options = NULL;

int execute(int argc, char **argv)
int ffmpeg_execute(int argc, char **argv)
{
char _program_name[] = "ffmpeg";
program_name = (char*)&_program_name;
program_birth_year = 2000;

#define OFFSET(x) offsetof(OptionsContext, x)
OptionDef options[] = {

Expand Down Expand Up @@ -5465,15 +5468,15 @@ int execute(int argc, char **argv)
{ NULL, },
};

global_options = options;
ffmpeg_options = options;

int i, ret;
BenchmarkTimeStamps ti;

int savedCode = setjmp(ex_buf__);
if (savedCode == 0) {

cleanup();
ffmpeg_var_cleanup();

init_dynload();

Expand Down Expand Up @@ -5538,11 +5541,11 @@ int execute(int argc, char **argv)
if ((decode_error_stat[0] + decode_error_stat[1]) * max_error_rate < decode_error_stat[1])
exit_program(69);

exit_program(received_nb_signals ? 255 : main_return_code);
exit_program(received_nb_signals ? 255 : main_ffmpeg_return_code);

} else {
main_return_code = longjmp_value;
main_ffmpeg_return_code = longjmp_value;
}

return main_return_code;
return main_ffmpeg_return_code;
}
4 changes: 3 additions & 1 deletion android/app/src/main/cpp/fftools_ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/

/*
* CHANGES 01.2020
* - ffprobe support changes
*
* CHANGES 12.2019
* - Concurrent execution support
*
Expand Down Expand Up @@ -637,7 +640,6 @@ extern __thread char *qsv_device;
#endif
extern __thread HWDevice *filter_hw_device;


void term_init(void);
void term_exit(void);

Expand Down
Loading

0 comments on commit 7d97477

Please sign in to comment.