Filarius

Untitled

May 20th, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include <boost/process.hpp>
  6.  
  7. namespace bp = boost::process;
  8. int main()
  9. {
  10.  
  11.     /*
  12.     ffmpeg - y - f rawvideo - pix_fmt monob - s:v 1280x720 - r 20 - i - -c : v libx264 - preset veryfast - crf 25 1.mp4
  13.        
  14.     ffmpeg - y - i 1.mp4 - f image2pipe - pix_fmt monob - c : v rawvideo -
  15.     */
  16.     int const frame_size = 1280 * 720 ;
  17.  
  18.     BYTE * data = new BYTE[frame_size];
  19.     bp::opstream outgo;
  20.     bp::ipstream ingo;
  21.     /*
  22.     bp::child c("ffmpeg",  bp::std_err > ingo);
  23.  
  24.     std::string text;
  25.     while (std::getline(ingo, text)) {
  26.         std::cout << text << "\n";
  27.     }
  28.  
  29.     c.wait();
  30.     */
  31.     /*
  32.     std::srand(0);
  33.     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");
  34.     for (int j = 0; j < 1000; j++) {
  35.         for (int i = 0; i < frame_size; i++) {
  36.             BYTE r = (std::rand() % 2) * 255;
  37.             data[i] = r;
  38.         }
  39.         if (!child.running()) {
  40.             std::cerr << "Error: ffmpeg not started or abruptly closed" << std::endl;
  41.             break;
  42.         }
  43.         outgo.write((char*)data, frame_size);
  44.        
  45.         std::cout << j << "\n";
  46.     }
  47.     outgo.flush();
  48.     outgo.pipe().close();
  49.     child.wait();
  50.  
  51.     std::cout << "!!!!!!!!!" << "\n";
  52.     */
  53.     std::srand(0);
  54.     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");
  55.     for (int j = 0; j < 1000; j++) {
  56.         long long cnt = 0;
  57.         ingo.read((char *)data, frame_size);
  58.         for (int i = 0; i < frame_size; i++) {
  59.             BYTE r = std::rand() % 2;
  60.             BYTE value = data[i] > 128 ? 1 : 0;
  61.             if (value != r) {
  62.                 cnt += 1;
  63.             }
  64.         }      
  65.  
  66.         std::cout << j << "  " << cnt << " \n";
  67.         Sleep(1);
  68.        
  69.     }
  70.  
  71.     child2.wait();
  72.  
  73.     //std::cout << child2.exit_code() << std::endl;
  74.     std::cout << "Hello, world!" << std::endl;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment