Guest User

Untitled

a guest
Jun 30th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. cv::VideoWriter being bipolar
  2. #include <opencv/highgui.h>
  3. #include <iostream>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7. if (argc < 3) { return -1; }
  8.  
  9. cv::VideoCapture cap(argv[1]);
  10.  
  11. std::string str = argv[2];
  12.  
  13. int fourcc = CV_FOURCC('j', 'p', 'e', 'g');
  14. double fps = cap.get(CV_CAP_PROP_FPS);
  15. int width = int(cap.get(CV_CAP_PROP_FRAME_WIDTH));
  16. int height = int(cap.get(CV_CAP_PROP_FRAME_HEIGHT));
  17.  
  18. // COMMENT OUT THIS BLOCK TO MAKE THE PROGRAM CRASH
  19. // This code creates a variable on the stack and preforms
  20. // some operations with it. This somehow alligns the memory
  21. // for the call "cv::VideoWriter vw(...)" in a way that
  22. // libavcoded expects and makes the call "vw << img" not crash.
  23. // Note that these variables are never used outside of this block.
  24. char * name_c = new char[100];
  25. strcpy(name_c, str.c_str());
  26. delete[] name_c;
  27. // END COMMENT OUT THIS BLOCK TO MAKE THE PROGRAM CRASH
  28.  
  29. cv::VideoWriter vw(
  30. str,
  31. fourcc,
  32. fps,
  33. cv::Size(width, height));
  34.  
  35. int fnum = 0;
  36. cv::Mat img;
  37. while(cap.grab() && cap.retrieve(img) && fnum < 30)
  38. {
  39. cv::imshow("img", img);
  40. vw << img;
  41. ++fnum;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
  47. cv::VideoWriter vw(
  48. str,
  49. fourcc,
  50. fps,
  51. cv::Size(width, height));
  52. 00401290 fld qword ptr [esp+50h]
  53. 00401294 add esp,4
  54. 00401297 push 1
  55. 00401299 sub esp,8
  56. 0040129C mov eax,esp
  57. 0040129E mov dword ptr [esp+60h],esp
  58. 004012A2 sub esp,8
  59. 004012A5 fstp qword ptr [esp]
  60. 004012A8 mov dword ptr [eax],edi
  61. 004012AA mov dword ptr [eax+4],ebp
  62. 004012AD push 6765706Ah
  63. 004012B2 lea eax,[esp+0A8h]
  64. 004012B9 push eax
  65. 004012BA lea ecx,[esp+5Ch]
  66. 004012BE call cv::VideoWriter::VideoWriter (401454h)
  67.  
  68. ...
  69.  
  70. vw << img;
  71. 00401353 mov edx,dword ptr [esp+40h]
  72. 00401357 mov eax,dword ptr [edx+0Ch]
  73. 0040135A lea ecx,[esp+20h]
  74. 0040135E push ecx
  75. 0040135F lea ecx,[esp+44h]
  76. 00401363 call eax
  77. 00401365 lea ecx,[esp+14h]
  78.  
  79. cv::VideoWriter vw(
  80. str,
  81. fourcc,
  82. fps,
  83. cv::Size(width, height));
  84. 00401253 fld qword ptr [esp+44h]
  85. 00401257 push 1
  86. 00401259 sub esp,8
  87. 0040125C mov ecx,esp
  88. 0040125E mov dword ptr [esp+58h],esp
  89. 00401262 sub esp,8
  90. 00401265 fstp qword ptr [esp]
  91. 00401268 mov dword ptr [ecx+4],eax
  92. 0040126B push 6765706Ah
  93. 00401270 lea eax,[esp+0A0h]
  94. 00401277 mov dword ptr [ecx],edi
  95. 00401279 push eax
  96. 0040127A lea ecx,[esp+54h]
  97. 0040127E call cv::VideoWriter::VideoWriter (401454h)
  98.  
  99. ...
  100.  
  101. vw << img;
  102. 00401313 mov edx,dword ptr [esp+38h]
  103. 00401317 mov eax,dword ptr [edx+0Ch]
  104. 0040131A lea ecx,[esp+18h]
  105. 0040131E push ecx
  106. 0040131F lea ecx,[esp+3Ch]
  107. 00401323 call eax
  108. 00401325 lea ecx,[esp+0Ch]
  109.  
  110. // Working (with extra block) Crashes (without extra block)
  111. 00401290 fld qword ptr [esp+50h] 00401253 fld qword ptr [esp+44h]
  112. *** 00401294 add esp,4
  113. 00401297 push 1 00401257 push 1
  114. ...
  115. 004012A5 fstp qword ptr [esp] 00401265 fstp qword ptr [esp]
  116. *** 004012A8 mov dword ptr [eax],edi 00401268 mov dword ptr [ecx+4],eax
  117. *** 004012AA mov dword ptr [eax+4],ebp 0040126B push 6765706Ah
  118. *** 004012AD push 6765706Ah 00401270 lea eax,[esp+0A0h]
  119. 004012B2 lea eax,[esp+0A8h] 00401277 mov dword ptr [ecx],edi
  120. 004012B9 push eax 00401279 push eax
  121.  
  122. #include <opencv/highgui.h>
  123.  
  124. void save(const std::string & str, cv::VideoCapture & cap)
  125. {
  126. int fourcc = int(cap.get(CV_CAP_PROP_FOURCC));
  127. double fps = cap.get(CV_CAP_PROP_FPS);
  128. int width = int(cap.get(CV_CAP_PROP_FRAME_WIDTH));
  129. int height = int(cap.get(CV_CAP_PROP_FRAME_HEIGHT));
  130.  
  131. cv::VideoWriter vw(
  132. str,
  133. fourcc,
  134. fps,
  135. cv::Size(width, height));
  136.  
  137. int fnum = 0;
  138. cv::Mat img;
  139. while(cap.grab() && cap.retrieve(img) && fnum < 30)
  140. {
  141. cv::imshow("img", img);
  142. cv::waitKey(1);
  143. vw << img;
  144. ++fnum;
  145. }
  146. }
  147.  
  148. int main(int argc, char* argv[])
  149. {
  150. if (argc < 3) { return -1; }
  151.  
  152. cv::VideoCapture cap(argv[1]);
  153.  
  154. std::string str = argv[2];
  155. save(str, cap);
  156. /*
  157. int fourcc = int(cap.get(CV_CAP_PROP_FOURCC));
  158. double fps = cap.get(CV_CAP_PROP_FPS);
  159. int width = int(cap.get(CV_CAP_PROP_FRAME_WIDTH));
  160. int height = int(cap.get(CV_CAP_PROP_FRAME_HEIGHT));
  161.  
  162. cv::VideoWriter vw(
  163. str,
  164. fourcc,
  165. fps,
  166. cv::Size(width, height));
  167.  
  168. int fnum = 0;
  169. cv::Mat img;
  170. while(cap.grab() && cap.retrieve(img) && fnum < 30)
  171. {
  172. cv::imshow("img", img);
  173. cv::waitKey(1);
  174. vw << img;
  175. ++fnum;
  176. }
  177. */
  178. return 0;
  179. }
Advertisement
Add Comment
Please, Sign In to add comment