Practical Lessons from Building a Desktop Batch Audio/Video Converter with AI-Assisted Development

    This article walks through the key practices of using AI-assisted development to build a desktop batch audio/video conversion tool. It covers how to break down vague requirements into verifiable checklists, how to structure the application into clean layers, how to keep the UI responsive with worker threads and message queues, and how to handle progress feedback, errors, naming conflicts, and acceptance testing. The checklists and test cases provided can be used to verify AI-generated code item by item.

    1. Breaking Down Requirements: Turning Vague Requests into Verifiable Items

    A common problem with desktop tool requirements is vague wording. A statement like “support batch conversion” cannot be directly verified. It needs to be broken down into four dimensions: input, processing, output, and feedback.

    • Input: Which video container formats are supported, whether subdirectories are scanned recursively, and whether drag-and-drop import is allowed.
    • Processing: Whether output audio format (such as MP3 or WAV), sample rate, and channel settings are configurable, and whether tasks can be cancelled.
    • Output: The default output directory and the strategy for handling duplicate filenames (overwrite, skip, or auto-numbering).
    • Feedback: Progress bars, status bars, error messages or logs, and how the tool recovers after failures.

    With requirements written as this kind of checklist, developers can review each item themselves. When using code generation tools, the same checklist can be used to verify that the generated output covers every requirement.

    2. Module Structure

    A typical architecture has five layers:

    1. UI layer: Handles control layout and event binding.
    2. Task management layer: Maintains the queue of files to process and the status of each task.
    3. Conversion engine layer: Invokes command-line transcoding programs or codec libraries.
    4. Feedback layer: Aggregates progress, logs, and error information.
    5. Configuration layer: Stores options such as formats and paths.

    Layers communicate through well-defined interfaces. UI code never executes time-consuming operations directly, which keeps responsibilities clear and makes each layer testable in isolation.

    3. Core Challenge: Keeping the UI Responsive

    GUI applications rely on a single event loop. If transcoding runs synchronously inside a button callback, the event loop is blocked, the window cannot repaint, and the user sees a “not responding” freeze.

    The solution is to move time-consuming work into a worker thread while the UI thread only handles display. The two communicate through a thread-safe queue. The worker thread pushes events such as progress, completion, and failure into the queue, and the UI thread polls the queue on a timer (for example, every 100 ms) to update controls.

    Two things require attention during implementation:

    1. UI controls can only be modified on the UI thread. The worker thread must never touch controls directly, otherwise unpredictable errors may occur.
    2. Cancellation should use a flag or event object. The worker thread checks the flag before processing each file and exits safely, rather than being forcibly terminated.

    Illustrative pseudocode (syntax close to common scripting languages):

    1. queue = create_thread_safe_queue()
    2. cancel_flag = create_event()
    3. function worker_thread(file_list, params):
    4. for each file in file_list:
    5. if cancel_flag is set:
    6. queue.put({type: "cancelled"})
    7. exit
    8. result = run_transcoder(file, params)
    9. queue.put({type: "progress", file: file, result: result})
    10. queue.put({type: "done"})
    11. function poll_ui():
    12. while queue is not empty:
    13. message = queue.get()
    14. update progress bar and status bar based on message.type
    15. ui.call_later(poll_ui, 100)

    The benefit of this structure is a clean separation of concerns. The UI always stays responsive, and the conversion logic can be debugged independently of the interface.

    4. Progress and Status Feedback

    Progress is usually calculated as “completed files / total files.” If the duration of each video can be obtained, progress can be weighted by duration, making the progress bar reflect actual elapsed time more accurately. When durations are unavailable, counting files is fine — do not display a remaining-time estimate that has no basis.

    The status bar works well for showing the current action, such as “Processing file 3” or “Ready.” Errors should not be presented only through pop-up dialogs; they should also be written to a log area so they can be traced later.

    5. Error Handling Strategy

    In a batch task, the failure of a single file should not interrupt the entire batch. The recommended approach:

    • Catch per-file exceptions, record the filename and the reason for the failure, then continue with the remaining files.
    • After the task finishes, show a summary dialog listing the number of successes and failures.
    • Before starting, check whether the required command-line transcoding program is available. If it is missing, give clear installation guidance instead of failing mid-conversion.

    Error messages should be readable by end users, while technical details are kept in logs. Separating the two avoids bothering regular users while still giving developers what they need to troubleshoot.

    6. Common Engineering Details

    6.1 Recursive Scanning and Format Filtering

    Use directory traversal APIs to read subdirectories. Normalize extensions to lowercase before comparison and filter through a whitelist to avoid adding non-media files to the queue. The whitelist should be defined in one central place so formats can be added or removed easily.

    6.2 Handling Duplicate Output Names

    If the target file already exists, try “name(1).mp3”, “name(2).mp3”, and so on until a free name is found. This prevents overwriting existing files without requiring the user to resolve conflicts manually.

    1. function generate_unique_path(directory, base_name, extension):
    2. candidate = directory/base_name.extension
    3. index = 1
    4. while candidate exists:
    5. candidate = directory/(base_name + "(" + index + ")." + extension)
    6. index = index + 1
    7. return candidate

    6.3 Choosing the Default Output Directory

    The default output directory directly affects usability. Two common options:

    • The source file’s directory: Results sit next to the original files, matching the intuitive expectation of “convert and see it immediately.”
    • A fixed user directory: Centralized output management, suitable for large batch jobs.

    It is not recommended to use the program’s own directory as the default output location. When installed in a system directory or a permission-protected location, the program often lacks write access and conversion will fail outright. A more robust approach is to provide a configurable output directory and remember the user’s last choice at startup.

    6.4 Encapsulating Formats and Parameters

    Encapsulate the output format and its parameters (bitrate, sample rate, channel count, etc.) into a structured configuration object. The UI only collects user selections; the conversion engine only receives the configuration object. Adding a new format then only requires extending the configuration definition, without touching the UI or scheduling logic.

    7. Acceptance Testing

    Whether the code is AI-generated or handwritten, merely launching successfully does not prove the tool works. Verify against the following four categories of test cases:

    • Functional cases: Convert one file of each supported input format and check that the output format, duration, and audio quality parameters are correct.
    • Boundary cases: Empty directories, videos without audio tracks, filenames containing spaces and non-ASCII characters, duplicate output names, and insufficient disk space.
    • Interaction cases: Drag the window, click cancel, and close the program during conversion. Observe whether the UI stays responsive, whether child processes are properly cleaned up, and whether temporary files are left behind.
    • Environment cases: Uninstall the transcoding program and launch the tool to check that the missing-dependency message is clear and that erroneous operations are blocked.

    Only when all four categories pass can the tool be considered usable. Keep the acceptance records so they can be reused for regression testing in later versions.

    8. Conclusion

    The main challenges in building this kind of desktop batch conversion tool are breaking requirements into verifiable items, isolating the UI from time-consuming tasks, and ensuring the batch continues when individual files fail. Details such as the output directory and duplicate-name handling determine the quality of the user experience. When working with code generation tools, developers can use the requirement checklist and acceptance cases in this article to verify the output item by item, reducing rework and reaching a deliverable version faster.