Paired First-Last Frame Generation and the Pit Within the STCODE Placeholder Pit
In the image generation pipeline of the Yuncao Academy system, drawrole and placeaiwords are two completely different invocation paths, and their parameter differences directly determine whether you will hit the pit of missing first and last frames. drawrole is the dedicated function for character image generation. Its invocation method is synchronous direct call, meaning that when you send a request, the client blocks and waits for Volcano Engine to return the image result until the image is successfully generated and written to the specified path, and only then returns a success flag. placeaiwords, on the other hand, is the location image generation function, and it follows an asynchronous branch. When an image generation task is submitted to it, the function immediately returns a task acceptance number, and the actual image generation process runs in the background while the client can continue handling other tasks. Precisely because placeaiwords is asynchronous, the image generation client must actively poll the task status and obtain the image path after the background task completes. This asynchronous mechanism itself is not a problem, but if you do not carefully process the complete image generation results for each shot when writing the client polling code, you will miss the generation of the last frame. Each shot must generate two images: the first frame filename ends with -a, and the last frame ends with -b. This is a hard convention written into the firstpic and secondpic fields of the dbvideo_arcpictask table. The firstpic field stores the full path of the first frame image, and the secondpic field stores the full path of the last frame image. When an image generation task is created, the system inserts a row into the arcpictask table, where the firstpic field is assigned a temporary placeholder string, here STCODE.png, and the secondpic field is also assigned STCODE.png. The original design intent of this placeholder is to occupy the field and prevent NULL values from causing program errors, but the problem is that it only represents that the image has not been generated yet, not that missing is allowed. If for some reason, such as the client crashing immediately after generating the first frame, or the task being manually cancelled, the secondpic field will permanently retain STCODE.png. Afterwards, no log will tell you that there is a problem with this shot, because from the perspective of the image generation client, the firstpic field of this task has a value and the secondpic field also has a value, so it will not re-push this task. Eventually, when the video generation module reads the storyboard data, it reads firstpic and secondpic from the arcpictask table and passes these two paths to the Jimeng video generation interface. But when secondpic is still STCODE.png, the system must either copy this file to the expected disk directory first, or directly read a non-existent file, causing the video generation task to fail, or worse, if the placeholder happens to exist in some shared directory, the video generator will treat it as a black default image to generate the last frame, causing the ending of the video to suddenly black out or show completely meaningless images. The logical coherence of the finished film is thus broken. This is not hypothetical. During the actual production of "The First Avenue," seven shots exhibited this phenomenon, three of which had stcode values where the last frame was not fully written due to a machine power outage, and the other four had asynchronous callback timeouts causing placeaiwords to return success but the actual disk write failed. To prevent this problem, the simplest approach is to establish detection logic before the video generation stage by using an SQL query to check whether all shots pending video generation have paired image output. One core SQL statement can accomplish this task: SELECT scenecode, firstpic, secondpic FROM dbvideo_arcpictask WHERE firstpic = 'STCODE.png' OR secondpic = 'STCODE.png' OR firstpic LIKE '%\_a.png' = 0 OR secondpic LIKE '%\_b.png' = 0. This statement will precisely identify all records where the first or last frame is missing, or where the naming does not conform to the -a and -b rules. A stricter approach is to verify during the image generation task completion callback that the firstpic file actually exists and is larger than 100KB, and to do the same for secondpic. When verification fails, reset the task status to failed and let the task scheduler automatically reassign it. Additionally, you can create check constraints at the database level by using a stored procedure to compare new.firstpic and new.secondpic during updates. If one of them ends with STCODE.png while the other is a normal path, return an error and roll back the transaction. If detection finds already corrupted data, there are two repair strategies. The first is manual image re-generation, which is suitable for shots that are more important. The operator enters the prompt for that shot individually in the system management interface and calls drawrole or placeaiwords to generate the missing image. For example, if only the last frame is missing, modify the task description corresponding to the taskid so that it only generates the -b last frame. However, note that images generated individually in this way are likely to be inconsistent in angle, expression, and lighting with the original first frame, because the random seeds of the two calls differ. The second approach is to re-run the entire image generation task, clearing both firstpic and secondpic, resetting the status to pending, and letting the image generation client regenerate starting from the first frame. Although this repair wastes some computing power, it guarantees that the first and last frames are perfectly consistent in style. In actual practice, it is recommended to prioritize re-running the entire task, because the style inconsistency caused by manual image re-generation is almost impossible to fix in post-production for the final video, and the stiff transition between the first and last frames will be very obvious. So why must the first and last frames be generated as a pair? Behind this is a technical constraint of the Jimeng video generator. Jimeng generates videos in an image-to-video mode: it takes the first frame as the starting point and the last frame as the ending point, and the generator interpolates the dynamic frames in between. If there is only a first frame and no last frame, the generator cannot determine the state at the end of the motion and can only rely on the model to randomly generate an ending, which usually results in rapid camera shaking or abnormal zoom. If there is only a last frame and no first frame, the generator lacks a starting point and will generate a completely unrelated opening frame, causing the first second the audience sees to have no connection to the subsequent content. Only when the first and last frames exist as a pair and are consistent in style can the model reasonably plan camera movement and character action within a closed time segment, ensuring visual continuity and narrative coherence. This is also why, in the image generation pipeline of the Yuncao Academy system, the offline task scheduler requests two images from drawrole at once and strictly checks that both images were successfully saved before marking the task as complete. To ensure the entire process runs smoothly, you can modify the status field in the dbvideo_arcpictask table (initial value 0 means unprocessed, 1 means successful, 2 means failed) and add a rerun_flag field. When STCODE.png is detected, automatically force rerun_flag=1 and set both firstpic and secondpic to NULL. The task scheduler's selection condition is simple and direct: SELECT * FROM dbvideo_arcpictask WHERE status = 0 OR rerun_flag = 1. In this way, any task marked for re-run will be immediately captured by the client and restarted from character or location image generation. This loop-back mechanism ensures that even if three machines are working simultaneously during image generation, a delay in one asynchronous task will not cause a chain collapse in subsequent steps. In the actual production of "The First Avenue," this repair path was used to regenerate all seven shots that initially had the STCODE.png placeholder, and after replacement and assembly, the completed video did not show a single frame of breakage or any disruption in audio rhythm. The paired first-last frame generation mechanism, although it adds complexity to task scheduling, eliminates uncontrollable random factors and allows the entire generation pipeline to truly run unattended.