Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <boost/process.hpp>
- namespace bp = boost::process;
- int main()
- {
- /*
- ffmpeg - y - f rawvideo - pix_fmt monob - s:v 1280x720 - r 20 - i - -c : v libx264 - preset veryfast - crf 25 1.mp4
- ffmpeg - y - i 1.mp4 - f image2pipe - pix_fmt monob - c : v rawvideo -
- */
- int const frame_size = 1280 * 720 ;
- BYTE * data = new BYTE[frame_size];
- bp::opstream outgo;
- bp::ipstream ingo;
- /*
- bp::child c("ffmpeg", bp::std_err > ingo);
- std::string text;
- while (std::getline(ingo, text)) {
- std::cout << text << "\n";
- }
- c.wait();
- */
- /*
- std::srand(0);
- bp::child child("ffmpeg -y -f rawvideo -pix_fmt gray -s:v 1280x720 -r 20 -i - -c:v libx264 -preset veryfast -crf 20 1.mp4", bp::std_in < outgo, bp::std_out > "ffmpeg_out.log", bp::std_err > "ffmpeg_err.log");
- for (int j = 0; j < 1000; j++) {
- for (int i = 0; i < frame_size; i++) {
- BYTE r = (std::rand() % 2) * 255;
- data[i] = r;
- }
- if (!child.running()) {
- std::cerr << "Error: ffmpeg not started or abruptly closed" << std::endl;
- break;
- }
- outgo.write((char*)data, frame_size);
- std::cout << j << "\n";
- }
- outgo.flush();
- outgo.pipe().close();
- child.wait();
- std::cout << "!!!!!!!!!" << "\n";
- */
- std::srand(0);
- bp::child child2("ffmpeg -y -i 1.mp4 -f image2pipe -pix_fmt gray -c:v rawvideo -",bp::std_out > ingo, bp::std_err > "ffmpeg_err2.log");
- for (int j = 0; j < 1000; j++) {
- long long cnt = 0;
- ingo.read((char *)data, frame_size);
- for (int i = 0; i < frame_size; i++) {
- BYTE r = std::rand() % 2;
- BYTE value = data[i] > 128 ? 1 : 0;
- if (value != r) {
- cnt += 1;
- }
- }
- std::cout << j << " " << cnt << " \n";
- Sleep(1);
- }
- child2.wait();
- //std::cout << child2.exit_code() << std::endl;
- std::cout << "Hello, world!" << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment