提交 d9a916e2 编写于 作者: C Charles Yates 提交者: Michael Niedermayer

stdin patch by (Charles Yates <charles dot yates at pandora dot be>)

* removes use of read_key and getchar when input is received on stdin
(this was corrupting the packet reading)
* terminates av_encode when a termination signal is received (use of
ctrl-c issued a term_exit and subsequent uses of q failed)
* specific correction to yuv4mpeg pipe reading - the defined header was
too short to allow for extended yuv4mpeg flags [as used by smil2yuv and
y4mscaler and accepted by mjpeg tools]

Originally committed as revision 2183 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 572f992e
...@@ -162,6 +162,8 @@ static char *video_standard = "ntsc"; ...@@ -162,6 +162,8 @@ static char *video_standard = "ntsc";
static char *audio_grab_format = "audio_device"; static char *audio_grab_format = "audio_device";
static char *audio_device = NULL; static char *audio_device = NULL;
static int using_stdin = 0;
#define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass" #define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
typedef struct AVOutputStream { typedef struct AVOutputStream {
...@@ -1139,14 +1141,15 @@ static int av_encode(AVFormatContext **output_files, ...@@ -1139,14 +1141,15 @@ static int av_encode(AVFormatContext **output_files,
} }
#ifndef CONFIG_WIN32 #ifndef CONFIG_WIN32
fprintf(stderr, "Press [q] to stop encoding\n"); if ( !using_stdin )
fprintf(stderr, "Press [q] to stop encoding\n");
#endif #endif
term_init(); term_init();
stream_no_data = 0; stream_no_data = 0;
key = -1; key = -1;
for(;;) { for(; received_sigterm == 0;) {
int file_index, ist_index; int file_index, ist_index;
AVPacket pkt; AVPacket pkt;
uint8_t *ptr; uint8_t *ptr;
...@@ -1160,7 +1163,7 @@ static int av_encode(AVFormatContext **output_files, ...@@ -1160,7 +1163,7 @@ static int av_encode(AVFormatContext **output_files,
redo: redo:
/* if 'q' pressed, exits */ /* if 'q' pressed, exits */
if (key) { if (!using_stdin) {
/* read_key() returns 0 on EOF */ /* read_key() returns 0 on EOF */
key = read_key(); key = read_key();
if (key == 'q') if (key == 'q')
...@@ -1991,6 +1994,9 @@ static void opt_input_file(const char *filename) ...@@ -1991,6 +1994,9 @@ static void opt_input_file(const char *filename)
if (!strcmp(filename, "-")) if (!strcmp(filename, "-"))
filename = "pipe:"; filename = "pipe:";
using_stdin |= !strcmp(filename, "pipe:" ) ||
!strcmp( filename, "/dev/stdin" );
/* get default parameters from command line */ /* get default parameters from command line */
memset(ap, 0, sizeof(*ap)); memset(ap, 0, sizeof(*ap));
ap->sample_rate = audio_sample_rate; ap->sample_rate = audio_sample_rate;
...@@ -2366,13 +2372,19 @@ static void opt_output_file(const char *filename) ...@@ -2366,13 +2372,19 @@ static void opt_output_file(const char *filename)
if (url_exist(filename)) { if (url_exist(filename)) {
int c; int c;
printf("File '%s' already exists. Overwrite ? [y/N] ", filename); if ( !using_stdin ) {
fflush(stdout); fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
c = getchar(); fflush(stderr);
if (toupper(c) != 'Y') { c = getchar();
fprintf(stderr, "Not overwriting - exiting\n"); if (toupper(c) != 'Y') {
fprintf(stderr, "Not overwriting - exiting\n");
exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
exit(1); exit(1);
} }
} }
} }
......
...@@ -173,7 +173,8 @@ AVOutputFormat yuv4mpegpipe_oformat = { ...@@ -173,7 +173,8 @@ AVOutputFormat yuv4mpegpipe_oformat = {
.flags = AVFMT_RAWPICTURE, .flags = AVFMT_RAWPICTURE,
}; };
#define MAX_YUV4_HEADER 50 /* Header size increased to allow room for optional flags */
#define MAX_YUV4_HEADER 80
#define MAX_FRAME_HEADER 10 #define MAX_FRAME_HEADER 10
static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap) static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册