PDA

View Full Version : x264 patch to fix stdin problem on Win32


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 )

akupenguin
3rd March 2007, 06:27
Does fseek(stdin,...) do something bad on windows? Of course it will fail (unless stdin was redirected from a file), but the code already checks for failure.

neuron2
3rd March 2007, 14:44
Anyway fseek()/ftell() won't work with large files under Windows.

stanleyhuang
3rd March 2007, 18:30
fseek should fail with stdin, but it doesn't on Windows and thus the i_frame_total won't be 0 as it should be when stdin as input(0 means unlimited number of frames).

akupenguin
4th March 2007, 04:31
from config.h on windows
#define fseek fseeko64
#define ftell ftello64

stanleyhuang
4th March 2007, 07:13
Maybe the two defines should be written into config.h by x264 configure.

DarkZell666
4th March 2007, 10:23
ATM stdin only works under win32 if x264 has been compiled with Visual Studio (Sharktooth provided some Intel builds somewhere that have correctly working stdin without any patch). If this patch fixes the problem with mingw it's good news :)

See Sharktooth's intel builds with VS here : http://forum.doom9.org/showthread.php?t=120247

stanleyhuang
4th March 2007, 21:45
I'm using mingw to build x264 and this fix is to mingw.