added ffplay utility

Originally committed as revision 1936 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Fabrice Bellard 2003-06-07 18:34:02 +00:00
parent a86b921c7d
commit 01310af292
5 changed files with 1593 additions and 200 deletions

View File

@ -16,18 +16,22 @@ endif
ifeq ($(CONFIG_WIN32),yes)
EXE=.exe
PROG=ffmpeg$(EXE)
else
ifeq ($(CONFIG_OS2),yes)
EXE=.exe
PROG=ffmpeg$(EXE)
else
EXE=
PROG=ffmpeg ffplay
endif
endif
PROG=ffmpeg$(EXE)
ifeq ($(CONFIG_FFSERVER),yes)
PROG+=ffserver
endif
PROG+=ffserver$(EXE)
endif
ifeq ($(CONFIG_FFPLAY),yes)
PROG+=ffplay$(EXE)
endif
ifeq ($(CONFIG_AUDIO_BEOS),yes)
@ -67,7 +71,7 @@ else
TEST=test
endif
OBJS = ffmpeg.o ffserver.o
OBJS = ffmpeg.o ffserver.o cmdutils.o ffplay.o
SRCS = $(OBJS:.o=.c) $(ASM_OBJS:.o=.s)
FFLIBS = -L./libavformat -lavformat -L./libavcodec -lavcodec
@ -77,9 +81,8 @@ lib: $(AMRLIBS)
$(MAKE) -C libavcodec all
$(MAKE) -C libavformat all
ffmpeg_g$(EXE): ffmpeg.o .libs
$(CC) $(LDFLAGS) -o $@ ffmpeg.o $(FFLIBS) $(EXTRALIBS)
ffmpeg_g$(EXE): ffmpeg.o cmdutils.o .libs
$(CC) $(LDFLAGS) -o $@ ffmpeg.o cmdutils.o $(FFLIBS) $(EXTRALIBS)
ffmpeg$(EXE): ffmpeg_g$(EXE)
cp -p $< $@
@ -88,8 +91,15 @@ ffmpeg$(EXE): ffmpeg_g$(EXE)
ffserver$(EXE): ffserver.o .libs
$(CC) $(LDFLAGS) $(FFSLDFLAGS) -o $@ ffserver.o $(FFLIBS) $(EXTRALIBS)
ffplay: ffmpeg$(EXE)
ln -sf $< $@
ffplay_g$(EXE): ffplay.o cmdutils.o .libs
$(CC) $(LDFLAGS) -o $@ ffplay.o cmdutils.o $(FFLIBS) $(EXTRALIBS) $(SDL_LIBS)
ffplay$(EXE): ffplay_g$(EXE)
cp -p $< $@
$(STRIP) $@
ffplay.o: ffplay.c
$(CC) $(CFLAGS) $(SDL_CFLAGS) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
@ -101,7 +111,6 @@ install: all $(INSTALLVHOOK)
$(MAKE) -C libavcodec install
install -d $(prefix)/bin
install -c -s -m 755 $(PROG) $(prefix)/bin
ln -sf ffmpeg $(prefix)/bin/ffplay
install-vhook: $(prefix)/lib/vhook
$(MAKE) -C vhook install INSTDIR=$(prefix)/lib/vhook
@ -133,7 +142,7 @@ clean: $(CLEANVHOOK)
$(MAKE) -C libavcodec clean
$(MAKE) -C libavformat clean
$(MAKE) -C tests clean
rm -f *.o *.d *~ .libs .depend gmon.out TAGS ffmpeg_g$(EXE) $(PROG)
rm -f *.o *.d *~ .libs .depend gmon.out TAGS ffmpeg_g$(EXE) ffplay_g$(EXE) $(PROG)
clean-vhook:
$(MAKE) -C vhook clean

120
cmdutils.c Normal file
View File

@ -0,0 +1,120 @@
/*
* Various utilities for command line tools
* Copyright (c) 2000-2003 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "avformat.h"
#include "cmdutils.h"
void show_help_options(const OptionDef *options)
{
const OptionDef *po;
int i, expert, first;
printf("Main options are:\n");
for(i=0;i<2;i++) {
first = 1;
for(po = options; po->name != NULL; po++) {
char buf[64];
expert = (po->flags & OPT_EXPERT) != 0;
if (expert == i) {
if (expert && first) {
printf("\nAdvanced options are:\n");
first = 0;
}
strcpy(buf, po->name);
if (po->flags & HAS_ARG) {
strcat(buf, " ");
strcat(buf, po->argname);
}
printf("-%-17s %s\n", buf, po->help);
}
}
}
}
void parse_options(int argc, char **argv, const OptionDef *options)
{
const char *opt, *arg;
int optindex;
const OptionDef *po;
/* parse options */
optindex = 1;
while (optindex < argc) {
opt = argv[optindex++];
if (opt[0] == '-' && opt[1] != '\0') {
po = options;
while (po->name != NULL) {
if (!strcmp(opt + 1, po->name))
break;
po++;
}
if (!po->name) {
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
exit(1);
}
arg = NULL;
if (po->flags & HAS_ARG) {
arg = argv[optindex++];
if (!arg) {
fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
exit(1);
}
}
if (po->flags & OPT_STRING) {
char *str;
str = strdup(arg);
*po->u.str_arg = str;
} else if (po->flags & OPT_BOOL) {
*po->u.int_arg = 1;
} else {
po->u.func_arg(arg);
}
} else {
parse_arg_file(opt);
}
}
}
void print_error(const char *filename, int err)
{
switch(err) {
case AVERROR_NUMEXPECTED:
fprintf(stderr, "%s: Incorrect image filename syntax.\n"
"Use '%%d' to specify the image number:\n"
" for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
" for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
filename);
break;
case AVERROR_INVALIDDATA:
fprintf(stderr, "%s: Error while parsing header\n", filename);
break;
case AVERROR_NOFMT:
fprintf(stderr, "%s: Unknown format\n", filename);
break;
default:
fprintf(stderr, "%s: Error while opening file\n", filename);
break;
}
}

25
cmdutils.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef _CMD_UTILS_H
#define _CMD_UTILS_H
typedef struct {
const char *name;
int flags;
#define HAS_ARG 0x0001
#define OPT_BOOL 0x0002
#define OPT_EXPERT 0x0004
#define OPT_STRING 0x0008
union {
void (*func_arg)(const char *);
int *int_arg;
char **str_arg;
} u;
const char *help;
const char *argname;
} OptionDef;
void show_help_options(const OptionDef *options);
void parse_options(int argc, char **argv, const OptionDef *options);
void parse_arg_file(const char *filename);
void print_error(const char *filename, int err);
#endif /* _CMD_UTILS_H */

216
ffmpeg.c
View File

@ -1,6 +1,6 @@
/*
* FFmpeg main
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* Copyright (c) 2000-2003 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -40,28 +40,14 @@
#include <time.h>
#include <ctype.h>
#include "cmdutils.h"
#if !defined(INFINITY) && defined(HUGE_VAL)
#define INFINITY HUGE_VAL
#endif
#define MAXINT64 int64_t_C(0x7fffffffffffffff)
typedef struct {
const char *name;
int flags;
#define HAS_ARG 0x0001
#define OPT_BOOL 0x0002
#define OPT_EXPERT 0x0004
#define OPT_STRING 0x0008
union {
void (*func_arg)(const char *);
int *int_arg;
char **str_arg;
} u;
const char *help;
const char *argname;
} OptionDef;
/* select an input stream for an output stream */
typedef struct AVStreamMap {
int file_index;
@ -133,7 +119,6 @@ static int use_4mv = 0;
static int use_aic = 0;
static int use_umv = 0;
/* /Fx */
static int use_h263p_extra = 0;
static int do_deinterlace = 0;
static int workaround_bugs = FF_BUG_AUTODETECT;
static int error_resilience = 2;
@ -161,7 +146,6 @@ static char *str_copyright = NULL;
static char *str_comment = NULL;
static int do_benchmark = 0;
static int do_hex_dump = 0;
static int do_play = 0;
static int do_psnr = 0;
static int do_vstats = 0;
static int do_pass = 0;
@ -1134,11 +1118,7 @@ static int av_encode(AVFormatContext **output_files,
}
#ifndef CONFIG_WIN32
if (!do_play) {
fprintf(stderr, "Press [q] to stop encoding\n");
} else {
fprintf(stderr, "Press [q] to stop playing\n");
}
fprintf(stderr, "Press [q] to stop encoding\n");
#endif
term_init();
@ -1998,28 +1978,6 @@ static void opt_recording_time(const char *arg)
recording_time = parse_date(arg, 1);
}
static void print_error(const char *filename, int err)
{
switch(err) {
case AVERROR_NUMEXPECTED:
fprintf(stderr, "%s: Incorrect image filename syntax.\n"
"Use '%%d' to specify the image number:\n"
" for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"
" for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",
filename);
break;
case AVERROR_INVALIDDATA:
fprintf(stderr, "%s: Error while parsing header\n", filename);
break;
case AVERROR_NOFMT:
fprintf(stderr, "%s: Unknown format\n", filename);
break;
default:
fprintf(stderr, "%s: Error while opening file\n", filename);
break;
}
}
static void opt_input_file(const char *filename)
{
AVFormatContext *ic;
@ -2524,40 +2482,6 @@ static void prepare_grab(void)
}
}
/* open the necessary output devices for playing */
static void prepare_play(void)
{
int has_video, has_audio;
check_audio_video_inputs(&has_video, &has_audio);
/* manual disable */
if (audio_disable) {
has_audio = 0;
}
if (video_disable) {
has_video = 0;
}
if (has_audio) {
file_oformat = guess_format("audio_device", NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Could not find audio device\n");
exit(1);
}
opt_output_file(audio_device?audio_device:"/dev/dsp");
}
if (has_video) {
file_oformat = guess_format("framebuffer_device", NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Could not find framebuffer device\n");
exit(1);
}
opt_output_file("");
}
}
/* same option as mencoder */
static void opt_pass(const char *pass_str)
{
@ -2668,47 +2592,6 @@ static void show_formats(void)
exit(1);
}
void show_help(void)
{
const char *prog;
const OptionDef *po;
int i, expert;
prog = do_play ? "ffplay" : "ffmpeg";
printf("%s version " FFMPEG_VERSION ", Copyright (c) 2000, 2001, 2002 Fabrice Bellard\n",
prog);
if (!do_play) {
printf("usage: ffmpeg [[options] -i input_file]... {[options] outfile}...\n"
"Hyper fast MPEG1/MPEG4/H263/RV and AC3/MPEG audio encoder\n");
} else {
printf("usage: ffplay [options] input_file...\n"
"Simple audio player\n");
}
printf("\n"
"Main options are:\n");
for(i=0;i<2;i++) {
if (i == 1)
printf("\nAdvanced options are:\n");
for(po = options; po->name != NULL; po++) {
char buf[64];
expert = (po->flags & OPT_EXPERT) != 0;
if (expert == i) {
strcpy(buf, po->name);
if (po->flags & HAS_ARG) {
strcat(buf, " ");
strcat(buf, po->argname);
}
printf("-%-17s %s\n", buf, po->help);
}
}
}
exit(1);
}
const OptionDef options[] = {
{ "L", 0, {(void*)show_licence}, "show license" },
{ "h", 0, {(void*)show_help}, "show help" },
@ -2803,83 +2686,42 @@ const OptionDef options[] = {
{ NULL, },
};
void show_help(void)
{
printf("ffmpeg version " FFMPEG_VERSION ", Copyright (c) 2000, 2001, 2002 Fabrice Bellard\n");
printf("usage: ffmpeg [[options] -i input_file]... {[options] outfile}...\n"
"Hyper fast Audio and Video encoder\n");
printf("\n");
show_help_options(options);
exit(1);
}
void parse_arg_file(const char *filename)
{
opt_output_file(filename);
}
int main(int argc, char **argv)
{
int optindex, i;
const char *opt, *arg;
const OptionDef *po;
int i;
int64_t ti;
av_register_all();
/* detect if invoked as player */
i = strlen(argv[0]);
if (i >= 6 && !strcmp(argv[0] + i - 6, "ffplay"))
do_play = 1;
if (argc <= 1)
show_help();
/* parse options */
optindex = 1;
while (optindex < argc) {
opt = argv[optindex++];
if (opt[0] == '-' && opt[1] != '\0') {
po = options;
while (po->name != NULL) {
if (!strcmp(opt + 1, po->name))
break;
po++;
}
if (!po->name) {
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);
exit(1);
}
arg = NULL;
if (po->flags & HAS_ARG) {
arg = argv[optindex++];
if (!arg) {
fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);
exit(1);
}
}
if (po->flags & OPT_STRING) {
char *str;
str = av_strdup(arg);
*po->u.str_arg = str;
} else if (po->flags & OPT_BOOL) {
*po->u.int_arg = 1;
} else {
po->u.func_arg(arg);
}
} else {
if (!do_play) {
opt_output_file(opt);
} else {
opt_input_file(opt);
}
}
parse_options(argc, argv, options);
/* file converter / grab */
if (nb_output_files <= 0) {
fprintf(stderr, "Must supply at least one output file\n");
exit(1);
}
if (!do_play) {
/* file converter / grab */
if (nb_output_files <= 0) {
fprintf(stderr, "Must supply at least one output file\n");
exit(1);
}
if (nb_input_files == 0) {
prepare_grab();
}
} else {
/* player */
if (nb_input_files <= 0) {
fprintf(stderr, "Must supply at least one input file\n");
exit(1);
}
prepare_play();
if (nb_input_files == 0) {
prepare_grab();
}
ti = getutime();

1397
ffplay.c Normal file

File diff suppressed because it is too large Load Diff