macflim icon indicating copy to clipboard operation
macflim copied to clipboard

Support creation of longer flims

Open fstark opened this issue 3 years ago • 1 comments

Creating flims longer than 10 minutes is impractical, due to the memory consumption of flimmaker.

fstark avatar Sep 11 '21 17:09 fstark

From this reddit comment: https://www.reddit.com/r/cpp/comments/s980ik/a_highlevel_coroutine_explanation/htsa1m4/

Here is an example of how to implement coroutines for video/audio: https://godbolt.org/z/Y7aEP9aoo

Using the generator from: https://github.com/lewissbaker/cppcoro

Copy of the code:

#include <cppcoro/generator.hpp>
#include <iostream>
#include <random>
#include <tuple>
#include <vector>

using video_frame = int;
using audio_frame = double;
using data_packet = std::tuple<std::vector<video_frame>, audio_frame>;

cppcoro::generator<data_packet> decoder() {
    std::random_device r;
    std::default_random_engine engine{r()};
    std::uniform_int_distribution<video_frame> uniform_dist(-100, 100);

    std::vector<video_frame> buffer{};

    for (std::size_t iter{1}; iter < 100; ++iter) {
        if (iter % 10 != 0) {
            buffer.push_back(uniform_dist(engine));
        } else {
            co_yield data_packet{buffer, 10.6 * iter};
            buffer.clear();
        }
    }
}

int main() {
    for (auto const& [video_buffer, audio_buffer] : decoder()) {
        std::cout << "Audio " << audio_buffer << "\nVideo ";

        for (auto frame : video_buffer) {
            std::cout << frame << ",";
        }

        std::cout << "\n";
    }
    return 0;
}

fstark avatar Jan 23 '22 11:01 fstark