Skip to content

Commit

Permalink
Update video template to support transparent videos
Browse files Browse the repository at this point in the history
  • Loading branch information
melund committed Jan 17, 2025
1 parent 4e8efbd commit 59a74fb
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions Tools/ModelUtilities/Video/VideoLookAtCamera.any
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,35 @@ To use the class template.
#class_template VideoLookAtCamera (
UP_DIRECTION = y,
CREATE_GIF = 0,
TRANSPARENT_BACKGROUND=0,
_AUTO_PLAY_VIDEOS = 1,
_OVER_WRITE = 1,
_DEBUG = 0,
_CLEAN_UP_IMAGES = 1,
_AUTO_OPEN_PREVIEW_ = 1,
ENABLE_SAVE_SETTINGS=0,
ENABLE_OVERLAY= 1
ENABLE_OVERLAY= 1,
VIDEO_ENCODER="vp9"
)
{
// Arguments:
// ---------------
//VideoLookAtCamera#UP_DIRECTION
// The direction of the up vector of the camera.
//
//VideoLookAtCamera#TRANSPARENT_BACKGROUND
// Create images and videos with transparent background.
//
//VideoLookAtCamera#CREATE_GIF
// If set to 1, a gif will be created in addition to the video.
//
//VideoLookAtCamera#ENABLE_OVERLAY
// If set to 1, the settings used to create the video will be saved in a file.
//
//VideoLookAtCamera#VIDEO_ENCODER
// Sets the codec used for encoding the video in FFMPEG. A few options have been
// preconfigured. "xvid" gives mp4 videos encoded with xvid which are highly compatible.
// "vp9" gives "*.webm" videos which have better quality for the size and support transparency.


//VideoLookAtCamera
Expand Down Expand Up @@ -108,7 +118,7 @@ To use the class template.
/// The video codec ffmepg will use to create the video.
/// Choose "libxvid" for best for compatibility (eg. with PowerPoint)
/// or "libvpx-vp9" for best performance
#var AnyString VideoCodec = "libvpx-vp9";
#var AnyString VideoCodec = "";

//VideoLookAtCamera
/// This is the start frame used when creating Videos. This can be used to
Expand Down Expand Up @@ -189,7 +199,11 @@ To use the class template.

AnyFolder CheckInputs = {
AnyInt VideoInputFrameRate = assert(gtfun(.VideoInputFrameRate,0), "Video Input frame rate should larger than 0");
AnyInt deprecated_codec = warn(not(.VideoCodec), strformat("\n") +"Deprecated: The member VideoCodec is deprecated. Use class argument VIDEO_ENCODER instead");

#if VIDEO_ENCODER == "xvid" & TRANSPARENT_BACKGROUND
AnyInt warn_transparent = warn(0, strformat("\nPlease use argument VIDEO_ENCODER=" + strquote("vp9") + " to create videos that support transparency."));
#endif
};


Expand Down Expand Up @@ -219,7 +233,7 @@ To use the class template.
#endif
AnyOperationMacro ResetFilename =
{
MacroStr = {"classoperation "+CompleteNameOf(..Camera.Recorder.F)+"ileName "+strquote("Reset Value")};
MacroStr = {"classoperation "+CompleteNameOf(..Camera.Recorder.F) + "ileName " + strquote("Reset Value")};
};
};

Expand Down Expand Up @@ -294,6 +308,10 @@ To use the class template.
#var ResetTrig = DesignVar(Off);
#var AntiAlias = 16;

#if TRANSPARENT_BACKGROUND
#var TransparentBackgroundOnOff = On;
#endif

FileName = ..VideoOutputPath+ "/"+ ..VideoName + "_" + strval(..Counter , CounterFormat)+ ".png";


Expand Down Expand Up @@ -451,9 +469,15 @@ To use the class template.
#var FileName = "cmd.exe";
#var AnyStringVar inputfile = ..VideoName + "_" + ..Camera.Recorder.CounterFormat +".png";


#var AnyStringVar video_extension =
#if VIDEO_ENCODER == "vp9"
".webm";
#else
".mp4";
#endif

#var AnyFileVar out_file = ..VideoOutputPath+ "/"+ ..VideoName + ".mp4";

#var AnyFileVar out_file = ..VideoOutputPath+ "/"+ ..VideoName + video_extension;

#if ENABLE_OVERLAY
#var AnyString OverLayFilter = "[bg];[1:v]scale=-2:2*trunc("+strval(..VideoResolution[1])+"*"+strval(..OverlayImageScale)+"/2)[overlay];[bg][overlay]overlay=W-w:H-h";
Expand All @@ -472,23 +496,30 @@ To use the class template.
" -r " + strval(..VideoInputFrameRate) +
" -start_number " + strval(..VideoStartFrame,..Camera.Recorder.CounterFormat) +
" -i "+strquote(inputfile) +
#if ENABLE_OVERLAY
" -i " + strquote(..OverlayImage) +
#endif
" -filter_complex " + strquote("[0:v]fps="+strval(..VideoOutputFrameRate)+ ",scale=trunc(iw/(2*"+strval(InputOutputScale,"%g" )+"))*2:trunc(ih/(2*"+strval(InputOutputScale,"%g" )+"))*2" + OverLayFilter + "[outv]") +
" -map [outv]" +
" -an" +
" -metadata comment=" + strquote("Created with the AnyBody Modeling System.")
;

#var AnyStringVar CodecArgs = " -c:v " + ..VideoCodec + " -crf " + strval(..ConstantRateFactor)+" -level 3.0 -pix_fmt yuv420p -strict experimental -movflags +faststart ";
#var AnyStringVar CodecArgs_VP9 = " -c:v libvpx-vp9" + " -crf " + strval(..ConstantRateFactor)+" -pix_fmt yuv420p -row-mt 1 ";
#var AnyStringVar CodecArgs_default = " -c:v libxvid -crf " + strval(..ConstantRateFactor)+" -level 3.0 -pix_fmt yuv420p -strict experimental -movflags +faststart ";
#var AnyStringVar CodecArgs_vp9 = " -c:v libvpx-vp9 -an -crf " + strval(..ConstantRateFactor)+" -pix_fmt yuva420p -row-mt 1 "; //-metadata:s:v:0 alpha_mode=" + strquote("1")
// #var AnyStringVar CodecArgs_VP9 = " -c:v apng" + " -crf " + strval(..ConstantRateFactor)+" -pix_fmt rgba -row-mt 1 ";


#var AnyStringVar OutputArg = strquote(FilePathCompleteOf(out_file));

#var Arguments = iffun(_DEBUG , "/K","/C") + " TITLE Creating Video && "+iffun(neqfun(..VideoCodec,"libvpx-vp9"),
ffmpegBaseArg + CodecArgs + OutputArg,
ffmpegBaseArg + CodecArgs_VP9 +" -pass 1 -f null NUL && " + ffmpegBaseArg + CodecArgs_VP9 + " -pass 2 " + OutputArg
) ;
#var Arguments = iffun(_DEBUG , "/K","/C") + " TITLE Creating Video && " + ffmpegBaseArg
#if VIDEO_ENCODER == "vp9"
+ CodecArgs_vp9 +" -pass 1 -f null NUL && " + ffmpegBaseArg + CodecArgs_vp9 + " -pass 2 -auto-alt-ref 0 "
#else
+ CodecArgs_default
#endif
+ OutputArg;

#var WorkDir = ..VideoOutputPath;
#var Show = DesignVar(_DEBUG);
};
Expand Down

0 comments on commit 59a74fb

Please sign in to comment.