From: Ali Gholami Rudi Date: Tue, 13 Sep 2011 18:40:22 +0000 (+0430) Subject: let -a and -v choose audio/video stream X-Git-Url: https://repo.or.cz/w/fbff.git/commitdiff_plain/107e93254007229cc5846a393d64a526c6d80550 let -a and -v choose audio/video stream --- diff --git a/README b/README index 54cb5a0..689b9cd 100644 --- a/README +++ b/README @@ -11,8 +11,8 @@ OPTION DESCRIPTION -m x magnify the screen by repeating pixels -j x jump every x video frames; for slow machines -f start full screen --v video only playback --a audio only playback +-v x select video stream; '-' disables video +-a x select audio stream; '-' disables audio -t use time based seeking; only if the default does't work -s don't rely on video framerate; always synchronize -R adjust the video to the right of the screen diff --git a/fbff.c b/fbff.c index 75e2ca4..d083bbd 100644 --- a/fbff.c +++ b/fbff.c @@ -34,8 +34,8 @@ static float zoom = 1; static int magnify = 1; static int jump = 0; static int fullscreen = 0; -static int audio = 1; -static int video = 1; +static int video = 1; /* video stream; 0=none, 1=auto, >2=idx */ +static int audio = 1; /* audio stream; 0=none, 1=auto, >2=idx */ static int just = 0; static int frame_jmp = 1; /* the changes to pos_cur for each frame */ @@ -326,8 +326,8 @@ static char *usage = "usage: fbff [options] file\n" " -m x magnify the screen by repeating pixels\n" " -j x jump every x video frames; for slow machines\n" " -f start full screen\n" - " -v video only playback\n" - " -a audio only playback\n" + " -v x select video stream; '-' disables video\n" + " -a x select audio stream; '-' disables audio\n" " -s always synchronize; useful for files with bad video framerate\n" " -t use time based seeking; only if the default does't work\n" " -R adjust the video to the right of the screen\n\n"; @@ -344,12 +344,12 @@ static void read_args(int argc, char *argv[]) jump = atoi(argv[++i]); if (!strcmp(argv[i], "-f")) fullscreen = 1; - if (!strcmp(argv[i], "-a")) - video = 0; if (!strcmp(argv[i], "-s")) sync_cnt = sync_cur = (1 << 30); if (!strcmp(argv[i], "-v")) - audio = 0; + video = argv[++i][0] == '-' ? 0 : atoi(argv[i]) + 2; + if (!strcmp(argv[i], "-a")) + audio = argv[++i][0] == '-' ? 0 : atoi(argv[i]) + 2; if (!strcmp(argv[i], "-t")) frame_jmp = 1024; if (!strcmp(argv[i], "-h")) @@ -370,9 +370,9 @@ int main(int argc, char *argv[]) } read_args(argc, argv); ffs_globinit(); - if (video && !(vffs = ffs_alloc(path, 1))) + if (video && !(vffs = ffs_alloc(path, FFS_VIDEO | video - 1))) video = 0; - if (audio && !(affs = ffs_alloc(path, 0))) + if (audio && !(affs = ffs_alloc(path, FFS_AUDIO | audio - 1))) audio = 0; if (!video && !audio) return 1; diff --git a/ffs.c b/ffs.c index 6152efd..0033a06 100644 --- a/ffs.c +++ b/ffs.c @@ -25,10 +25,11 @@ struct ffs { AVFrame *tmp; }; -struct ffs *ffs_alloc(char *path, int video) +struct ffs *ffs_alloc(char *path, int flags) { struct ffs *ffs; - int type = video ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO; + int type = flags & FFS_VIDEO ? AVMEDIA_TYPE_VIDEO : AVMEDIA_TYPE_AUDIO; + int idx = (flags & FFS_STRIDX) - 1; ffs = malloc(sizeof(*ffs)); memset(ffs, 0, sizeof(*ffs)); ffs->si = -1; @@ -36,7 +37,7 @@ struct ffs *ffs_alloc(char *path, int video) goto failed; if (av_find_stream_info(ffs->fc) < 0) goto failed; - ffs->si = av_find_best_stream(ffs->fc, type, -1, -1, NULL, 0); + ffs->si = av_find_best_stream(ffs->fc, type, idx, -1, NULL, 0); if (ffs->si < 0) goto failed; ffs->cc = ffs->fc->streams[ffs->si]->codec; diff --git a/ffs.h b/ffs.h index ec40e26..a6f4177 100644 --- a/ffs.h +++ b/ffs.h @@ -1,7 +1,11 @@ +#define FFS_AUDIO 0x1000 +#define FFS_VIDEO 0x2000 +#define FFS_STRIDX 0x0fff + void ffs_globinit(void); /* ffmpeg stream */ -struct ffs *ffs_alloc(char *path, int video); +struct ffs *ffs_alloc(char *path, int flags); void ffs_free(struct ffs *ffs); long ffs_pos(struct ffs *ffs, int diff);