GLM-5.3 Coding Test: Building a Video-to-Audio Extraction Tool

    This article documents a hands-on test of GLM-5.3's coding ability by asking it to build a desktop tool with a tkinter GUI that batch-converts video files to audio. It covers the test setup, a requirement-by-requirement verification table, an analysis of a thread-safety flaw in the generated sample code with a corrected runnable implementation, follow-up questions for validating edge-case handling, and steps for readers to reproduce the results in their own environment.

    1. Test Goals and Evaluation Criteria

    A model’s coding ability is usually measured by leaderboard scores, but developers care more about whether the generated code runs directly, handles exceptions, and avoids hidden problems with multithreading and resource management. This article uses a desktop application with a graphical interface as the test task and records results across four dimensions:

    1. Requirement breakdown: can the model cover all functional requirements?
    2. Code generation: does the code pass syntax checks and launch successfully?
    3. Engineering details: does the UI freeze, and are missing dependencies and file conflicts handled correctly?
    4. Follow-up verification: can the model explain the code it wrote?

    This article only documents a single test run. Every conclusion notes its verification method, so readers can repeat the checks in their own environment.

    2. Task Requirements

    The prompt contained a list of 9 requirements, mainly including:

    • Batch import of video files in MP4, AVI, MKV, MOV, FLV and other formats, exporting to MP3, WAV, AAC, FLAC and other audio formats.
    • A GUI built with Python and tkinter, including a file list, a format dropdown, a convert button, and an exit button.
    • A progress bar and a status bar, with an error dialog on conversion failure.
    • The UI must not freeze during conversion.
    • Recursively scan subdirectories for video files.
    • Automatically append a number to same-named output files to avoid overwriting.
    • Detect whether FFmpeg is installed before conversion, and provide installation guidance if it is not.

    The prompt gave no implementation approach or code skeleton. The threading model, file traversal method, and exception handling were all left to the model. This was done to observe the model’s engineering judgment, at the cost of making the result more dependent on the model’s default choices.

    3. Test Environment

    Before reproducing, record the following information first. Test results without version numbers are hard to compare with others.

    Item Requirement or check command
    Operating system Record name and version, e.g., Windows 11, macOS 14, Ubuntu 22.04
    Python 3.10 or higher; run python --version to check
    tkinter Bundled with the Python standard library; running python -m tkinter opens a test window
    FFmpeg Run ffmpeg -version to check the version; it must be callable directly from PATH
    Third-party libraries The reference code in this article uses only the standard library, with no dependency on moviepy or ffmpeg-python

    FFmpeg detection works as follows:

    • On Windows, use where ffmpeg.
    • On macOS and Linux, use which ffmpeg.
    • Inside the program, use shutil.which("ffmpeg"), which works on all three systems.

    When FFmpeg is not detected, the program should prompt the user to download and install it from the official site, add the installation directory to PATH, and then restart the program.

    4. Requirements vs. Implementation

    The table below lists the check method for each requirement. The “Original test record” column only relays observations from the original test; readers need to open the generated code and verify it themselves.

    No. Requirement Check method Original test record
    R1 Batch import videos and export audio Import 5 videos in different formats; check output format and duration Implemented
    R2 tkinter GUI Launch the program; check the file list, dropdown, and buttons Implemented
    R3 Progress bar and status bar During conversion, check whether the progress bar grows step by step and the status bar shows the current file Implemented
    R4 Error dialog on failure Add a corrupted video file; check whether a dialog pops up and the program keeps running Implemented
    R5 UI does not freeze Convert 50+ files while dragging the window; check for unresponsiveness Implemented, using a background thread
    R6 Recursive subdirectory scan Place videos in a subdirectory; check whether they are imported Implemented
    R7 Auto-numbering for same-named files Convert the same file twice; check whether name_1.mp3 is generated Implemented
    R8 FFmpeg detection before conversion Temporarily remove FFmpeg from PATH; check whether installation guidance appears Implemented
    R9 Default output directory Check whether the output directory is output/ under the source file’s directory Implemented

    R5 is the requirement most prone to errors. The original test record shows the model used a background thread, but the original sample code had an obvious problem, explained in the next section.

    5. Thread Safety: Problems in the Sample Code and the Fix

    The original test record included a piece of “sample code” that directly modified the progress bar and status bar from the worker thread and called update_idletasks(). This approach has two problems:

    1. tkinter widgets are not thread-safe. Modifying widgets from a non-main thread can cause random crashes or UI glitches on certain platforms and Tk versions.
    2. The sample code referenced an undefined task_queue and never called FFmpeg, so it could not run directly.

    The correct approach: the worker thread only performs conversion and puts results into a queue.Queue. The main thread periodically retrieves results with after() and updates the UI. Below is a runnable reference implementation:

    1. import os
    2. import queue
    3. import shutil
    4. import subprocess
    5. import threading
    6. import tkinter as tk
    7. from tkinter import ttk, messagebox
    8. def find_ffmpeg():
    9. """Return the path to ffmpeg, or None if not found."""
    10. return shutil.which("ffmpeg")
    11. def convert_one(src, dst):
    12. """Call ffmpeg to convert a single file. This function touches no Tk widgets."""
    13. # -n: fail instead of overwriting if the target exists; -vn: drop the video stream
    14. cmd = ["ffmpeg", "-n", "-i", src, "-vn", dst]
    15. result = subprocess.run(cmd, capture_output=True, text=True)
    16. if result.returncode != 0:
    17. last_line = result.stderr.strip().splitlines()[-1] if result.stderr else "Unknown error"
    18. raise RuntimeError(last_line)
    19. class ConvertApp:
    20. POLL_MS = 100 # Interval in ms for the main thread to check the queue
    21. def __init__(self, root):
    22. self.root = root
    23. self.result_queue = queue.Queue()
    24. self.errors = []
    25. self.status_var = tk.StringVar(value="Ready")
    26. self.progress = ttk.Progressbar(root, maximum=1)
    27. self.progress.pack(fill="x", padx=10, pady=5)
    28. ttk.Label(root, textvariable=self.status_var).pack(anchor="w", padx=10)
    29. def start(self, tasks):
    30. """tasks is [(src, dst), ...], built by the main thread and passed in."""
    31. if find_ffmpeg() is None:
    32. messagebox.showerror("FFmpeg missing", "Please install FFmpeg, add it to PATH, and restart the program.")
    33. return
    34. self.errors = []
    35. self.progress.configure(maximum=len(tasks), value=0)
    36. self.status_var.set("Converting...")
    37. threading.Thread(target=self._worker, args=(tasks,), daemon=True).start()
    38. self.root.after(self.POLL_MS, self._poll_queue)
    39. def _worker(self, tasks):
    40. """Background thread: only converts; results go to the main thread via the queue."""
    41. for src, dst in tasks:
    42. try:
    43. convert_one(src, dst)
    44. self.result_queue.put(("ok", src))
    45. except Exception as exc:
    46. self.result_queue.put(("error", src, str(exc)))
    47. self.result_queue.put(("done",))
    48. def _poll_queue(self):
    49. """Runs only on the main thread; writes results back to the UI."""
    50. while True:
    51. try:
    52. msg = self.result_queue.get_nowait()
    53. except queue.Empty:
    54. self.root.after(self.POLL_MS, self._poll_queue)
    55. return
    56. if msg[0] == "ok":
    57. self.progress.step(1)
    58. self.status_var.set(f"Done: {os.path.basename(msg[1])}")
    59. elif msg[0] == "error":
    60. self.progress.step(1)
    61. self.errors.append(f"{os.path.basename(msg[1])}: {msg[2]}")
    62. elif msg[0] == "done":
    63. self.status_var.set("Conversion complete")
    64. if self.errors:
    65. messagebox.showerror("Some files failed", "\n".join(self.errors))
    66. return

    Key points of this code:

    • All reads and writes of Tk widgets happen on the main thread.
    • The worker thread sends results through queue.Queue and never calls UI methods directly.
    • Errors are collected first and shown in a single dialog after conversion ends, avoiding one dialog per failed file interrupting the workflow.
    • ffmpeg -n fails instead of overwriting when the target file already exists. The same-name numbering logic must be done when building tasks; this example omits that step.

    6. Follow-up Questions and Edge-Path Verification

    After the code was generated, this test asked a follow-up question: is the default output directory the directory where the program itself resides? The original test record shows the model answered that the default directory is an output/ subdirectory under the source file’s directory, created automatically if it does not exist, and explained how to change it to a custom path.

    This answer must be verified against the code. Readers should check three places:

    1. Whether the target-path construction uses os.path.dirname(src) rather than os.getcwd().
    2. Whether there is a call like os.makedirs(out_dir, exist_ok=True).
    3. How many places in the code need to change to modify the output location.

    Two more follow-up questions are recommended to test the model’s understanding of edge paths:

    • “When FFmpeg is missing, on which line does the program stop? Point to the code location.”
    • “If the target disk fills up, where does the temporary file from the failed conversion remain?”

    A correct answer should point to specific functions and conditions. If the model only gives a vague description, it has not truly understood the code.

    Edge-path checks should cover at least the following cases:

    • The source file does not exist.
    • The source file is corrupted, e.g., a truncated MP4.
    • The output directory has no write permission.
    • FFmpeg is not installed.
    • The target file already exists.

    For each case, confirm whether the program crashes, whether it gives a readable message, and whether it affects the conversion of subsequent files.

    7. Steps to Reproduce the Failure Case

    To verify the thread-safety issue, readers can compare the two approaches with the following steps.

    1. Prepare 200 small video files