Index: configure =================================================================== --- configure (revision 697) +++ configure (working copy) @@ -8,6 +8,7 @@ echo "" echo " --help print this message" echo " --enable-avis-input enables avisynth input (win32 only)" +echo " --enable-mjpegtools enables avi input (mjpegtools)" echo " --enable-mp4-output enables mp4 output (using gpac)" echo " --enable-gtk build GTK+ interface" echo " --enable-pthread enables multithreaded encoding" @@ -24,6 +25,19 @@ exit 1 fi +mjpeg_check() { + rm -f conftest* + cat > conftest.c << EOF +#include +#include +int main () { lav_open_input_file(""); decode_jpeg_raw(0,0,0,0,0,0,0,0,0); return 0; } +EOF + $CC conftest.c $CFLAGS -I/usr/include/mjpegtools $LDFLAGS -llavfile -lmjpegutils -llavjpeg -o conftest 2>$DEVNULL + TMP="$?" + rm -f conftest* + return $TMP +} + cc_check() { rm -f conftest* cat > conftest.c << EOF @@ -55,6 +69,7 @@ DEVNULL='/dev/null' avis_input="auto" +mjpegtools="auto" mp4_output="auto" pthread="auto" debug="no" @@ -109,9 +124,15 @@ --enable-avis-input) avis_input="yes" ;; + --enable-mjpegtools) + mjpegtools="yes" + ;; --disable-avis-input) avis_input="no" ;; + --disable-mjpegtools) + mjpegtools="no" + ;; --enable-mp4-output) mp4_output="yes" ;; @@ -374,6 +395,16 @@ LDFLAGS="$LDFLAGS $MP4_LDFLAGS" fi +if [ "$mjpegtools" = "auto" ] ; then + mjpegtools="no" + mjpeg_check && mjpegtools="yes" +fi +if [ "$mjpegtools" = "yes" ] ; then + echo "#define HAVE_MJPEGTOOLS" >>config.h + LDFLAGS="$LDFLAGS -llavfile -lmjpegutils -llavjpeg" + CFLAGS="$CFLAGS -I/usr/include/mjpegtools" +fi + if [ "$avis_input" = "auto" ] ; then if [ $SYS = CYGWIN -o $SYS = MINGW ]; then avis_input="yes" @@ -477,6 +508,7 @@ echo "Platform: $ARCH" echo "System: $SYS" echo "avis input: $avis_input" +echo "mjpegtools: $mjpegtools" echo "mp4 output: $mp4_output" echo "pthread: $pthread" echo "gtk: $gtk" Index: x264.c =================================================================== --- x264.c (revision 697) +++ x264.c (working copy) @@ -132,6 +132,7 @@ "Infile can be raw YUV 4:2:0 (in which case resolution is required),\n" " or YUV4MPEG 4:2:0 (*.y4m),\n" " or AVI or Avisynth if compiled with AVIS support (%s).\n" + " or AVI compiled with mjpegtools, support MJPEG,YUV420,YUV422 avi' (%s)\n" "Outfile type is selected by filename:\n" " .264 -> Raw bytestream\n" " .mkv -> Matroska\n" @@ -148,6 +149,11 @@ #else "no", #endif +#ifdef HAVE_MJPEGTOOLS + "yes", +#else + "no", +#endif #ifdef MP4_OUTPUT "yes" #else @@ -633,9 +639,16 @@ p_read_frame = read_frame_avis; p_close_infile = close_file_avis; #else +#ifdef HAVE_MJPEGTOOLS + p_open_infile = open_file_lav; + p_get_frame_total = get_frame_total_lav; + p_read_frame = read_frame_lav; + p_close_infile = close_file_lav; +#else fprintf( stderr, "x264 [error]: not compiled with AVIS input support\n" ); return -1; #endif +#endif } if ( b_y4m ) { Index: muxers.c =================================================================== --- muxers.c (revision 697) +++ muxers.c (working copy) @@ -29,6 +29,12 @@ #include +#ifdef HAVE_MJPEGTOOLS +#include +#include +#include +#endif + #ifdef AVIS_INPUT #include #include @@ -321,6 +327,90 @@ return 0; } +#ifdef HAVE_MJPEGTOOLS +#define MAX_JPEG_LEN (3*576*768/2) +typedef struct { + lav_file_t *lav; + uint8_t buf[MAX_JPEG_LEN]; + int inter,width,height; +} lav_h; + +int open_file_lav( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ) +{ + lav_h *h = malloc(sizeof(lav_h)); + h->lav = lav_open_input_file(psz_filename); + if(!h->lav) { + fprintf( stderr, "[error] Can't open avi file\n"); + return -1; + } + + if(!(h->lav->dataformat == DATAFORMAT_MJPG || + h->lav->dataformat == DATAFORMAT_YUV420 || + h->lav->dataformat == DATAFORMAT_YUV422)) { + fprintf( stderr, "[error] Support only MJPEG,YUV420,YUV422 avi's\n"); + return -1; + } + h->inter = lav_video_interlacing(h->lav); + p_param->i_width = h->width = lav_video_width(h->lav); + p_param->i_height = h->height = lav_video_height(h->lav); + p_param->i_fps_num = lav_frame_rate(h->lav); + *p_handle = (hnd_t)h; + return 0; +} + +int get_frame_total_lav( hnd_t handle ) +{ + lav_h *h = handle; + int i = lav_video_frames(h->lav); + return i; +} + +int read_frame_lav( x264_picture_t *p_pic, hnd_t handle, int i_frame ) +{ + lav_h *h = handle; + int len; + + lav_set_video_position(h->lav, i_frame); + len = lav_read_frame(h->lav, h->buf); + + if(h->lav->dataformat == DATAFORMAT_MJPG) { + p_pic->img.i_csp = X264_CSP_I420; + decode_jpeg_raw(h->buf, + len, + h->inter, + Y4M_CHROMA_420JPEG, + h->width, + h->height, + p_pic->img.plane[0], + p_pic->img.plane[1], + p_pic->img.plane[2]); + return 0; + } + if(h->lav->dataformat == DATAFORMAT_YUV420) { + p_pic->img.i_csp = X264_CSP_I420; + memcpy(p_pic->img.plane[0],h->buf, h->width * h->height); + memcpy(p_pic->img.plane[1],h->buf + (h->width * h->height), h->width * h->height / 4); + memcpy(p_pic->img.plane[2],h->buf + (h->width * h->height * 5 / 4), h->width * h->height / 4); + } + if(h->lav->dataformat == DATAFORMAT_YUV422) { + p_pic->img.i_csp = X264_CSP_I422; + memcpy(p_pic->img.plane[0], h->buf, h->width * h->height); + memcpy(p_pic->img.plane[1], h->buf + (h->width * h->height), h->width * h->height / 4); + memcpy(p_pic->img.plane[2], h->buf + (h->width * h->height * 5 / 4), h->width * h->height / 4); + } + return -1; +} + +int close_file_lav( hnd_t handle ) +{ + lav_h *h = handle; + lav_close(h->lav); + free(h); + return 0; +} + +#endif + /* avs/avi input file support under cygwin */ #ifdef AVIS_INPUT Index: muxers.h =================================================================== --- muxers.h (revision 697) +++ muxers.h (working copy) @@ -18,6 +18,12 @@ int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame ); int close_file_avis( hnd_t handle ); +int open_file_lav( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); +int get_frame_total_lav( hnd_t handle ); +int read_frame_lav( x264_picture_t *p_pic, hnd_t handle, int i_frame ); +int close_file_lav( hnd_t handle ); + + int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); int get_frame_total_thread( hnd_t handle ); int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame );