Created
November 30, 2011 08:37
-
-
Save SAPikachu/1408441 to your computer and use it in GitHub Desktop.
support yv16 and yv24 in avs4x264mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- E:\avs4x264mod_v0.3\src\avs4x264mod.c 2011-11-29 10:44:43.000000000 +0800 | |
+++ E:\avs4x264mod_v0.3\src\avs4x264mod - Copy.c 2011-11-30 16:46:54.000000000 +0800 | |
@@ -116,13 +116,13 @@ | |
return 0; | |
fail: | |
FreeLibrary( h->library ); | |
return -1; | |
} | |
-char* generate_new_commadline(int argc, char *argv[], int i_frame_total, int i_fps_num, int i_fps_den, int i_width, int i_height, char* infile ) | |
+char* generate_new_commadline(int argc, char *argv[], int i_frame_total, int i_fps_num, int i_fps_den, int i_width, int i_height, char* infile, const char* csp ) | |
{ | |
int i; | |
char *cmd, *buf; | |
int b_tc = 0; | |
int len = (unsigned int)strrchr(argv[0], '\\'); | |
char *x264_binary; | |
@@ -213,12 +213,17 @@ | |
strcat(cmd, " "); | |
} | |
} | |
} | |
sprintf(buf, "- --input-res %dx%d", i_width, i_height); | |
strcat(cmd, buf); | |
+ if (csp) | |
+ { | |
+ sprintf(buf, " --input-csp %s", csp); | |
+ strcat(cmd, buf); | |
+ } | |
free(buf); | |
return cmd; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
@@ -240,16 +245,17 @@ | |
int i_fps_num; | |
int i_fps_den; | |
int i_frame_total; | |
int b_interlaced=0; | |
/*Video Info End*/ | |
char *planeY, *planeU, *planeV; | |
- unsigned int frame,len,h_half,w_half; | |
+ unsigned int frame,len,chroma_height,chroma_width; | |
int i,j; | |
char *cmd; | |
char *infile = NULL; | |
+ const char *csp = NULL; | |
if (argc>1) | |
{ | |
//get the script file and other informations from the commandline | |
for (i=1;i<argc;i++) | |
{ | |
len = strlen(argv[i]); | |
@@ -319,15 +325,25 @@ | |
if( vi->width&1 || vi->height&1 ) | |
{ | |
fprintf( stderr, "avs [error]: input clip width or height not divisible by 2 (%dx%d)\n", | |
vi->width, vi->height ); | |
goto avs_fail; | |
} | |
- /* always call ConvertToYV12 to convert non YV12 planar colorspaces to YV12 when user's AVS supports them, | |
- as all planar colorspaces are flagged as YV12. If it is already YV12 in this case, the call does nothing */ | |
- if( !avs_is_yv12( vi ) || avs_version >= AVS_INTERFACE_OTHER_PLANAR ) | |
+ if ( avs_is_yv24( vi ) ) | |
+ { | |
+ csp = "i444"; | |
+ chroma_width = vi->width; | |
+ chroma_height = vi->height; | |
+ } | |
+ else if ( avs_is_yv16( vi ) ) | |
+ { | |
+ csp = "i422"; | |
+ chroma_width = vi->width >> 1; | |
+ chroma_height = vi->height; | |
+ } | |
+ else if( !avs_is_yv12( vi ) ) | |
{ | |
avs_h.func.avs_release_clip( avs_h.clip ); | |
fprintf( stderr, "avs %s\n", !avs_is_yv12( vi ) ? "[warning]: converting input clip to YV12" | |
: "[info]: Avisynth 2.6+ detected, forcing conversion to YV12" ); | |
const char *arg_name[2] = { NULL, "interlaced" }; | |
AVS_Value arg_arr[2] = { res, avs_new_value_bool( b_interlaced ) }; | |
@@ -337,12 +353,15 @@ | |
fprintf( stderr, "avs [error]: Couldn't convert input clip to YV12\n" ); | |
goto avs_fail; | |
} | |
avs_h.clip = avs_h.func.avs_take_clip( res2, avs_h.env ); | |
avs_h.func.avs_release_value( res2 ); | |
vi = avs_h.func.avs_get_video_info( avs_h.clip ); | |
+ chroma_width = vi->width >> 1; | |
+ chroma_height = vi->height >> 1; | |
+ | |
} | |
avs_h.func.avs_release_value( res ); | |
i_width = vi->width; | |
i_height = vi->height; | |
i_fps_num = vi->fps_numerator; | |
@@ -381,28 +400,24 @@ | |
si_info.cb = sizeof(STARTUPINFO); | |
si_info.dwFlags = STARTF_USESTDHANDLES; | |
si_info.hStdInput = h_pipeRead; | |
si_info.hStdOutput = h_stdOut; | |
si_info.hStdError = h_stdErr; | |
- cmd = generate_new_commadline(argc, argv, i_frame_total, i_fps_num, i_fps_den, i_width, i_height, infile ); | |
+ cmd = generate_new_commadline(argc, argv, i_frame_total, i_fps_num, i_fps_den, i_width, i_height, infile, csp ); | |
printf("avs4x264 [info]: %s\n", cmd); | |
if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &si_info, &pi_info)) | |
{ | |
fprintf( stderr, "Error: Failed to create process <%d>!", (int)GetLastError()); | |
free(cmd); | |
goto pipe_fail; | |
} | |
//cleanup before writing to pipe | |
CloseHandle(h_pipeRead); | |
free(cmd); | |
- | |
- //prepare for writing | |
- w_half = i_width >> 1; | |
- h_half = i_height >> 1; | |
//write | |
for (frame=0; frame<i_frame_total; frame++) | |
{ | |
frm = avs_h.func.avs_get_frame( avs_h.clip, frame ); | |
const char *err = avs_h.func.avs_clip_get_error( avs_h.clip ); | |
@@ -418,23 +433,23 @@ | |
fprintf( stderr, "avs [error]: Error occurred while writing frame %d\n(Maybe x264_64.exe closed)\n", frame ); | |
goto process_fail; | |
} | |
planeY += frm->pitch; | |
} | |
planeU = (char*)(frm->vfb->data + frm->offsetU); | |
- for (j=0; j<h_half; j++){ | |
- if( !WriteFile(h_pipeWrite, planeU, w_half, (PDWORD)&i, NULL) ) | |
+ for (j=0; j<chroma_height; j++){ | |
+ if( !WriteFile(h_pipeWrite, planeU, chroma_width, (PDWORD)&i, NULL) ) | |
{ | |
fprintf( stderr, "avs [error]: Error occurred while writing frame %d\n(Maybe x264_64.exe closed)\n", frame ); | |
goto process_fail; | |
} | |
planeU += frm->pitchUV; | |
} | |
planeV = (char*)(frm->vfb->data + frm->offsetV); | |
- for (j=0; j<h_half; j++){ | |
- if( !WriteFile(h_pipeWrite, planeV, w_half, (PDWORD)&i, NULL) ) | |
+ for (j=0; j<chroma_height; j++){ | |
+ if( !WriteFile(h_pipeWrite, planeV, chroma_width, (PDWORD)&i, NULL) ) | |
{ | |
fprintf( stderr, "avs [error]: Error occurred while writing frame %d\n(Maybe x264_64.exe closed)\n", frame ); | |
goto process_fail; | |
} | |
planeV += frm->pitchUV; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment