Warning, /firebird/docs/tutorials/03_saving_video.md is written in an unsupported language. File is not indexed.
0001 # Saving Videos and Frames
0002
0003 This tutorial explains how to record the Firebird event display as a video or as individual PNG frames.
0004 Firebird provides two approaches: **real-time screen recording** for quick captures, and **offline 4K capture**
0005 for producing smooth, high-resolution frame sequences suitable for professional presentations and publications.
0006
0007 ## 1. Open the Debug Panel
0008
0009 Both recording methods are accessed through the debug GUI panel.
0010
0011 1. Load your geometry and event data as usual (see [Tutorial 01](./01_basic_ui) if you need help).
0012 2. Click the **bug icon** (🪲) in the header toolbar to toggle the debug panel.
0013 3. A floating panel will appear in the top-right area of the display.
0014
0015 ## 2. Real-Time Screen Recording
0016
0017 The simplest approach captures whatever is on screen in real time, including your mouse interactions
0018 and any animations. This uses the browser's built-in `MediaRecorder` API.
0019
0020 1. In the debug panel, click **"Start recording"**.
0021 2. Interact with the display — rotate, zoom, play animations, switch events, etc.
0022 3. Click **"Stop recording"** when you're done.
0023 4. Click **"Download recording"** to save the result as a `.webm` video file.
0024
0025 > **Note:** Real-time recording captures at whatever frame rate your browser achieves.
0026 > If performance drops during recording, the resulting video may have stutters or frame drops.
0027 > For smooth, presentation-quality output, use the offline capture method described below.
0028
0029 ## 3. Offline 4K Frame Capture
0030
0031 The offline capture method renders each frame independently at **3840 x 2160** (4K UHD) resolution.
0032 Because each frame is rendered one at a time and saved as a PNG, the result is perfectly smooth
0033 regardless of your machine's real-time performance.
0034
0035 ### Starting a Capture
0036
0037 1. Expand the **"4K Capture"** folder in the debug panel.
0038 2. Click **"▶ Start Capture"**.
0039 3. The progress indicator will show the current frame count:
0040 - During the collision animation phase: `Frame 42 (collision phase)`
0041 - During the time evolution phase: `Frame 120 / 2000`
0042
0043 The capture runs through two phases automatically:
0044 - **Collision phase** — the electron-ion collision animation
0045 - **Time phase** — stepping through the event time, showing particles propagating through the detector
0046
0047 ### Stopping Early
0048
0049 You don't have to wait for the full capture to finish. If you have enough frames:
0050
0051 1. Click **"⏹ Stop"** at any time.
0052 2. The progress indicator will show how many frames were captured.
0053 3. All frames captured before stopping are preserved.
0054
0055 ### Downloading Frames
0056
0057 Once the capture finishes (or you stop it early):
0058
0059 1. Click **"💾 Download Frames"**.
0060 2. **On Chrome/Edge:** A folder picker dialog appears. Choose (or create) a folder and Firebird
0061 writes each PNG directly into it — no zipping, no memory spike.
0062 3. **On Firefox/Safari:** Frames are automatically split into multiple smaller ZIP files
0063 (~200 frames each) and downloaded sequentially. The files are named
0064 `frames_4k_part01.zip`, `frames_4k_part02.zip`, etc. Each contains a `frames/` folder
0065 with files like `frame_000000.png`, `frame_000001.png`, etc.
0066
0067 Progress is shown in the debug panel and via a notification bar at the bottom of the screen.
0068
0069 > **Tip:** The frames stay in memory until you start a new capture.
0070 > You can download them multiple times if needed.
0071 >
0072 > **Why not one big ZIP?** A 4K capture can easily exceed 2 GB, which is beyond the
0073 > browser's single-allocation limit. The folder picker avoids this entirely;
0074 > the chunked ZIP fallback keeps each file well under the limit.
0075
0076 ## 4. Converting Frames to Video
0077
0078 Once you have the PNG frames, you can assemble them into a video using FFmpeg.
0079
0080 ### Install FFmpeg
0081
0082 If you don't have FFmpeg installed:
0083
0084 ```bash
0085 # Ubuntu/Debian
0086 sudo apt install ffmpeg
0087
0088 # macOS (Homebrew)
0089 brew install ffmpeg
0090
0091 # Or download from https://ffmpeg.org
0092 ```
0093
0094 ### Encode to MP4
0095
0096 Unzip the frames and encode them:
0097
0098 ```bash
0099 unzip frames_4k.zip
0100 cd frames
0101
0102 # High-quality H.264 MP4 at 60fps
0103 ffmpeg -framerate 60 -i frame_%06d.png -c:v libx264 -pix_fmt yuv420p -crf 18 output_4k.mp4
0104 ```
0105
0106 The key parameters:
0107 - `-framerate 60` — playback speed (60 fps for smooth motion)
0108 - `-crf 18` — quality level (lower = better quality, 18 is visually lossless)
0109 - `-pix_fmt yuv420p` — pixel format for broad compatibility
0110
0111 ### Other Useful Encoding Options
0112
0113 ```bash
0114 # Smaller file size (slightly lower quality)
0115 ffmpeg -framerate 60 -i frame_%06d.png -c:v libx264 -pix_fmt yuv420p -crf 23 output.mp4
0116
0117 # 30 fps (slower playback, half the duration)
0118 ffmpeg -framerate 30 -i frame_%06d.png -c:v libx264 -pix_fmt yuv420p -crf 18 output_30fps.mp4
0119
0120 # Lossless (very large file)
0121 ffmpeg -framerate 60 -i frame_%06d.png -c:v libx264 -pix_fmt yuv420p -crf 0 output_lossless.mp4
0122
0123 # WebM/VP9 for web embedding
0124 ffmpeg -framerate 60 -i frame_%06d.png -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm
0125 ```
0126
0127 ## 5. Tips
0128
0129 - **Memory usage:** Each 4K PNG frame is roughly 5-15 MB uncompressed in memory.
0130 A 2000-frame capture may use several GB of RAM. Close other browser tabs if needed.
0131 - **Start a new capture** to clear the previous frames from memory.
0132 - **Camera position:** Set up your camera angle before starting the capture.
0133 The camera will move automatically during the collision and time animation phases.
0134 - **Animation speed:** The offline capture respects the current animation speed setting.
0135 Adjust it before capturing if you want faster or slower playback.
0136
0137 ## Next Steps
0138
0139 - Learn about the [Firebird data format (DEX)](../dex) to prepare your own event data.
0140 - See [DD4Hep Plugin](../dd4hep-plugin) for generating trajectories from Geant4 simulations.