AI-Assisted Development of a Batch Audio/Video Conversion Tool: An Engineering Practice

    Using a batch audio/video converter as a test case for AI code generation is effective because it spans file operations, GUI development, long-running tasks, external process invocation, and error handling. This article walks through the full engineering workflow: turning requirements into verifiable acceptance criteria, separating the UI from background worker threads, detecting external transcoding components, designing output path and file-conflict policies, implementing robust error handling and feedback, and validating whether generated code is actually production-ready. It also offers practical advice on prompt writing for code generation tools.

    1. Why This Scenario Is a Good Test for Code Generation

    A batch audio/video conversion tool is an excellent test sample. It combines file operations, a graphical interface, time-consuming tasks, external program invocation, and error handling—covering the main aspects of desktop application development. Simply checking whether the code compiles tells you nothing about whether it is usable. What truly determines the user experience is often the non-functional requirements: does the interface stay responsive while converting a large file, and can users see why a conversion failed?

    Therefore, when evaluating code generation quality, requirements should be written as a checklist that can be verified item by item, and the implementation should be checked against each entry.

    2. Requirement Breakdown: Turning Requests into Verifiable Items

    Verbally described requirements are usually vague. Handing them directly to a code generation tool makes it easy to miss details. It is recommended to organize requirements into three categories first: functional requirements, UI requirements, and non-functional requirements.

    Category Requirement Acceptance Method
    Functional Recognize common video formats; export audio formats such as MP3 and WAV Convert one sample file per format and verify the output plays correctly
    Functional Support adding files and recursively scanning directories Select a folder containing subdirectories and check the list count
    Functional Support pre-conversion format settings Change the settings and inspect the output file’s encoding parameters
    UI File list, progress bar, status bar, exit button Operate each control and confirm its state is correct
    Non-functional The UI must not freeze during conversion Drag the window and click buttons while converting a large file
    Non-functional Show clear error messages on failure Deliberately use corrupted files and directories without write permission

    Every requirement should have a corresponding acceptance method. Requirements without acceptance criteria are typically ignored during implementation.

    3. Separating the UI from Background Tasks

    A GUI program has only one event loop. If the conversion runs directly inside an event handler, the interface cannot refresh until the conversion finishes, and the window appears unresponsive. This is the most common defect in this type of program.

    The correct approach is to run time-consuming tasks in worker threads while the main thread only handles UI updates. The worker thread communicates with the main thread through a message queue and never touches UI controls directly.

    1. Main thread:
    2. Initialize the UI
    3. Start the event loop
    4. Every 100 ms:
    5. Drain all pending messages from the message queue
    6. Update the progress bar, status bar, and failure list accordingly
    7. Worker thread (one per batch):
    8. For each file in the task list:
    9. If the cancel flag is set: terminate the thread
    10. Call the transcoding component (input path, output path, format parameters)
    11. Push the result (success, failure reason, progress percentage) into the message queue

    Three additional points matter during implementation. First, the cancel flag should be checked before each file is processed and must be able to interrupt the currently running external process. Second, concurrency should be limited—default to one task, or match the number of CPU cores—to avoid launching too many transcoding processes at once and exhausting resources. Third, shared variables need locks or thread-safe data structures; otherwise, progress counters may produce incorrect results.

    4. Detecting the External Transcoding Component

    Most audio/video conversion features rely on an external command-line transcoding component rather than codecs implemented by the application itself. The program must confirm that this component is available before starting any task; otherwise, users will only discover the problem midway through a batch job.

    The recommended detection flow:

    1. Function DetectTranscoder():
    2. path = search the system PATH for the component executable
    3. If path is empty:
    4. Show a prompt explaining how to install it
    5. Disable the "Start Conversion" button
    6. Return failure
    7. versionInfo = execute(path, "--version")
    8. Display versionInfo in the status bar
    9. Return success

    Detection should run once at startup and again when the user clicks Start. The component might be deleted while the program is running, so the second check is necessary.

    5. Output Paths and File Overwrite Policy

    This is a design issue worth discussing on its own. Many developers habitually default the output directory to the program’s installation directory, but this has obvious drawbacks. Installation directories usually require administrator privileges to write to, so the program may fail for regular users. Output files in that directory may also be wiped out when the program is updated or reinstalled.

    A more sensible approach is to default the output to the source file’s directory, or to remember the directory the user last selected. The UI should display the current output path and allow the user to change it.

    Name conflicts also require a clearly defined policy. A common practice is to automatically append a sequence number to avoid overwriting existing files:

    1. Function GenerateNonConflictingPath(directory, baseName, extension):
    2. candidate = baseName + extension
    3. counter = 1
    4. While a file named candidate exists in directory:
    5. candidate = baseName + "_" + counter + extension
    6. counter = counter + 1
    7. Return directory + candidate

    An alternative is to show a dialog letting the user choose to overwrite, skip, or rename. Whichever strategy is chosen, it should be documented and visible in the UI.

    6. Error Handling and Result Feedback

    Error handling for batch tasks should follow one principle: the failure of a single file must not interrupt the entire batch. The tool should record the failure reason, continue with the remaining files, and present a summary at the end.

    It is advisable to distinguish the following error categories, because they are handled differently:

    1. Corrupted input file or unsupported format: skip the file and record the reason.
    2. No write permission for the output directory: check in advance; stop the task and notify the user if a problem is found.
    3. Insufficient disk space: estimate the required space before starting and warn the user if it is not enough.
    4. Abnormal exit of the transcoding component: record the exit code and error output, and mark the file as failed.
    5. Individual task timeout: terminate the corresponding process to avoid hanging indefinitely.

    The end-of-run summary can include the number of successes, the number of failures, and the list of failed files. Detailed logs should also be written to a file to facilitate troubleshooting.

    7. Recursive Scanning and Format Detection

    Two issues require attention when recursively scanning directories. First, symbolic links can form loops and cause infinite traversal, so the real paths already visited should be recorded. Second, excessively deep directory hierarchies can exhaust resources, so a maximum depth can be set.

    There are generally two ways to identify formats. Checking by extension is fast, but filenames can be tampered with, and mismatches between the extension and actual content are not uncommon. Probing file content is more reliable but more expensive. In practice, a workable approach is to use extensions for initial screening and rely on error messages to inform the user when conversion fails. The list of supported extensions should be centralized in one place for easy maintenance.

    8. How to Verify Whether Generated Code Can Run Directly

    Code that passes syntax checks is only formally correct. Determining whether it can be used directly requires the following verification steps:

    1. Static checks: run syntax and style checks, paying attention to unused variables and unhandled exception branches.
    2. Startup test: does the program start normally, without unexpected errors or warnings?
    3. Functional test cases: test single-file conversion, batch conversion, empty directories, unsupported formats, corrupted files, name-conflicting outputs, and missing transcoding components—one pass each.
    4. Responsiveness test: convert a large file and, during conversion, drag the window, click buttons, and switch tabs to confirm the UI stays responsive.
    5. Cancel and exit test: click Cancel or Exit midway through a conversion and confirm the background process is terminated with no leftover temporary files.
    6. Code review: focus on state shared between threads, how paths are joined, and whether exceptions are silently swallowed.

    Generated code should be treated like a merge request from a junior colleague. The author’s explanation can serve as a reference, but every claim must be confirmed through testing.

    9. Tips for Writing Prompts

    A good prompt typically contains four parts: a functional description, technical constraints, acceptance criteria, and a request for design rationale. Acceptance criteria are especially important—for example, “the UI must not freeze during conversion” is far easier to verify than “it should be smooth.”

    After the code is generated, you can follow up with questions about design details, such as the default output directory, how name conflicts are handled, and how cancellation is implemented. The answers help you judge whether the model understood the requirements. However, the answers still need to be verified against the actual code—do not assume a feature is implemented just because the text says so.

    10. Summary

    1. A batch audio/video conversion tool covers the main aspects of desktop development, making it well suited for evaluating code quality.
    2. Requirements should be written as verifiable items; non-functional requirements in particular must be stated explicitly.
    3. Time-consuming tasks must run in background threads, with the UI updated only through a message queue.
    4. External dependencies should be detected before tasks begin and reconfirmed during operation.
    5. The default output path should be in a user-writable location, with a clear policy for name conflicts.
    6. The failure of a single file must not affect the rest of the batch; provide a final summary and logs.
    7. Whether code can run directly must be confirmed through static checks, functional tests, responsiveness tests, and cancellation tests together.