fork download
  1. #include <iostream>
  2.  
  3. // ダミーのクラス群
  4. class Mat{
  5. public:
  6. int m_frame;
  7. Mat(int frame=-1):m_frame(frame){}
  8. };
  9. class VideoCapture{
  10. public:
  11. int m_frame;
  12. VideoCapture():m_frame(0){}
  13. VideoCapture& operator>>( Mat &m){ m = m_frame++; return *this;}
  14. };
  15. class VideoWriter{
  16. public:
  17. int m_frame;
  18. VideoWriter():m_frame(0){}
  19. VideoWriter & operator<<(const Mat &m){
  20. std::cout << "dst[" << m_frame << "],src[" << m.m_frame << "]" << std::endl;
  21. m_frame++;
  22. return *this;
  23. }
  24. };
  25.  
  26. // ratio倍速のフレーム画像を取得
  27. Mat getImage( VideoCapture &src, int ratio)
  28. {
  29. // 倍速=間引いて取得する
  30. Mat frame(-1);
  31. for( int i = 0; i < ratio; i++){
  32. src >> frame;
  33. }
  34. return frame;
  35. }
  36.  
  37. int main() {
  38. VideoCapture video;
  39. VideoWriter writer;
  40. Mat frame = getImage( video, 1);
  41. for( int i = 0; i < 60; i++){
  42. // 10frameごとに0,1,2...倍速の画像を書き込む
  43. int ratio = i / 10;
  44. if( i % 10 == 0){
  45. std::cout << "ratio=" << ratio << std::endl;
  46. }
  47. if( ratio > 0){ // 0倍速=取得不要
  48. frame = getImage( video, ratio);
  49. }
  50. writer << frame;
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
ratio=0
dst[0],src[0]
dst[1],src[0]
dst[2],src[0]
dst[3],src[0]
dst[4],src[0]
dst[5],src[0]
dst[6],src[0]
dst[7],src[0]
dst[8],src[0]
dst[9],src[0]
ratio=1
dst[10],src[1]
dst[11],src[2]
dst[12],src[3]
dst[13],src[4]
dst[14],src[5]
dst[15],src[6]
dst[16],src[7]
dst[17],src[8]
dst[18],src[9]
dst[19],src[10]
ratio=2
dst[20],src[12]
dst[21],src[14]
dst[22],src[16]
dst[23],src[18]
dst[24],src[20]
dst[25],src[22]
dst[26],src[24]
dst[27],src[26]
dst[28],src[28]
dst[29],src[30]
ratio=3
dst[30],src[33]
dst[31],src[36]
dst[32],src[39]
dst[33],src[42]
dst[34],src[45]
dst[35],src[48]
dst[36],src[51]
dst[37],src[54]
dst[38],src[57]
dst[39],src[60]
ratio=4
dst[40],src[64]
dst[41],src[68]
dst[42],src[72]
dst[43],src[76]
dst[44],src[80]
dst[45],src[84]
dst[46],src[88]
dst[47],src[92]
dst[48],src[96]
dst[49],src[100]
ratio=5
dst[50],src[105]
dst[51],src[110]
dst[52],src[115]
dst[53],src[120]
dst[54],src[125]
dst[55],src[130]
dst[56],src[135]
dst[57],src[140]
dst[58],src[145]
dst[59],src[150]