georgmartius / vid.stab

Video stabilization library
http://public.hronopik.de/vid.stab/
Other
838 stars 110 forks source link

Improve serialization performance by creating a simple binary format for transform files. #97

Closed gabilan closed 3 years ago

gabilan commented 3 years ago

Improve serialization performance by creating a simple binary format for transform files. Binary serialization results in faster load/store times and files that are 40%+ smaller in size. Use of this binary serialization is controlled by using the argument "fileformat".

Also change Field and Vec to represent coordinate and size fields as 16-bit integers. This reduces the runtime memory usage of these data structures by ~50%.

georgmartius commented 3 years ago

Wonderful! This is really a welcome feature. However, I would prefer if both formats are supported at runtime, in particular, to be able to load old files. Do you think that would be too complicated? Maybe just the way you have it now, but the load module would be able to check if it is the ascii version? Also, we should make this the default and make a minor version bump.

mviereck commented 3 years ago

Does this also affect global_motions.trf that is created with option debug? I ask because I am parsing global_motions.trf to apply the changes myself with imagemagick. (I would prefer no change in global_motions.trf).

georgmartius commented 3 years ago

Does this also affect global_motions.trf that is created with option debug? Would be good to keep this untouched, you are right.

gabilan commented 3 years ago

Does this also affect global_motions.trf that is created with option debug? I ask because I am parsing global_motions.trf to apply the changes myself with imagemagick. (I would prefer no change in global_motions.trf).

As far as I can tell, global_motions.trf is not impacted by my change. It's populated in vsLocalmotions2Transforms/vsMotionsToTransform and doesn't appear to use any of the serialization methods.

gabilan commented 3 years ago

Wonderful! This is really a welcome feature. However, I would prefer if both formats are supported at runtime, in particular, to be able to load old files. Do you think that would be too complicated? Maybe just the way you have it now, but the load module would be able to check if it is the ascii version? Also, we should make this the default and make a minor version bump.

I've implemented your feedback.

georgmartius commented 3 years ago

Dear Ernest, looks good. Quite a bit of boilerplate code though. Is there no standard lib for all this big-endian to little endian conversion and binary serialization?

gabilan commented 3 years ago

There are a few that come to mind -- FlatBuffers, ProtoBuf, and Cereal. Cereal is probably the easiest to integrate because it's just a header. The other immediate alternatives require defining a schema and then generating code. I don't mind implementing Cereal if you are OK with mixing C and C++11. I avoided adding dependencies in order to keep this PR simple. I'd look to you for a strong suggestion in this area as this is your project.

georgmartius commented 3 years ago

You are right, let's keep it simple and do not create more dependencies than necessary.

georgmartius commented 3 years ago

Apparently, it causes problems on windows, see issue 104 https://github.com/georgmartius/vid.stab/issues/104 Do you have access to a windows machine to give it a try?

sufehmi commented 8 months ago

Apparently, it causes problems on windows, see issue 104 #104 Do you have access to a windows machine to give it a try?

Please change the default to the ASCII transform files - ffmpeg v6.0.1 on Mac M2 can't stabilize video as well because of this.

Second pass always output error "Cannot parse localmotion"

ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers built with Apple clang version 14.0.3 (clang-1403.0.22.14.1) configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon