stanleyhuang
3rd March 2007, 05:49
Here is a patch to fix x264 encoding from stdin problem on Win32. I made this patch in order to let MediaCoder feed x264 frames via stdin.
Index: muxers.c
===================================================================
--- muxers.c (revision 624)
+++ muxers.c (working copy)
@@ -43,6 +43,8 @@
#include <gpac/isomedia.h>
#endif
+#include <fcntl.h>
+
typedef struct {
FILE *fh;
int width, height;
@@ -58,7 +60,10 @@
h->next_frame = 0;
if( !strcmp(psz_filename, "-") )
+ {
h->fh = stdin;
+ setmode(fileno(stdin),O_BINARY);
+ }
else
h->fh = fopen(psz_filename, "rb");
if( h->fh == NULL )
@@ -73,6 +78,7 @@
yuv_input_t *h = handle;
int i_frame_total = 0;
+ if (h->fh == stdin) return 0;
if( !fseek( h->fh, 0, SEEK_END ) )
{
uint64_t i_size = ftell( h->fh );
@@ -134,7 +140,10 @@
h->next_frame = 0;
if( !strcmp(psz_filename, "-") )
+ {
h->fh = stdin;
+ setmode(fileno(stdin),O_BINARY);
+ }
else
h->fh = fopen(psz_filename, "rb");
if( h->fh == NULL )
Index: muxers.c
===================================================================
--- muxers.c (revision 624)
+++ muxers.c (working copy)
@@ -43,6 +43,8 @@
#include <gpac/isomedia.h>
#endif
+#include <fcntl.h>
+
typedef struct {
FILE *fh;
int width, height;
@@ -58,7 +60,10 @@
h->next_frame = 0;
if( !strcmp(psz_filename, "-") )
+ {
h->fh = stdin;
+ setmode(fileno(stdin),O_BINARY);
+ }
else
h->fh = fopen(psz_filename, "rb");
if( h->fh == NULL )
@@ -73,6 +78,7 @@
yuv_input_t *h = handle;
int i_frame_total = 0;
+ if (h->fh == stdin) return 0;
if( !fseek( h->fh, 0, SEEK_END ) )
{
uint64_t i_size = ftell( h->fh );
@@ -134,7 +140,10 @@
h->next_frame = 0;
if( !strcmp(psz_filename, "-") )
+ {
h->fh = stdin;
+ setmode(fileno(stdin),O_BINARY);
+ }
else
h->fh = fopen(psz_filename, "rb");
if( h->fh == NULL )