[x264-devel] flushing stdout (on win32)
Aaron Drew
aarond10 at gmail.com
Sun Jan 24 05:42:42 CET 2010
Hi,
I'm using x264 as a spawned process, feeding data in and out with
anonymous pipes. To avoid having to decode the output bitstream to
determine frame boundaries for my decoder/transport, its convenient to
be able to have data reads cleanly coincide with frame boundaries. If
the output stream is not flushed, the OS will buffer data until either
the program ends or the output buffer is filled (4kb on win32 by
default). I've compiled a version with an 8 line change to
output/raw.c that flushes the file out handle after writing a frame or
a header. This is not necessarily desirable unless streaming data via
stdout but its a simple enough change and it will probably help others
so I thought I'd throw it out here for review.
- Aaron
diff --git a/output/raw.c b/output/raw.c
index a4d1175..dbf45ee 100644
--- a/output/raw.c
+++ b/output/raw.c
@@ -43,14 +43,22 @@ static int write_headers( hnd_t handle, x264_nal_t *p_nal )
int size = p_nal[0].i_payload + p_nal[1].i_payload + p_nal[2].i_payload;
if( fwrite( p_nal[0].p_payload, size, 1, (FILE*)handle ) )
+ {
+ if(handle == stdout)
+ fflush((FILE*)handle);
return size;
+ }
return -1;
}
static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size,
x264_picture_t *p_picture )
{
if( fwrite( p_nalu, i_size, 1, (FILE*)handle ) )
+ {
+ if(handle == stdout)
+ fflush((FILE*)handle);
return i_size;
+ }
return -1;
}
More information about the x264-devel
mailing list