An agency sends us a finished video. We need a smaller copy for a website, a version for a desktop computer, or a file that will play on a kiosk. The request keeps coming back with a different detail. Today the file needs to be smaller. Tomorrow it needs to fit a different screen.
On Linux, we could write a script that calls FFmpeg and reuse it when needed. That may be enough when the task is occasional and one person always handles it. When files, destinations and settings keep changing, we can put the recurring choices in an interface. The person using it selects a video, chooses a preset and picks where to save the result. Later, we can add a feature when a real need comes up, building on a workflow we have already tried.
We begin this practical series with Magic Video, a local web app for Linux that can be developed and used on any distribution. It opens in a browser and runs FFmpeg on the same computer. We will describe the task to an AI assistant, give Codex a detailed prompt, and follow the tests that take us from a working conversion to a reusable tool. This continues the discussion in Could custom software solve one problem?.
1. Start with the work we already do
Before opening Codex, write down what file arrives, which decisions we make, and what we need to deliver. For the web, we can start with MP4, H.264 video and AAC audio. For a desktop or kiosk, we need to know which player will be used and test the file on that device. On the work computer, we want to choose one video at a time, use a few clear presets and keep the original untouched.
We can begin the conversation with the AI assistant like this.
An agency sends us videos that we often need to resize or make smaller for a website, desktop or kiosk. I want a small local web app for Linux that uses FFmpeg. Ask me questions that could change the result or how we test it. Then help me write a brief for Codex.
We give the assistant answers that can become project decisions. We want Web balanced, Smallest file and Best quality. Resizing and compression belong on the main screen. Cropping, trimming and audio options can go under advanced settings. The app runs locally behind Apache, uses PHP and keeps its history in text files. Bootstrap and jQuery stay inside the project, so the interface works without an Internet connection.
We can already describe the first end-to-end test. Load a clip, choose Web balanced, set a maximum width and save an MP4 that opens from the file manager.
2. Ask the AI assistant to write the XML prompt
A sentence like “let me choose the output folder” describes a control, but leaves an important question unanswered. The web server may be able to see the folder and still be unable to write to it. We turn the requirement into an observable test. The Check button creates a temporary file using the same account as Apache, writes to it and removes it. If that test fails, the user should see why before starting a conversion.
We ask the assistant to structure the rest of the specification in the same way.
Turn our decisions into an XML prompt for Codex. Put features, environment, installation, error handling and acceptance tests in separate sections. For each important behaviour, say what someone testing the app should be able to observe. Ask me to decide anything that is still ambiguous.
We read the prompt before handing it over. Three details make a practical difference in Magic Video.
- Under
<output>, the suggested name follows the selected preset until we edit it. After that, it keeps our manual choice. If the file already exists, we try the same name and check that the first result is still there. - Under
<progress>, upload measures the bytes sent, analysis shows a waiting state, and conversion uses FFmpeg progress data. The interface reaches 100% only when the result is ready. - Under
<testing>, we test a successful conversion, an unwritable destination, a duplicate filename and an upload that is too large. For every case, we state the expected message or result.
3. Give Codex the brief and open a preview
On Linux, open a project folder in Codex. Attach the XML file or paste the complete prompt. Tell Codex what we want to be able to try at the end of the first development pass.
Use this XML as the specification for Magic Video. Check the environment, implement the app in the project folder and open a local preview. Run a conversion with a synthetic clip. Tell me how to repeat the test, where to find the output and which checks need to be repeated under Apache.
As soon as the preview opens, choose System and check that PHP can find FFmpeg, FFprobe, the required encoders and the working folders. PHP connects the interface to the processes that handle the file. FFprobe reads the video properties and FFmpeg performs the conversion. The Codex summary should tell us which interface controls are connected to the backend. For example, the player in Source shows the original file. We open the converted file from its destination.
4. Run a complete conversion
We can ask Codex to create a short synthetic clip with an audio track. Follow these steps to reproduce the screenshots in this article.
- Load a clip that is 1280 × 720 and 8 seconds long. Check that the preview opens and shows its dimensions and duration.
- Choose Web balanced, set the maximum width to 854 px and select MP4. Enter
clip-webas the filename. The interface adds the extension. - Choose an existing output folder, click Check, then Start processing. When the progress panel says the file is ready, open it from the folder and check the picture and sound.
- Use FFprobe to inspect the file in the output folder.
ffprobe -v error -show_entries stream=codec_name,width,height:format=duration,size -of json clip-web.mp4
In our test, the result is an 854 × 480 MP4 with H.264 video, AAC audio and a duration of 8 seconds. Its size is about 925 KiB. The weight also depends on the source, so we measure the actual result. FFprobe documentation
A successful conversion gives us a baseline. From there, we can test the choices the app should reject and the ones it should preserve when we change settings.
| Test | What to check |
|---|---|
| Change the preset after manually editing the filename | The chosen name remains. The extension follows the format. |
| Repeat the conversion with the same name | The app reports the duplicate and keeps the existing file intact. |
| Choose a folder the server cannot write to | Check reports the problem before processing begins. |
| Change an advanced setting | For a trim, check the resulting duration. For an audio-only format, video controls should be disabled and the result should contain an audio track. |
If a test fails, give Codex the steps we took and what we observed. After the fix, repeat that case and the MP4 conversion that was already working.
5. Turn feedback into a repeatable test
In the project, we asked for a more compact interface. To let Codex verify the change, we specified what needed to fit on screen and the available space.
At 1280 × 640 and normal zoom, load a clip and start processing. I need to see the source, settings, start button and progress together. Keep the three columns and put advanced options in a dialog. Check the result with the video loaded.
A real file of about 3 GB exposed a different issue. PHP under Apache accepted uploads up to 2 GiB. The smaller clip worked, but the work video stopped during upload, before reaching FFmpeg. Our message to Codex needs to describe the difference between the two tests.
The short clip starts converting. With a video of about 3 GB, I click “Start processing” and the job stops before conversion. Check the effective limit under Apache. Detect files that are too large before uploading and show separate progress for upload and conversion.
On the local installation, the limit was raised to 8 GiB. The panel shows bytes during upload, a waiting state during analysis, and elapsed media time during conversion. To repeat the test, check the effective limit in System, run the same short conversion, then retry with a file representative of the videos we receive. The prompt also asks for a case where a file exceeds the declared limit and the app rejects it with a clear message.
6. Install under Apache and repeat the workflow
For Magic Video, deployment means installing the app on the same Linux computer. We ask Codex to provide the project, a README, install.sh and an update procedure with a backup. The installer should identify the DocumentRoot, the folder served by Apache’s default site, and check the destination before copying any files.
On the computer that hosts Apache, run this command from the Magic Video project folder.
sudo bash ./install.sh
Enter any password in the terminal. Then open http://localhost/Magic%20Video/ and repeat the test with the app served by Apache.
- Open System and check dependencies, the PHP process identity and effective upload limits. Run the output-folder write check from the main screen.
- Repeat the MP4 conversion. Open the result in the file manager and check that the operation appears in History.
- Ask Codex to check that a direct HTTP request to a log file is rejected. The normal way to view the history is through the History dialog.
In the project, Apache could save the result, but the user could not open it from the file manager. After correcting the permissions, we checked that the file could be read and that direct HTTP access to logs was blocked. This had to be tested on the real installation. In preview, the development server ran as the user who started it.
For the next delivery, we can select a preset and repeat a workflow that has already been checked. If we later need a profile for a particular kiosk, we can start from a file that plays correctly on that device, ask Codex to add the preset, and include a test using the same player.
7. Package the application and manage updates
When we want to install the app on another computer or share it with a team, we prepare an identifiable release. For this project, we can distribute a .tar.gz archive containing the application files, local assets, installer, README and release notes. The package lists required dependencies such as PHP, Apache, FFmpeg and FFprobe, together with the checks to repeat after installation. Recipients check that their Linux distribution provides those components and follow the instructions for their environment.
The package contains the code and files needed to update the app. Keep machine-specific configuration, credentials, uploaded videos, output files, logs and job state separate. This data belongs to the installation and should not be removed when replacing application files. The archive can be distributed through a project repository, an artifact registry or an internal download area. A numbered version, brief release notes and a checksum help identify and verify the package.
A practical Magic Video update
In this project, a dedicated script updates the interface. First wait for any active conversions to finish. Then run the script from the folder containing the new version. On the example computer, where the application uses this installation path, run:
sudo bash '/var/www/html/magic_video/Magic Video/update-interface.sh'
This is the essential content of the script used in the project:
#!/usr/bin/env bash
set -euo pipefail
[[ $EUID -eq 0 ]] || { echo 'Run with sudo bash'; exit 1; }
src=$(cd -- "$(dirname -- "$0")" && pwd)
target='/var/www/html/Magic Video'
[[ -f "$target/index.php" && -d "$target/assets" ]] || {
echo 'Magic Video installation not found'
exit 1
}
backup=$(mktemp -d /tmp/magic-video-interface-backup.XXXXXXXX)
for file in index.php api.php worker.php assets/app.css assets/app.js; do
cp -p "$target/$file" "$backup/$file"
install -o root -g root -m 644 "$src/$file" "$target/$file"
done
echo "Interface updated. Backup: $backup"
echo 'Reload Magic Video in the browser.'
The script checks for administrator privileges and confirms the installation exists. It saves the current files in a temporary directory, then installs the new index.php, api.php, worker.php, assets/app.css and assets/app.js. It prints the backup path, which starts with /tmp/magic-video-interface-backup.. Then force-refresh Magic Video in the browser. If a command fails, set -e stops the script, but it does not automatically restore files already replaced. For this example, rollback is a manual step.
Next repeat a short, meaningful workflow. Open System, select a test video, check the output folder, start an MP4 conversion, and inspect the result and history. If the new version has a problem, restore the saved files, replacing <backup-folder> with the path printed by the script:
sudo cp -a '<backup-folder>/.' '/var/www/html/Magic Video/'
After restoring, reload the page and repeat the control conversion. This script’s backup is temporary. Before a broader update, copy it somewhere durable because the system may remove files from /tmp. The installation path shown here belongs to the example computer. On another distribution, check the DocumentRoot and adapt the update script’s target path.
This script updates only the interface and conversion-worker files. It does not update a complete release, restore Apache configuration, or migrate data and settings. For a release that changes installation, dependencies or data structure, first record the changes, save the code and configuration, and prepare migration and rollback steps. Test the complete procedure on a staging installation, then apply the package to the working installation and repeat the main checks. If an update changes persistent data, rollback must also restore a copy of that data.
Keeping the package, release notes and restore instructions current makes maintenance repeatable. A colleague receiving a release can understand what it installs, what it preserves and how to return to the previous version.
8. Choose how to manage access
This example does not implement authentication inside Magic Video. The app was built for local use. If we make it reachable to other people or over a network, we need to decide who can open it before giving users access.
We can protect Apache with Basic Auth, build authentication into the app, add a second factor (MFA) or integrate Magic Video with the company’s SSO. The right option depends on the environment and identity systems already in place. We can ask Codex to keep the interface and services separate, protect API endpoints that start conversions, and avoid attaching permissions to a visual control alone. Test the chosen access model through the actual installation and workflow that people will use.
The design goal is to keep the application maintainable and easy to integrate. Authentication and authorisation should be addable without rewriting the conversion engine, screens or file handling. Document where user identity is received, which operations check permissions and how to verify changes to updates or configuration.
9. Ask a dedicated agent to write the documentation
Code and a prompt are not enough to hand the project over to a colleague. We can ask a dedicated agent to write the documentation while another workstream handles code changes. Give it the repository, original prompt, design decisions and test results. Ask it to verify facts, so the documentation does not describe a proposed feature as if it were already available.
A focused assignment could read:
Read the Magic Video project and its prompt. Write documentation for people who install, use, update or extend it. Explain the component structure, configuration, dependencies, conversion flow, permissions, retained data, update and rollback procedure. Distinguish implemented behaviour from planned work. Do not claim that application-level authentication is available: this version does not include it. Explain how Apache access controls or a company identity system could be integrated without attributing unverified features to the project. Check every instruction against the code and list anything you cannot confirm.
Once the agent finishes, compare its instructions with the code and repeat the installation and update steps by following the documentation. Keep release notes and acceptance checks current too. A colleague should be able to understand how to start the app, release a new version and integrate any parts needed for their environment.
Here is an example of the kind of excerpt we ask the agent to produce for the maintenance guide:
Updating the interface
Wait until active conversions finish. Run
update-interface.shfrom the folder containing the new version. The script saves the current application files under/tmp/magic-video-interface-backup.*and updatesindex.php,api.php,worker.php,assets/app.cssandassets/app.js. The backup contains these files, but not the Apache configuration or thelogs/,var/andoutput/folders.When the script finishes, force-refresh the page. Check that System reports no missing dependencies, convert a short test video and verify the result with FFprobe. To roll back, copy the files from the backup path printed by the script. Save the backup elsewhere before restarting or cleaning the system, because it is in a temporary directory.
Access
This version has no internal authentication. Configure access in the hosting environment. Before enabling the app for multiple people, verify that access controls also cover API requests that start conversions.
An excerpt makes clear what turns documentation into an operational guide: it lists affected files, says which data the backup excludes, and gives a check to repeat. If the agent cannot find a feature in the code, it should say that the feature is missing or unverified.
The XML prompt in English
The block below is an English translation of the prompt prepared in the project chat. We have made operating-system references independent of the Linux distribution. The project conversation and original prompt were in Italian; this translation keeps the same requirements and decisions. We can also download the English XML file and attach it to a new Codex chat.
<prompt>
<role>
You are a developer tasked with building Magic Video from scratch,
a local web app for Linux that makes FFmpeg easier to use.
Implement and verify the app; do not stop at proposing a plan.
</role>
<objective>
Build a complete app to resize, compress, crop, trim and convert video,
as well as extract and optimise audio. The app must run locally,
without accounts, databases or cloud services.
</objective>
<technologies>
<backend>PHP 8.1 or later, FFmpeg and FFprobe.</backend>
<frontend>Bootstrap 5, jQuery, HTML and CSS.</frontend>
<dependencies>
Include Bootstrap and jQuery in the project: no CDN dependencies
and no Internet connection required during use. Keep their licences.
</dependencies>
</technologies>
<installation>
<destination>
Use the existing default Apache virtual host, in a subfolder named
exactly "Magic Video". Do not create a new virtual host.
</destination>
<checks>
Identify the default HTTP virtual host and verify its effective
DocumentRoot before installing. Do not assume it is /var/www/html.
Stop the installation with an explanation if you cannot determine it.
</checks>
<privileges>
Do not ask for passwords in chat. If privileges are needed, use an
interactive terminal so the user can enter them there.
If sudo is blocked by the environment, say so immediately, complete
the project in the accessible workspace, and provide one manual
command to install it on the actual computer.
</privileges>
<scripts>
Provide install.sh for the first installation and an update script
with backup and recovery in case of an error.
Do not silently overwrite an existing installation.
Do not install packages automatically.
</scripts>
<permissions>
Apache must be able to read the code, but the web process must not be
able to modify it. Working folders must be writable by the effective
Apache user, normally www-data. Results must be readable by the local
user in the file manager. Do not use permissions 777.
</permissions>
</installation>
<features>
<source>
Select one file at a time using a file picker or drag and drop.
Show its name, size, resolution and duration when available.
Keep the original unchanged.
</source>
<presets>
Use a dropdown with:
- Web balanced: a compromise between quality and file size.
- Smallest file: stronger compression and less detail.
- Best quality: higher quality and potentially a larger file.
For H.264, use CRF 23, 29 and 18 respectively, with the FFmpeg
medium preset.
</presets>
<resizing>
Offer maximum widths of 1920, 1280 and 854 pixels, or original
resolution. Preserve aspect ratio, do not upscale, and ensure the
dimensions are compatible with the selected codec.
</resizing>
<formats>
<format>MP4: H.264, AAC, yuv420p pixel format and faststart.</format>
<format>MKV: H.264 and AAC.</format>
<format>WebM: VP9 and Opus.</format>
<format>MP3 audio only.</format>
<format>M4A audio only, with AAC and faststart.</format>
<format>WAV audio only, PCM.</format>
Disable video-only controls when an audio-only format is selected.
</formats>
<advanced_options>
Organise them in a tabbed dialog:
- Duration: start and duration in seconds, including decimals.
- Crop: width, height, X and Y position in original pixels.
- Audio: optional normalisation to -16 LUFS.
- MB limit: optional maximum video file size.
Validate values on the server. Crop before resizing.
Prevent crops outside the source and trims beyond its duration.
The MB limit must warn about possible quality loss. Use a bitrate
strategy appropriate to the duration and measure the final result.
If it exceeds the requested maximum, report the problem and discard
only that job's result. Do not promise an exact file size.
</advanced_options>
<output>
<folder>
Allow the user to enter the absolute path of an existing folder.
A "Check" button must actually create a temporary file, write to it
and remove it. Repeat the check before conversion. Under Apache,
run the check as the effective web-process user.
</folder>
<filename>
Suggest a name based on the source file and preset:
name-web, name-compressed or name-quality. Allow editing the name.
After a manual edit, do not replace it when the preset changes.
Show the extension separately and update it automatically for the
selected format. Avoid duplicate extensions.
</filename>
<protection>
Validate the name on the server too: no paths, separators, control
characters or names too long for the filesystem. Support valid
Italian and Unicode names. Never overwrite existing files: reserve
the destination atomically and handle concurrent requests using the
same name. An error must never delete a pre-existing file.
</protection>
</output>
</features>
<interface>
<style>
Professional, compact, ergonomic and colourful GUI. Use a dark
blue-grey background, turquoise for the source, violet for settings
and amber for the destination. Avoid oversized slogans, playful
decoration and wasted space. Keep text readable, provide adequate
contrast and support keyboard navigation.
</style>
<layout>
Use a short header with the app name, History and System.
On desktop, arrange three columns side by side:
1. Source and preview.
2. Preset dropdown, width and format.
3. Filename, output folder, check and start controls.
Reduce the video preview to about 100–122 pixels high, preserving its
aspect ratio and playback controls. Show the progress bar below all
three columns.
At normal zoom, verify that the main controls, loaded preview and
progress fit without scrolling in a 1280x640 desktop viewport. Do not
achieve this by clipping content with overflow hidden or making text
unreadable.
Open History, diagnostics and advanced options in dedicated dialogs
so they do not make the main screen taller. Allow the scrolling needed
on small screens and at high zoom.
</layout>
<preview>
State clearly that the preview plays the original file and does not
simulate the result of compression or cropping. Connect every
operational control to the backend.
</preview>
</interface>
<progress>
<phases>Upload, analysis, conversion, finalisation and completion.</phases>
<bar>
Use a prominent panel with a coloured bar and large percentage.
Explicitly identify the phase to which the percentage refers.
</bar>
<upload>
Read real progress from the request's upload progress event.
Show bytes transferred and total, speed, elapsed time and estimated
remaining time when it can be calculated.
</upload>
<analysis>
Show an indeterminate state while checking the file; do not invent
percentages.
</analysis>
<conversion>
Run FFmpeg in a background PHP CLI worker. Read its output through
-progress and calculate progress against the duration of the requested
segment. Show processed and total duration, speed relative to real
time, elapsed time and estimated remaining time. Present remaining
time as a changing estimate. Do not show 100% until FFmpeg exits
successfully and the result has been verified.
</conversion>
<robustness>
Update state files atomically so JSON is never partial. Do not overlap
polling requests. Distinguish a conversion error from a lost
connection: if polling fails, warn that the server-side job may still
be running. Prevent duplicate starts while a job is active. Never let
a click go without visible feedback.
</robustness>
</progress>
<diagnostics>
On startup, check:
- Compatible PHP version.
- Extensions and functions that are actually required.
- Presence and version of FFmpeg and FFprobe.
- Availability of the required encoders.
- Write access to logs, working-data and output folders.
- PHP process identity.
- Effective PHP upload limits.
If something is missing, provide concrete instructions without
installing packages. Distinguish checks run in the preview from those
run under Apache.
</diagnostics>
<large_files>
For the local installation, configure an 8 GiB file limit and a slightly
larger POST limit. Also check Apache limits and timeouts. Apply settings
only to this app when possible. Handle both mod_php and PHP-FPM without
adding directives that are incompatible with the active handler.
Report effective limits to the frontend and check file size before
upload. Explicitly handle requests that are too large, incomplete
uploads, insufficient disk space and non-JSON responses. Show a useful
message instead of a generic connection error. Never read multi-gigabyte
videos entirely into memory.
</large_files>
<history>
Record job start, completion and errors in daily text files inside
logs/, without a database. A JSON line per event is acceptable.
Include the date, source name, destination, final size and any relevant
error. Show a readable history of the latest 100 events in the
interface. Do not present raw JSON as the normal interface.
</history>
<local_security>
Limit HTTP access to local use. Deny direct HTTP access to logs/, working
data, output, workers, internal libraries and installation scripts.
Do not rely only on .htaccess: protection must work even when
AllowOverride None is set.
Do not allow arbitrary command execution. Pass FFmpeg arguments safely
and validate all options. Protect state-changing requests against CSRF.
Escape content shown in the interface. Remove temporary copies when a
job ends, including on error. Never delete original sources or existing
results.
</local_security>
<suggested_structure>
index.php: interface.
api.php: diagnostics, start, status, folder and history.
lib.php: validation, FFprobe, command building and utilities.
worker.php: conversion and real progress.
router.php: protections for PHP preview server.
assets/: Bootstrap, jQuery, CSS, JavaScript and licences.
logs/: daily history.
var/: temporary uploads and job state.
output/: default destination.
install.sh: installation verified under Apache.
update-interface.sh: update application files with a backup.
README.md: instructions, limits and checks.
</suggested_structure>
<workflow>
Inspect the environment before changing files.
Do not keep an old draft as a project constraint.
Do not ask again for decisions already included in this prompt.
Make ordinary implementation choices independently.
Open a preview in a Codex panel or tab as soon as possible.
State what is operational and what is only a visual representation.
Do not publish the app on the Internet or use external hosting.
If privileged installation is impossible, complete and test the
workspace and leave one clear manual step. Do not claim that the actual
installation has been verified unless you have checked it.
</workflow>
<testing>
Use small synthetic video and audio files; do not depend on personal
files. Verify:
- PHP, JavaScript and shell-script syntax.
- Real conversion and resulting codecs with FFprobe.
- Resizing, cropping and trimming.
- Audio extraction and normalisation.
- Real intermediate percentages and 100% only when the result is ready.
- FFmpeg errors without false completion.
- Automatic filename, manual edits and extension.
- Filename collisions without changing existing files.
- Rejection of names containing paths.
- Actual write and remove check.
- Explicit rejection of oversized uploads.
- HTTP protection of logs and internal files.
- 1280x640 layout with preview and progress visible.
- Dialog behaviour and accessibility of invalid fields.
Remove temporary test files and pages. Document checks that could not
be run.
</testing>
<deliverables>
Deliver the working project, an openable preview, installation and
update scripts, and a concise README. Summarise the checks performed
and any remaining manual steps.
</deliverables>
</prompt>