PageRenderTime 35ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Codec/Avidemux-EditorPlugin/avidemux-2.4.4/avidemux/ADM_outputs/oplug_ogm/op_ogsave.cpp

https://bitbucket.org/gianni/vaet
C++ | 205 lines | 138 code | 36 blank | 31 comment | 18 complexity | fa03ef8888c3ec8916e697b6a7688471 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, GPL-3.0
  1. //
  2. // C++ Implementation: op_ogsave
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: mean <fixounet@free.fr>, (C) 2004
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. /***************************************************************************
  13. * *
  14. * This program is free software; you can redistribute it and/or modify *
  15. * it under the terms of the GNU General Public License as published by *
  16. * the Free Software Foundation; either version 2 of the License, or *
  17. * (at your option) any later version. *
  18. * *
  19. ***************************************************************************/
  20. #include "config.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <math.h>
  25. #include <time.h>
  26. #include <sys/time.h>
  27. #include <ADM_assert.h>
  28. #include "fourcc.h"
  29. #include "avi_vars.h"
  30. #include "ADM_toolkit/toolkit.hxx"
  31. #include "subchunk.h"
  32. //#include "avilist.h"
  33. #include "ADM_video/ADM_genvideo.hxx"
  34. #include "ADM_filter/video_filters.h"
  35. #include "ADM_encoder/ADM_vidEncode.hxx"
  36. #include "ADM_audio/aviaudio.hxx"
  37. #include "ADM_audiofilter/audioprocess.hxx"
  38. #include "default.h"
  39. #include "oplug_ogm/op_ogsave.h"
  40. //_______________________________________________
  41. uint8_t ogmSave(const char *name)
  42. {
  43. uint8_t ret=0;
  44. ADM_ogmWrite *writter;
  45. if(videoProcessMode())
  46. writter=new ADM_ogmWriteProcess;
  47. else
  48. writter=new ADM_ogmWriteCopy;
  49. ret=writter->save(name);
  50. delete writter;
  51. return ret;
  52. }
  53. //_______________________________________________
  54. ADM_ogmWrite::ADM_ogmWrite(void)
  55. {
  56. _audioBuffer=_videoBuffer=NULL;
  57. videoStream=videoStream=NULL;
  58. encoding_gui=NULL;
  59. audioFilter=NULL;
  60. _fd=NULL;
  61. _togo=0;
  62. _packet=0;
  63. TwoPassLogFile=NULL;
  64. _encode = NULL;
  65. }
  66. //_______________________________________________
  67. ADM_ogmWrite::~ADM_ogmWrite()
  68. {
  69. #define FREE_IF(x) if(x) {delete x;x=NULL;}
  70. #define FREE_IFX(x) if(x) {delete [] x;x=NULL;}
  71. FREE_IFX(_audioBuffer);
  72. FREE_IFX(_videoBuffer);
  73. FREE_IF(videoStream);
  74. FREE_IF(videoStream);
  75. FREE_IF(encoding_gui);
  76. FREE_IF(audioFilter);
  77. if(_fd) fclose(_fd);
  78. _fd=NULL;
  79. if(TwoPassLogFile)
  80. delete [] TwoPassLogFile;
  81. TwoPassLogFile=NULL;
  82. }
  83. //_______________________________________________
  84. uint8_t ADM_ogmWrite::save(const char *name)
  85. {
  86. uint8_t *bufr;
  87. uint32_t len,flags;
  88. uint8_t error=0;
  89. _fd=fopen(name,"wb");
  90. if(!_fd)
  91. {
  92. GUI_Error_HIG(QT_TR_NOOP("File error"), QT_TR_NOOP("Cannot open \"%s\" for writing."), name);
  93. return 0;
  94. }
  95. videoStream=new ogm_page(_fd,1);
  96. encoding_gui=new DIA_encoding(25000);
  97. encoding_gui->setContainer(QT_TR_NOOP("OGM"));
  98. //______________ Write headers..._____________________
  99. if(!initVideo(name))
  100. {
  101. fclose(_fd);
  102. _fd=NULL;
  103. GUI_Error_HIG(QT_TR_NOOP("Could not initialize video"), NULL);
  104. return 0;
  105. }
  106. if(!initAudio())
  107. {
  108. fclose(_fd);
  109. _fd=NULL;
  110. GUI_Error_HIG(QT_TR_NOOP("Could not initialize audio"), NULL);
  111. return 0;
  112. }
  113. encoding_gui->setFps(_fps1000);
  114. encoding_gui->reset();
  115. uint32_t j=0;
  116. int frameDelay = 0;
  117. int videoSize;
  118. for (j = 0; j < _togo; j++)
  119. {
  120. if (!encoding_gui->isAlive())
  121. {
  122. error = 1;
  123. break;
  124. }
  125. for (;;)
  126. {
  127. videoSize = writeVideo(j + frameDelay);
  128. if (videoSize == 0 && _encode && (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH))
  129. {
  130. printf("skipping frame: %u size: %i\n", j + frameDelay, videoSize);
  131. frameDelay++;
  132. }
  133. else
  134. {
  135. error = 1;
  136. break;
  137. }
  138. }
  139. if (!writeAudio(j))
  140. {
  141. error = 1;
  142. break;
  143. }
  144. }
  145. if(abs(j-_togo)<3 && error) error=0; // might be caused by late B frame
  146. delete encoding_gui;
  147. encoding_gui=NULL;
  148. //________________ Flush______________________
  149. videoStream->flush();
  150. endAudio();
  151. //deleteAudioFilters();
  152. // ____________Close____________________
  153. fclose(_fd);
  154. _fd=NULL;
  155. return !error;
  156. }
  157. // Dummy ones
  158. uint8_t ADM_ogmWrite::initVideo(const char *name)
  159. {
  160. ADM_assert(0);
  161. return 0;
  162. }
  163. //___________________________________________________
  164. int ADM_ogmWrite::writeVideo(uint32_t frame)
  165. {
  166. ADM_assert(0);
  167. return 0;
  168. }
  169. // EOF