Skip to content

Commit 18d29ac

Browse files
authored
Add video recording, re-license as GPL v2 (#98)
* Add Record, re-license as GPL v2, FFmpeg is now an optional dependency * Add video controls * Add command line and recording to Lua * Update readme/docs add ffmpeg options
1 parent 8c79404 commit 18d29ac

145 files changed

Lines changed: 30982 additions & 121 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ jobs:
4141

4242
- name: install dependencies
4343
run: |
44-
sudo apt-get update && sudo apt-get install -y build-essential xvfb x11-apps imagemagick xorg-dev mesa-common-dev libx11-dev libxrandr-dev libgl1-mesa-dev libglu1-mesa-dev libfreetype6-dev libopenal-dev libsndfile1-dev libudev-dev libxinerama-dev libxcursor-dev xvfb x11-apps vulkan-tools libvulkan-dev vulkan-validationlayers-dev spirv-tools
44+
sudo apt-get update && sudo apt-get install -y build-essential xvfb x11-apps imagemagick xorg-dev mesa-common-dev libx11-dev libxrandr-dev libgl1-mesa-dev libglu1-mesa-dev libfreetype6-dev libopenal-dev libsndfile1-dev libudev-dev libxinerama-dev libxcursor-dev xvfb x11-apps vulkan-tools libvulkan-dev vulkan-validationlayers-dev spirv-tools libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
4545
python3 -m pip install gcovr
4646
- name: linux-linux
4747
run: |
48-
./build.sh -t -r -e
48+
./build.sh -r -e --ffmpeg
4949
mkdir linux-x86_64
50+
cp build/sfoav/sfoav linux-x86_64/sfoav-ffmpeg-linux-x86_64
51+
mv build/sfoav/sfoav sfoav-ffmpeg
52+
./build.sh -t -r -e
5053
cp build/sfoav/sfoav linux-x86_64/sfoav-linux-x86_64
54+
mv build/sfoav/sfoav sfoav
5155
cp LICENSE* linux-x86_64/
5256
5357
- name: unit tests with coverage
@@ -91,14 +95,50 @@ jobs:
9195
export PID=$!
9296
sleep 10
9397
xwd -root -silent | convert xwd:- png:screenshot-meshes.png
94-
sleep 5 && kill $PID
98+
sleep 5 && kill -9 $PID
99+
sudo pkill Xvfb
100+
101+
- name: jo_mpeg video test
102+
run: |
103+
export DISPLAY=:99
104+
sudo Xvfb :99 -screen 0 512x512x24 &
105+
sleep 5
106+
MESA_GL_VERSION_OVERRIDE=3.3 ./sfoav tests/test_structure_input/HISTORY -script tests/video.lua &
107+
export PID=$!
108+
sleep 10 && kill -9 $PID
109+
sudo pkill Xvfb
110+
mkdir jo_mpeg
111+
mv *.mp4 jo_mpeg/jo_mpeg.mp4
112+
113+
- name: ffmpeg video test
114+
run: |
115+
export DISPLAY=:99
116+
sudo Xvfb :99 -screen 0 512x512x24 &
117+
MESA_GL_VERSION_OVERRIDE=3.3 ./sfoav-ffmpeg tests/test_structure_input/HISTORY -script tests/video.lua &
118+
export PID=$!
119+
sleep 10 && kill -9 $PID
120+
sudo pkill Xvfb
121+
mkdir ffmpeg
122+
mv *.mp4 ffmpeg/ffmpeg.mp4
95123
96124
- name: upload screenshots
97125
uses: actions/upload-artifact@v4
98126
with:
99127
name: screenshots
100128
path: build/screenshot-meshes.png
101129

130+
- name: upload ffmpeg video
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: ffmpeg
134+
path: ffmpeg/ffmpeg.mp4
135+
136+
- name: upload jo_mpeg video
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: jo_mpeg
140+
path: jo_mpeg/jo_mpeg.mp4
141+
102142
- name: build artifact
103143
uses: actions/upload-artifact@v4
104144
with:
@@ -204,8 +244,9 @@ jobs:
204244
for release in linux-x86_64 macos windows;
205245
do
206246
mkdir $release
207-
mv sfoav-$release* $release/
247+
mv sfoav*-$release* $release/
208248
cp LICENSE* $release/
249+
cp README.md $release/
209250
cp SimpleFastOpenAtomicVisualiser.pdf $release
210251
zip -r $release.zip $release/*
211252
done

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ include/vendored/VulkanSDK/Windows/Include
1414
include/vendored/VulkanSDK/Windows/lib
1515
docs/html
1616
docs/latex
17+
*.mp4

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ add_compile_definitions(PRODUCT_NAME=${PRODUCT_NAME})
2323
add_compile_definitions(DESCRIPTION=${DESCRIPTION})
2424
add_compile_definitions(COPYRIGHT=${COPYRIGHT})
2525

26+
if(FFMPEG)
27+
add_compile_definitions(WITH_FFMPEG)
28+
endif()
29+
2630
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS shader)
2731

2832
set(CMAKE_CXX_STANDARD 17)
@@ -127,6 +131,36 @@ target_include_directories(
127131
${Vulkan_INCLUDE_DIR}
128132
)
129133

134+
if (FFMPEG)
135+
find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
136+
find_library(AVCODEC_LIBRARY avcodec)
137+
138+
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
139+
find_library(AVFORMAT_LIBRARY avformat)
140+
141+
find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
142+
find_library(AVUTIL_LIBRARY avutil)
143+
144+
find_path(SWSCALE_INCLUDE_DIR libswscale/swscale.h)
145+
find_library(SWSCALE_LIBRARY swscale)
146+
147+
target_link_libraries(${OUTPUT_NAME}
148+
${AVCODEC_LIBRARY}
149+
${AVFORMAT_LIBRARY}
150+
${AVUTIL_LIBRARY}
151+
${SWSCALE_LIBRARY}
152+
)
153+
154+
target_include_directories(
155+
${OUTPUT_NAME}
156+
PUBLIC
157+
${AVCODEC_INCLUDE_DIR}
158+
${AVFORMAT_INCLUDE_DIR}
159+
${AVUTIL_INCLUDE_DIR}
160+
${SWSCALE_INCLUDE_DIR}
161+
)
162+
endif()
163+
130164
if (OSX)
131165
# https://stackoverflow.com/questions/18391487/compiling-with-glfw3-linker-errors-undefined-reference
132166
target_link_libraries(${OUTPUT_NAME} "-framework Cocoa -framework IOKit -framework CoreVideo")

DOCUMENTATION.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
SimpleFastOpenAtomicVisualiser (SFOAV) is intented to enable fast visualisation of atomic and molecular structure files and trajectories.
1515

16-
It is an MIT licensed C++ project hosted here [https://github.com/JerboaBurrow/SimpleFastOpenAtomicVisualiser/](https://github.com/JerboaBurrow/SimpleFastOpenAtomicVisualiser). The visualisations are produced using OpenGL 3.3. There are options for "ray-traced" atoms and bonds or procedural meshes.
16+
It is a GPL licensed C++ project hosted here [https://github.com/JerboaBurrow/SimpleFastOpenAtomicVisualiser/](https://github.com/JerboaBurrow/SimpleFastOpenAtomicVisualiser). The visualisations are produced using OpenGL 3.3. There are options for "ray-traced" atoms and bonds or procedural meshes.
1717

1818
You can find the latest html Doxygen docs at [https://jerboaburrow.github.io/SimpleFastAtomicVisualiser/](https://jerboaburrow.github.io/SimpleFastAtomicVisualiser/).
1919

@@ -83,6 +83,7 @@ Miscellaneous key bindings are:
8383
| X | Toggle drawing the coordinate axes | |
8484
| C | Toggle drawing the simulation cell | |
8585
| I | Toggle information text | |
86+
| V | Start or finish a video recording | |
8687
| ESC | Quit | |
8788

8889
To enable MSAA at 16x
@@ -99,7 +100,7 @@ sfoav struct.xyz -bondCutOff 1.5
99100

100101
## Lua scripting
101102

102-
It is possible to write Lua scripts to manipulate visualisation in SFOAV. By supplying a path as ```--script PATH.lua``` to a Lua file, SFOAV will run the file each frame update. The console exports the following methods in the sfoav library.
103+
It is possible to write Lua scripts to manipulate visualisation in SFOAV. By supplying a path as ```-script PATH.lua``` to a Lua file, SFOAV will run the file each frame update. The console exports the following methods in the sfoav library.
103104

104105
> [!warning]
105106
> Lua indexes from 1, but all sfoav library functions index from 0.
@@ -114,8 +115,11 @@ It is possible to write Lua scripts to manipulate visualisation in SFOAV. By sup
114115
| getAtom | Atom index a | The Atom structure for a |
115116
| atomCount | | The number of atoms |
116117
| getAtomsNeighbours | Atom index x, cutoff distance | The neighbours of a within the cutoff |
117-
| setText | Text string | The neighbours of a within the cutoff |
118+
| setText | Text string | Set the text display |
118119
| getFrame | | The current frame number (from 0) |
120+
| toggleRecord | | Start or stop video recording |
121+
| play | | Play the trajectory |
122+
| pause | | Pause playing the trajectory |
119123

120124
E.g. the following script will set Atom 0 to a random colour every frame.
121125

@@ -143,6 +147,20 @@ for i = 1, #neighbours do
143147
end
144148
```
145149

150+
## Video
151+
152+
On macOS and Windows one release exists using jo_mpeg to write mp4 files.
153+
154+
On Linux two releases exist, the standalone ```sfoav``` which uses jo_mpeg for video writing, and the FFmpeg enabled version ```sfoav-ffmpeg``` which requires additional runtime dependencies (FFmpeg). The FFmpeg video quality is generally superior.
155+
156+
Videos are written out with the filename as the current timestamp.
157+
158+
Video frames are recorded at 60 fps whenever the camera or atoms are updated e.g. a new trajectory frame, new colours, camera moved etc.
159+
160+
Frames are written in the background which will impact visualisation frame rate.
161+
162+
For FFmpeg the ```-codec``` option accepts strings as seen via ```ffmpeg -codecs``` e.g. ```-codec nvenc_h264 -qp 21 -preset lossless``` for Nvidia's H264 encoder. Quality may be controlled by ```-preset```, as well as (depending on the codec) the ```-cp```, ```-crf```, and ```-qp``` arguments where 0 is best and 51 is worst. Other FFmpeg options are ```-bitrate``` and ```-maxBFrames``` and ```-gopSize```.
163+
146164
## Performance
147165

148166
For a system with an intel i7-4790K, Kingston A400 SATA SSD, a GTX 1080 ti, and 16 GB available RAM. SFOAV is capable of rendering at least 5,000,000 static atoms at 60 frames per second with 16x MSAA and with a moveable camera. At this scale moving the atoms will run cause drops to 30 fps, and frame increments will cost ~5 seconds.

0 commit comments

Comments
 (0)