# Wan 2.2 14B Image to Video - Extracting Last Frame An example on how to extract and save the last frame when generating videos in ComfyUI. ## Custom nodes This example requires [ComfyUI-VideoHelperSuite](https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite). ## Overview The general idea is to extract the last frame directly after the VAE Decode step, so that no quality is lost. ![Screenshot of the Select Images node configuration](select-images.png) It works by setting the `indexes` field to select all frames but the last one to save as a video file, and then the last frame only to save as an image. The last frame is not included in the video file - this avoids frame duplication when concatenating another video that is generated using the saved frame as its starting frame. ## Example output After generation, the result is a video file and an image: ![Screenshot of the output of the Select Images nodes](example-output.png) This workflow saves the generated video frames in a lossless format. In general, it's usually a good idea to avoid compressing the video until the last concatenation stage - your GPU worked hard to create these pixels so don't throw them away prematurely! ## Concatenation After you have generated all the segments, concatenate them using your favorite video processing tool. For example, using ffmpeg and ImageMagick: ```bash magick Wan2.2_00001_.webp Wan2.2_00003_.webp Wan2.2_00005_.webp Wan2.2_00007_.webp Wan2.2_00008_.png -coalesce -alpha on -compress none PPM:- | ffmpeg -f image2pipe -vcodec ppm -framerate 16 -i - -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p concatenated.mp4 ``` The very last extracted frame can also be included in the video by specifying it last, so no generated data is lost. ## Pick a different ending frame It's not necessary to choose the very last generated frame as the clip's last frame. To select another, simply update the ending index number. For example, to end at 12 frames before the end: ![Screenshot of the Select Images node 12 frames before the end](select-images-custom.png) Just run the workflow again after changing the `indexes` field, as long as nothing else changed ComfyUI will rerun the frame extraction part only. (Note that this requires a fixed seed). ## Render the next segment When you have selected a good ending frame that should start the next segment, just press `refresh` on the `Load image (from Outputs)` node, ensure the correct image is selected: ![Screenshot of the output of the Load Image (from Outputs) nodes](select-next.png) Then update the prompt as necessary and generate the next part! ## Caveats This method provides fairly seamless concatenation of video segments, but the individual segments still have to be generated carefully so that the motion doesn't change abruptly. This has to be accomplished by prompting, as the only input from one segment to another is a still image. ## Reference data * [Input image](example.png) * [Final combined video](combined.mp4)