blender-3.0.1-ffmpeg5.patch 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. Patch to extend support ffmpeg>=5.0 in Blender 3.0.1 (for latest slackbuild compatible with Slackware64 current)
  2. Source: https://github.com/blender/blender/commit/af6a1b08e3f0d0070ac9423868d2d3f81057717a
  3. Adapted by Giancarlo Dessi <slack at giand dot it>
  4. --- blender-3.0.1/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
  5. +++ blender-3.0.1-fixed/extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
  6. @@ -177,7 +177,7 @@
  7. // get a decoder and open it
  8. #ifndef FFMPEG_OLD_CODE
  9. - AVCodec* aCodec = avcodec_find_decoder(m_formatCtx->streams[m_stream]->codecpar->codec_id);
  10. + const AVCodec* aCodec = avcodec_find_decoder(m_formatCtx->streams[m_stream]->codecpar->codec_id);
  11. if(!aCodec)
  12. AUD_THROW(FileException, "File couldn't be read, no decoder found with ffmpeg.");
  13. --- blender-3.0.1/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
  14. +++ blender-3.0.1-fixed/extern/audaspace/plugins/ffmpeg/FFMPEGWriter.cpp
  15. @@ -23,6 +23,7 @@
  16. extern "C" {
  17. #include <libavcodec/avcodec.h>
  18. #include <libavformat/avio.h>
  19. +#include <libavutil/channel_layout.h>
  20. }
  21. AUD_NAMESPACE_BEGIN
  22. @@ -171,66 +172,66 @@
  23. if(avformat_alloc_output_context2(&m_formatCtx, nullptr, formats[format], filename.c_str()) < 0)
  24. AUD_THROW(FileException, "File couldn't be written, format couldn't be found with ffmpeg.");
  25. - AVOutputFormat* outputFmt = m_formatCtx->oformat;
  26. + const AVOutputFormat* outputFmt = m_formatCtx->oformat;
  27. if(!outputFmt) {
  28. avformat_free_context(m_formatCtx);
  29. AUD_THROW(FileException, "File couldn't be written, output format couldn't be found with ffmpeg.");
  30. }
  31. - outputFmt->audio_codec = AV_CODEC_ID_NONE;
  32. + AVCodecID audio_codec = AV_CODEC_ID_NONE;
  33. switch(codec)
  34. {
  35. case CODEC_AAC:
  36. - outputFmt->audio_codec = AV_CODEC_ID_AAC;
  37. + audio_codec = AV_CODEC_ID_AAC;
  38. break;
  39. case CODEC_AC3:
  40. - outputFmt->audio_codec = AV_CODEC_ID_AC3;
  41. + audio_codec = AV_CODEC_ID_AC3;
  42. break;
  43. case CODEC_FLAC:
  44. - outputFmt->audio_codec = AV_CODEC_ID_FLAC;
  45. + audio_codec = AV_CODEC_ID_FLAC;
  46. break;
  47. case CODEC_MP2:
  48. - outputFmt->audio_codec = AV_CODEC_ID_MP2;
  49. + audio_codec = AV_CODEC_ID_MP2;
  50. break;
  51. case CODEC_MP3:
  52. - outputFmt->audio_codec = AV_CODEC_ID_MP3;
  53. + audio_codec = AV_CODEC_ID_MP3;
  54. break;
  55. case CODEC_OPUS:
  56. - outputFmt->audio_codec = AV_CODEC_ID_OPUS;
  57. + audio_codec = AV_CODEC_ID_OPUS;
  58. break;
  59. case CODEC_PCM:
  60. switch(specs.format)
  61. {
  62. case FORMAT_U8:
  63. - outputFmt->audio_codec = AV_CODEC_ID_PCM_U8;
  64. + audio_codec = AV_CODEC_ID_PCM_U8;
  65. break;
  66. case FORMAT_S16:
  67. - outputFmt->audio_codec = AV_CODEC_ID_PCM_S16LE;
  68. + audio_codec = AV_CODEC_ID_PCM_S16LE;
  69. break;
  70. case FORMAT_S24:
  71. - outputFmt->audio_codec = AV_CODEC_ID_PCM_S24LE;
  72. + audio_codec = AV_CODEC_ID_PCM_S24LE;
  73. break;
  74. case FORMAT_S32:
  75. - outputFmt->audio_codec = AV_CODEC_ID_PCM_S32LE;
  76. + audio_codec = AV_CODEC_ID_PCM_S32LE;
  77. break;
  78. case FORMAT_FLOAT32:
  79. - outputFmt->audio_codec = AV_CODEC_ID_PCM_F32LE;
  80. + audio_codec = AV_CODEC_ID_PCM_F32LE;
  81. break;
  82. case FORMAT_FLOAT64:
  83. - outputFmt->audio_codec = AV_CODEC_ID_PCM_F64LE;
  84. + audio_codec = AV_CODEC_ID_PCM_F64LE;
  85. break;
  86. default:
  87. - outputFmt->audio_codec = AV_CODEC_ID_NONE;
  88. + audio_codec = AV_CODEC_ID_NONE;
  89. break;
  90. }
  91. break;
  92. case CODEC_VORBIS:
  93. - outputFmt->audio_codec = AV_CODEC_ID_VORBIS;
  94. + audio_codec = AV_CODEC_ID_VORBIS;
  95. break;
  96. default:
  97. - outputFmt->audio_codec = AV_CODEC_ID_NONE;
  98. + audio_codec = AV_CODEC_ID_NONE;
  99. break;
  100. }
  101. @@ -268,10 +269,10 @@
  102. try
  103. {
  104. - if(outputFmt->audio_codec == AV_CODEC_ID_NONE)
  105. + if(audio_codec == AV_CODEC_ID_NONE)
  106. AUD_THROW(FileException, "File couldn't be written, audio codec not found with ffmpeg.");
  107. - AVCodec* codec = avcodec_find_encoder(outputFmt->audio_codec);
  108. + const AVCodec* codec = avcodec_find_encoder(audio_codec);
  109. if(!codec)
  110. AUD_THROW(FileException, "File couldn't be written, audio encoder couldn't be found with ffmpeg.");
  111. --- blender-3.0.1/source/blender/blenkernel/BKE_writeffmpeg.h
  112. +++ blender-3.0.1-fixed/source/blender/blenkernel/BKE_writeffmpeg.h
  113. @@ -85,12 +85,8 @@
  114. void BKE_ffmpeg_preset_set(struct RenderData *rd, int preset);
  115. void BKE_ffmpeg_image_type_verify(struct RenderData *rd, struct ImageFormatData *imf);
  116. -void BKE_ffmpeg_codec_settings_verify(struct RenderData *rd);
  117. bool BKE_ffmpeg_alpha_channel_is_supported(const struct RenderData *rd);
  118. -int BKE_ffmpeg_property_add_string(struct RenderData *rd, const char *type, const char *str);
  119. -void BKE_ffmpeg_property_del(struct RenderData *rd, void *type, void *prop_);
  120. -
  121. void *BKE_ffmpeg_context_create(void);
  122. void BKE_ffmpeg_context_free(void *context_v);
  123. --- blender-3.0.1/source/blender/blenkernel/intern/scene.c
  124. +++ blender-3.0.1-fixed/source/blender/blenkernel/intern/scene.c
  125. @@ -332,12 +332,6 @@
  126. scene_dst->r.avicodecdata->lpParms = MEM_dupallocN(scene_dst->r.avicodecdata->lpParms);
  127. }
  128. - if (scene_src->r.ffcodecdata.properties) {
  129. - /* intentionally check sce_dst not sce_src. */ /* XXX ??? comment outdated... */
  130. - scene_dst->r.ffcodecdata.properties = IDP_CopyProperty_ex(scene_src->r.ffcodecdata.properties,
  131. - flag_subdata);
  132. - }
  133. -
  134. if (scene_src->display.shading.prop) {
  135. scene_dst->display.shading.prop = IDP_CopyProperty(scene_src->display.shading.prop);
  136. }
  137. @@ -408,10 +402,6 @@
  138. MEM_freeN(scene->r.avicodecdata);
  139. scene->r.avicodecdata = NULL;
  140. }
  141. - if (scene->r.ffcodecdata.properties) {
  142. - IDP_FreeProperty(scene->r.ffcodecdata.properties);
  143. - scene->r.ffcodecdata.properties = NULL;
  144. - }
  145. scene_free_markers(scene, do_id_user);
  146. BLI_freelistN(&scene->transform_spaces);
  147. @@ -915,9 +905,6 @@
  148. BLO_write_raw(writer, (size_t)sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
  149. }
  150. }
  151. - if (sce->r.ffcodecdata.properties) {
  152. - IDP_BlendWrite(writer, sce->r.ffcodecdata.properties);
  153. - }
  154. /* writing dynamic list of TimeMarkers to the blend file */
  155. LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) {
  156. @@ -1157,11 +1144,6 @@
  157. BLO_read_data_address(reader, &sce->r.avicodecdata->lpFormat);
  158. BLO_read_data_address(reader, &sce->r.avicodecdata->lpParms);
  159. }
  160. - if (sce->r.ffcodecdata.properties) {
  161. - BLO_read_data_address(reader, &sce->r.ffcodecdata.properties);
  162. - IDP_BlendDataRead(reader, &sce->r.ffcodecdata.properties);
  163. - }
  164. -
  165. BLO_read_list(reader, &(sce->markers));
  166. LISTBASE_FOREACH (TimeMarker *, marker, &sce->markers) {
  167. BLO_read_data_address(reader, &marker->prop);
  168. @@ -1773,10 +1755,6 @@
  169. sce_copy->r.avicodecdata->lpParms = MEM_dupallocN(sce_copy->r.avicodecdata->lpParms);
  170. }
  171. - if (sce->r.ffcodecdata.properties) { /* intentionally check scen not sce. */
  172. - sce_copy->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
  173. - }
  174. -
  175. BKE_sound_reset_scene_runtime(sce_copy);
  176. /* grease pencil */
  177. --- blender-3.0.1/source/blender/blenkernel/intern/writeffmpeg.c
  178. +++ blender-3.0.1-fixed/source/blender/blenkernel/intern/writeffmpeg.c
  179. @@ -56,6 +56,7 @@
  180. * like M_SQRT1_2 leading to warnings with MSVC */
  181. # include <libavcodec/avcodec.h>
  182. # include <libavformat/avformat.h>
  183. +# include <libavutil/channel_layout.h>
  184. # include <libavutil/imgutils.h>
  185. # include <libavutil/opt.h>
  186. # include <libavutil/rational.h>
  187. @@ -113,8 +114,6 @@
  188. printf
  189. static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value);
  190. -static void ffmpeg_dict_set_float(AVDictionary **dict, const char *key, float value);
  191. -static void ffmpeg_set_expert_options(RenderData *rd);
  192. static void ffmpeg_filepath_get(FFMpegContext *context,
  193. char *string,
  194. const struct RenderData *rd,
  195. @@ -425,99 +424,6 @@
  196. return context->current_frame;
  197. }
  198. -static void set_ffmpeg_property_option(IDProperty *prop, AVDictionary **dictionary)
  199. -{
  200. - char name[128];
  201. - char *param;
  202. -
  203. - PRINT("FFMPEG expert option: %s: ", prop->name);
  204. -
  205. - BLI_strncpy(name, prop->name, sizeof(name));
  206. -
  207. - param = strchr(name, ':');
  208. -
  209. - if (param) {
  210. - *param++ = '\0';
  211. - }
  212. -
  213. - switch (prop->type) {
  214. - case IDP_STRING:
  215. - PRINT("%s.\n", IDP_String(prop));
  216. - av_dict_set(dictionary, name, IDP_String(prop), 0);
  217. - break;
  218. - case IDP_FLOAT:
  219. - PRINT("%g.\n", IDP_Float(prop));
  220. - ffmpeg_dict_set_float(dictionary, prop->name, IDP_Float(prop));
  221. - break;
  222. - case IDP_INT:
  223. - PRINT("%d.\n", IDP_Int(prop));
  224. -
  225. - if (param) {
  226. - if (IDP_Int(prop)) {
  227. - av_dict_set(dictionary, name, param, 0);
  228. - }
  229. - else {
  230. - return;
  231. - }
  232. - }
  233. - else {
  234. - ffmpeg_dict_set_int(dictionary, prop->name, IDP_Int(prop));
  235. - }
  236. - break;
  237. - }
  238. -}
  239. -
  240. -static int ffmpeg_proprty_valid(AVCodecContext *c, const char *prop_name, IDProperty *curr)
  241. -{
  242. - int valid = 1;
  243. -
  244. - if (STREQ(prop_name, "video")) {
  245. - if (STREQ(curr->name, "bf")) {
  246. - /* flash codec doesn't support b frames */
  247. - valid &= c->codec_id != AV_CODEC_ID_FLV1;
  248. - }
  249. - }
  250. -
  251. - return valid;
  252. -}
  253. -
  254. -static void set_ffmpeg_properties(RenderData *rd,
  255. - AVCodecContext *c,
  256. - const char *prop_name,
  257. - AVDictionary **dictionary)
  258. -{
  259. - IDProperty *prop;
  260. - IDProperty *curr;
  261. -
  262. - /* TODO(sergey): This is actually rather stupid, because changing
  263. - * codec settings in render panel would also set expert options.
  264. - *
  265. - * But we need ti here in order to get rid of deprecated settings
  266. - * when opening old files in new blender.
  267. - *
  268. - * For as long we don't allow editing properties in the interface
  269. - * it's all good. bug if we allow editing them, we'll need to
  270. - * replace it with some smarter code which would port settings
  271. - * from deprecated to new one.
  272. - */
  273. - ffmpeg_set_expert_options(rd);
  274. -
  275. - if (!rd->ffcodecdata.properties) {
  276. - return;
  277. - }
  278. -
  279. - prop = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, prop_name);
  280. - if (!prop) {
  281. - return;
  282. - }
  283. -
  284. - for (curr = prop->data.group.first; curr; curr = curr->next) {
  285. - if (ffmpeg_proprty_valid(c, prop_name, curr)) {
  286. - set_ffmpeg_property_option(curr, dictionary);
  287. - }
  288. - }
  289. -}
  290. -
  291. static AVRational calc_time_base(uint den, double num, int codec_id)
  292. {
  293. /* Convert the input 'num' to an integer. Simply shift the decimal places until we get an integer
  294. @@ -572,7 +478,7 @@
  295. int error_size)
  296. {
  297. AVStream *st;
  298. - AVCodec *codec;
  299. + const AVCodec *codec;
  300. AVDictionary *opts = NULL;
  301. error[0] = '\0';
  302. @@ -585,21 +491,15 @@
  303. /* Set up the codec context */
  304. - context->video_codec = avcodec_alloc_context3(NULL);
  305. - AVCodecContext *c = context->video_codec;
  306. - c->codec_id = codec_id;
  307. - c->codec_type = AVMEDIA_TYPE_VIDEO;
  308. -
  309. - codec = avcodec_find_encoder(c->codec_id);
  310. + codec = avcodec_find_encoder(codec_id);
  311. if (!codec) {
  312. fprintf(stderr, "Couldn't find valid video codec\n");
  313. - avcodec_free_context(&c);
  314. context->video_codec = NULL;
  315. return NULL;
  316. }
  317. - /* Load codec defaults into 'c'. */
  318. - avcodec_get_context_defaults3(c, codec);
  319. + context->video_codec = avcodec_alloc_context3(codec);
  320. + AVCodecContext *c = context->video_codec;
  321. /* Get some values from the current render settings */
  322. @@ -713,6 +613,13 @@
  323. }
  324. }
  325. + if (codec_id == AV_CODEC_ID_DNXHD) {
  326. + if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT) {
  327. + /* Set the block decision algorithm to be of the highest quality ("rd" == 2). */
  328. + c->mb_decision = 2;
  329. + }
  330. + }
  331. +
  332. if (codec_id == AV_CODEC_ID_FFV1) {
  333. c->pix_fmt = AV_PIX_FMT_RGB32;
  334. }
  335. @@ -751,8 +658,6 @@
  336. 255);
  337. st->avg_frame_rate = av_inv_q(c->time_base);
  338. - set_ffmpeg_properties(rd, c, "video", &opts);
  339. -
  340. if (codec->capabilities & AV_CODEC_CAP_AUTO_THREADS) {
  341. c->thread_count = 0;
  342. }
  343. @@ -815,8 +720,7 @@
  344. int error_size)
  345. {
  346. AVStream *st;
  347. - AVCodec *codec;
  348. - AVDictionary *opts = NULL;
  349. + const AVCodec *codec;
  350. error[0] = '\0';
  351. @@ -826,24 +730,17 @@
  352. }
  353. st->id = 1;
  354. - context->audio_codec = avcodec_alloc_context3(NULL);
  355. - AVCodecContext *c = context->audio_codec;
  356. - c->thread_count = BLI_system_thread_count();
  357. - c->thread_type = FF_THREAD_SLICE;
  358. -
  359. - c->codec_id = codec_id;
  360. - c->codec_type = AVMEDIA_TYPE_AUDIO;
  361. -
  362. - codec = avcodec_find_encoder(c->codec_id);
  363. + codec = avcodec_find_encoder(codec_id);
  364. if (!codec) {
  365. fprintf(stderr, "Couldn't find valid audio codec\n");
  366. - avcodec_free_context(&c);
  367. context->audio_codec = NULL;
  368. return NULL;
  369. }
  370. - /* Load codec defaults into 'c'. */
  371. - avcodec_get_context_defaults3(c, codec);
  372. + context->audio_codec = avcodec_alloc_context3(codec);
  373. + AVCodecContext *c = context->audio_codec;
  374. + c->thread_count = BLI_system_thread_count();
  375. + c->thread_type = FF_THREAD_SLICE;
  376. c->sample_rate = rd->ffcodecdata.audio_mixrate;
  377. c->bit_rate = context->ffmpeg_audio_bitrate * 1000;
  378. @@ -911,19 +808,15 @@
  379. c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
  380. }
  381. - set_ffmpeg_properties(rd, c, "audio", &opts);
  382. -
  383. - int ret = avcodec_open2(c, codec, &opts);
  384. + int ret = avcodec_open2(c, codec, NULL);
  385. if (ret < 0) {
  386. fprintf(stderr, "Couldn't initialize audio codec: %s\n", av_err2str(ret));
  387. BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size);
  388. - av_dict_free(&opts);
  389. avcodec_free_context(&c);
  390. context->audio_codec = NULL;
  391. return NULL;
  392. }
  393. - av_dict_free(&opts);
  394. /* need to prevent floating point exception when using vorbis audio codec,
  395. * initialize this value in the same way as it's done in FFmpeg itself (sergey) */
  396. @@ -969,15 +862,6 @@
  397. av_dict_set(dict, key, buffer, 0);
  398. }
  399. -static void ffmpeg_dict_set_float(AVDictionary **dict, const char *key, float value)
  400. -{
  401. - char buffer[32];
  402. -
  403. - BLI_snprintf(buffer, sizeof(buffer), "%.8f", value);
  404. -
  405. - av_dict_set(dict, key, buffer, 0);
  406. -}
  407. -
  408. static void ffmpeg_add_metadata_callback(void *data,
  409. const char *propname,
  410. char *propvalue,
  411. @@ -996,8 +880,7 @@
  412. {
  413. /* Handle to the output file */
  414. AVFormatContext *of;
  415. - AVOutputFormat *fmt;
  416. - AVDictionary *opts = NULL;
  417. + const AVOutputFormat *fmt;
  418. char name[FILE_MAX], error[1024];
  419. const char **exts;
  420. @@ -1034,11 +917,13 @@
  421. rectx,
  422. recty);
  423. + /* Sanity checks for the output file extensions. */
  424. exts = get_file_extensions(context->ffmpeg_type);
  425. if (!exts) {
  426. BKE_report(reports, RPT_ERROR, "No valid formats found");
  427. return 0;
  428. }
  429. +
  430. fmt = av_guess_format(NULL, exts[0], NULL);
  431. if (!fmt) {
  432. BKE_report(reports, RPT_ERROR, "No valid formats found");
  433. @@ -1047,66 +932,50 @@
  434. of = avformat_alloc_context();
  435. if (!of) {
  436. - BKE_report(reports, RPT_ERROR, "Error opening output file");
  437. + BKE_report(reports, RPT_ERROR, "Can't allocate ffmpeg format context");
  438. return 0;
  439. }
  440. - /* Returns after this must 'goto fail;' */
  441. -
  442. - of->oformat = fmt;
  443. -
  444. - /* Only bother with setting packet size & mux rate when CRF is not used. */
  445. - if (context->ffmpeg_crf == 0) {
  446. - of->packet_size = rd->ffcodecdata.mux_packet_size;
  447. - if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
  448. - ffmpeg_dict_set_int(&opts, "muxrate", rd->ffcodecdata.mux_rate);
  449. - }
  450. - else {
  451. - av_dict_set(&opts, "muxrate", "0", 0);
  452. - }
  453. - }
  454. -
  455. - ffmpeg_dict_set_int(&opts, "preload", (int)(0.5 * AV_TIME_BASE));
  456. -
  457. - of->max_delay = (int)(0.7 * AV_TIME_BASE);
  458. -
  459. - fmt->audio_codec = context->ffmpeg_audio_codec;
  460. + enum AVCodecID audio_codec = context->ffmpeg_audio_codec;
  461. + enum AVCodecID video_codec = context->ffmpeg_codec;
  462. of->url = av_strdup(name);
  463. - /* set the codec to the user's selection */
  464. + /* Check if we need to force change the codec because of file type codec restrictions */
  465. switch (context->ffmpeg_type) {
  466. - case FFMPEG_AVI:
  467. - case FFMPEG_MOV:
  468. - case FFMPEG_MKV:
  469. - fmt->video_codec = context->ffmpeg_codec;
  470. - break;
  471. case FFMPEG_OGG:
  472. - fmt->video_codec = AV_CODEC_ID_THEORA;
  473. + video_codec = AV_CODEC_ID_THEORA;
  474. break;
  475. case FFMPEG_DV:
  476. - fmt->video_codec = AV_CODEC_ID_DVVIDEO;
  477. + video_codec = AV_CODEC_ID_DVVIDEO;
  478. break;
  479. case FFMPEG_MPEG1:
  480. - fmt->video_codec = AV_CODEC_ID_MPEG1VIDEO;
  481. + video_codec = AV_CODEC_ID_MPEG1VIDEO;
  482. break;
  483. case FFMPEG_MPEG2:
  484. - fmt->video_codec = AV_CODEC_ID_MPEG2VIDEO;
  485. + video_codec = AV_CODEC_ID_MPEG2VIDEO;
  486. break;
  487. case FFMPEG_H264:
  488. - fmt->video_codec = AV_CODEC_ID_H264;
  489. + video_codec = AV_CODEC_ID_H264;
  490. break;
  491. case FFMPEG_XVID:
  492. - fmt->video_codec = AV_CODEC_ID_MPEG4;
  493. + video_codec = AV_CODEC_ID_MPEG4;
  494. break;
  495. case FFMPEG_FLV:
  496. - fmt->video_codec = AV_CODEC_ID_FLV1;
  497. + video_codec = AV_CODEC_ID_FLV1;
  498. break;
  499. - case FFMPEG_MPEG4:
  500. default:
  501. - fmt->video_codec = context->ffmpeg_codec;
  502. + /* These containers are not restricted to any specific codec types.
  503. + * Currently we expect these to be .avi, .mov, .mkv, and .mp4.
  504. + */
  505. + video_codec = context->ffmpeg_codec;
  506. break;
  507. }
  508. - if (fmt->video_codec == AV_CODEC_ID_DVVIDEO) {
  509. +
  510. + /* Returns after this must 'goto fail;' */
  511. +
  512. + of->oformat = fmt;
  513. +
  514. + if (video_codec == AV_CODEC_ID_DVVIDEO) {
  515. if (rectx != 720) {
  516. BKE_report(reports, RPT_ERROR, "Render width has to be 720 pixels for DV!");
  517. goto fail;
  518. @@ -1122,17 +991,17 @@
  519. }
  520. if (context->ffmpeg_type == FFMPEG_DV) {
  521. - fmt->audio_codec = AV_CODEC_ID_PCM_S16LE;
  522. + audio_codec = AV_CODEC_ID_PCM_S16LE;
  523. if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE &&
  524. rd->ffcodecdata.audio_mixrate != 48000 && rd->ffcodecdata.audio_channels != 2) {
  525. BKE_report(reports, RPT_ERROR, "FFMPEG only supports 48khz / stereo audio for DV!");
  526. goto fail;
  527. }
  528. }
  529. if (fmt->video_codec != AV_CODEC_ID_NONE) {
  530. context->video_stream = alloc_video_stream(
  531. - context, rd, fmt->video_codec, of, rectx, recty, error, sizeof(error));
  532. + context, rd, video_codec, of, rectx, recty, error, sizeof(error));
  533. PRINT("alloc video stream %p\n", context->video_stream);
  534. if (!context->video_stream) {
  535. if (error[0]) {
  536. @@ -1148,8 +1017,7 @@
  537. }
  538. if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
  539. - context->audio_stream = alloc_audio_stream(
  540. - context, rd, fmt->audio_codec, of, error, sizeof(error));
  541. + context->audio_stream = alloc_audio_stream(context, rd, audio_codec, of, error, sizeof(error));
  542. if (!context->audio_stream) {
  543. if (error[0]) {
  544. BKE_report(reports, RPT_ERROR, error);
  545. @@ -1186,7 +1054,6 @@
  546. context->outfile = of;
  547. av_dump_format(of, 0, name, 1);
  548. - av_dict_free(&opts);
  549. return 1;
  550. @@ -1203,7 +1070,6 @@
  551. context->audio_stream = NULL;
  552. }
  553. - av_dict_free(&opts);
  554. avformat_free_context(of);
  555. return 0;
  556. }
  557. @@ -1533,198 +1399,17 @@
  558. end_ffmpeg_impl(context, false);
  559. }
  560. -/* properties */
  561. -
  562. -void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_)
  563. -{
  564. - struct IDProperty *prop = (struct IDProperty *)prop_;
  565. - IDProperty *group;
  566. -
  567. - if (!rd->ffcodecdata.properties) {
  568. - return;
  569. - }
  570. -
  571. - group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type);
  572. - if (group && prop) {
  573. - IDP_FreeFromGroup(group, prop);
  574. - }
  575. -}
  576. -
  577. -static IDProperty *BKE_ffmpeg_property_add(RenderData *rd,
  578. - const char *type,
  579. - const AVOption *o,
  580. - const AVOption *parent)
  581. -{
  582. - AVCodecContext c;
  583. - IDProperty *group;
  584. - IDProperty *prop;
  585. - IDPropertyTemplate val;
  586. - int idp_type;
  587. - char name[256];
  588. -
  589. - val.i = 0;
  590. -
  591. - avcodec_get_context_defaults3(&c, NULL);
  592. -
  593. - if (!rd->ffcodecdata.properties) {
  594. - rd->ffcodecdata.properties = IDP_New(IDP_GROUP, &val, "ffmpeg");
  595. - }
  596. -
  597. - group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type);
  598. -
  599. - if (!group) {
  600. - group = IDP_New(IDP_GROUP, &val, type);
  601. - IDP_AddToGroup(rd->ffcodecdata.properties, group);
  602. - }
  603. -
  604. - if (parent) {
  605. - BLI_snprintf(name, sizeof(name), "%s:%s", parent->name, o->name);
  606. - }
  607. - else {
  608. - BLI_strncpy(name, o->name, sizeof(name));
  609. - }
  610. -
  611. - PRINT("ffmpeg_property_add: %s %s\n", type, name);
  612. -
  613. - prop = IDP_GetPropertyFromGroup(group, name);
  614. - if (prop) {
  615. - return prop;
  616. - }
  617. -
  618. - switch (o->type) {
  619. - case AV_OPT_TYPE_INT:
  620. - case AV_OPT_TYPE_INT64:
  621. - val.i = o->default_val.i64;
  622. - idp_type = IDP_INT;
  623. - break;
  624. - case AV_OPT_TYPE_DOUBLE:
  625. - case AV_OPT_TYPE_FLOAT:
  626. - val.f = o->default_val.dbl;
  627. - idp_type = IDP_FLOAT;
  628. - break;
  629. - case AV_OPT_TYPE_STRING:
  630. - val.string.str =
  631. - (char
  632. - *)" ";
  633. - val.string.len = 80;
  634. - idp_type = IDP_STRING;
  635. - break;
  636. - case AV_OPT_TYPE_CONST:
  637. - val.i = 1;
  638. - idp_type = IDP_INT;
  639. - break;
  640. - default:
  641. - return NULL;
  642. - }
  643. - prop = IDP_New(idp_type, &val, name);
  644. - IDP_AddToGroup(group, prop);
  645. - return prop;
  646. -}
  647. -
  648. -/* not all versions of ffmpeg include that, so here we go ... */
  649. -
  650. -int BKE_ffmpeg_property_add_string(RenderData *rd, const char *type, const char *str)
  651. -{
  652. - AVCodecContext c;
  653. - const AVOption *o = NULL;
  654. - const AVOption *p = NULL;
  655. - char name_[128];
  656. - char *name;
  657. - char *param;
  658. - IDProperty *prop = NULL;
  659. -
  660. - avcodec_get_context_defaults3(&c, NULL);
  661. -
  662. - BLI_strncpy(name_, str, sizeof(name_));
  663. -
  664. - name = name_;
  665. - while (*name == ' ') {
  666. - name++;
  667. - }
  668. -
  669. - param = strchr(name, ':');
  670. -
  671. - if (!param) {
  672. - param = strchr(name, ' ');
  673. - }
  674. - if (param) {
  675. - *param++ = '\0';
  676. - while (*param == ' ') {
  677. - param++;
  678. - }
  679. - }
  680. -
  681. - o = av_opt_find(&c, name, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
  682. - if (!o) {
  683. - PRINT("Ignoring unknown expert option %s\n", str);
  684. - return 0;
  685. - }
  686. - if (param && o->type == AV_OPT_TYPE_CONST) {
  687. - return 0;
  688. - }
  689. - if (param && o->type != AV_OPT_TYPE_CONST && o->unit) {
  690. - p = av_opt_find(&c, param, o->unit, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
  691. - if (p) {
  692. - prop = BKE_ffmpeg_property_add(rd, (char *)type, p, o);
  693. - }
  694. - else {
  695. - PRINT("Ignoring unknown expert option %s\n", str);
  696. - }
  697. - }
  698. - else {
  699. - prop = BKE_ffmpeg_property_add(rd, (char *)type, o, NULL);
  700. - }
  701. -
  702. - if (!prop) {
  703. - return 0;
  704. - }
  705. -
  706. - if (param && !p) {
  707. - switch (prop->type) {
  708. - case IDP_INT:
  709. - IDP_Int(prop) = atoi(param);
  710. - break;
  711. - case IDP_FLOAT:
  712. - IDP_Float(prop) = atof(param);
  713. - break;
  714. - case IDP_STRING:
  715. - strncpy(IDP_String(prop), param, prop->len);
  716. - break;
  717. - }
  718. - }
  719. - return 1;
  720. -}
  721. -
  722. -static void ffmpeg_set_expert_options(RenderData *rd)
  723. -{
  724. - int codec_id = rd->ffcodecdata.codec;
  725. -
  726. - if (rd->ffcodecdata.properties) {
  727. - IDP_FreePropertyContent(rd->ffcodecdata.properties);
  728. - }
  729. -
  730. - if (codec_id == AV_CODEC_ID_DNXHD) {
  731. - if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT) {
  732. - BKE_ffmpeg_property_add_string(rd, "video", "mbd:rd");
  733. - }
  734. - }
  735. -}
  736. -
  737. void BKE_ffmpeg_preset_set(RenderData *rd, int preset)
  738. {
  739. - int isntsc = (rd->frs_sec != 25);
  740. -
  741. - if (rd->ffcodecdata.properties) {
  742. - IDP_FreePropertyContent(rd->ffcodecdata.properties);
  743. - }
  744. + bool is_ntsc = (rd->frs_sec != 25);
  745. switch (preset) {
  746. case FFMPEG_PRESET_VCD:
  747. rd->ffcodecdata.type = FFMPEG_MPEG1;
  748. rd->ffcodecdata.video_bitrate = 1150;
  749. rd->xsch = 352;
  750. - rd->ysch = isntsc ? 240 : 288;
  751. - rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
  752. + rd->ysch = is_ntsc ? 240 : 288;
  753. + rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
  754. rd->ffcodecdata.rc_max_rate = 1150;
  755. rd->ffcodecdata.rc_min_rate = 1150;
  756. rd->ffcodecdata.rc_buffer_size = 40 * 8;
  757. @@ -1736,8 +1421,8 @@
  758. rd->ffcodecdata.type = FFMPEG_MPEG2;
  759. rd->ffcodecdata.video_bitrate = 2040;
  760. rd->xsch = 480;
  761. - rd->ysch = isntsc ? 480 : 576;
  762. - rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
  763. + rd->ysch = is_ntsc ? 480 : 576;
  764. + rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
  765. rd->ffcodecdata.rc_max_rate = 2516;
  766. rd->ffcodecdata.rc_min_rate = 0;
  767. rd->ffcodecdata.rc_buffer_size = 224 * 8;
  768. @@ -1754,7 +1439,7 @@
  769. rd->ysch = isntsc ? 480 : 576;
  770. # endif
  771. - rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
  772. + rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
  773. rd->ffcodecdata.rc_max_rate = 9000;
  774. rd->ffcodecdata.rc_min_rate = 0;
  775. rd->ffcodecdata.rc_buffer_size = 224 * 8;
  776. @@ -1765,14 +1450,14 @@
  777. case FFMPEG_PRESET_DV:
  778. rd->ffcodecdata.type = FFMPEG_DV;
  779. rd->xsch = 720;
  780. - rd->ysch = isntsc ? 480 : 576;
  781. + rd->ysch = is_ntsc ? 480 : 576;
  782. break;
  783. case FFMPEG_PRESET_H264:
  784. rd->ffcodecdata.type = FFMPEG_AVI;
  785. rd->ffcodecdata.codec = AV_CODEC_ID_H264;
  786. rd->ffcodecdata.video_bitrate = 6000;
  787. - rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
  788. + rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
  789. rd->ffcodecdata.rc_max_rate = 9000;
  790. rd->ffcodecdata.rc_min_rate = 0;
  791. rd->ffcodecdata.rc_buffer_size = 224 * 8;
  792. @@ -1793,16 +1478,14 @@
  793. }
  794. rd->ffcodecdata.video_bitrate = 6000;
  795. - rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
  796. + rd->ffcodecdata.gop_size = is_ntsc ? 18 : 15;
  797. rd->ffcodecdata.rc_max_rate = 9000;
  798. rd->ffcodecdata.rc_min_rate = 0;
  799. rd->ffcodecdata.rc_buffer_size = 224 * 8;
  800. rd->ffcodecdata.mux_packet_size = 2048;
  801. rd->ffcodecdata.mux_rate = 10080000;
  802. break;
  803. }
  804. -
  805. - ffmpeg_set_expert_options(rd);
  806. }
  807. void BKE_ffmpeg_image_type_verify(RenderData *rd, ImageFormatData *imf)
  808. @@ -1848,11 +1531,6 @@
  809. }
  810. }
  811. -void BKE_ffmpeg_codec_settings_verify(RenderData *rd)
  812. -{
  813. - ffmpeg_set_expert_options(rd);
  814. -}
  815. -
  816. bool BKE_ffmpeg_alpha_channel_is_supported(const RenderData *rd)
  817. {
  818. int codec = rd->ffcodecdata.codec;
  819. --- blender-3.0.1/source/blender/imbuf/intern/IMB_anim.h
  820. +++ blender-3.0.1-fixed/source/blender/imbuf/intern/IMB_anim.h
  821. @@ -124,7 +124,7 @@
  822. #ifdef WITH_FFMPEG
  823. AVFormatContext *pFormatCtx;
  824. AVCodecContext *pCodecCtx;
  825. - AVCodec *pCodec;
  826. + const AVCodec *pCodec;
  827. AVFrame *pFrame;
  828. int pFrameComplete;
  829. AVFrame *pFrameRGB;
  830. --- blender-3.0.1/source/blender/imbuf/intern/anim_movie.c
  831. +++ blender-3.0.1-fixed/source/blender/imbuf/anim_movie.c
  832. @@ -511,7 +511,7 @@
  833. {
  834. int i, video_stream_index;
  835. - AVCodec *pCodec;
  836. + const AVCodec *pCodec;
  837. AVFormatContext *pFormatCtx = NULL;
  838. AVCodecContext *pCodecCtx;
  839. AVRational frame_rate;
  840. --- blender-3.0.1/source/blender/imbuf/intern/indexer.c
  841. +++ blender-3.0.1-fixed/source/blender/imbuf/intern/indexer.c
  842. @@ -490,7 +490,7 @@
  843. AVFormatContext *of;
  844. AVStream *st;
  845. AVCodecContext *c;
  846. - AVCodec *codec;
  847. + const AVCodec *codec;
  848. struct SwsContext *sws_ctx;
  849. AVFrame *frame;
  850. int cfra;
  851. @@ -522,12 +522,9 @@
  852. rv->st = avformat_new_stream(rv->of, NULL);
  853. rv->st->id = 0;
  854. - rv->c = avcodec_alloc_context3(NULL);
  855. - rv->c->codec_type = AVMEDIA_TYPE_VIDEO;
  856. - rv->c->codec_id = AV_CODEC_ID_H264;
  857. + rv->codec = avcodec_find_encoder(AV_CODEC_ID_H264);
  858. - rv->of->oformat->video_codec = rv->c->codec_id;
  859. - rv->codec = avcodec_find_encoder(rv->c->codec_id);
  860. + rv->c = avcodec_alloc_context3(rv->codec);
  861. if (!rv->codec) {
  862. fprintf(stderr,
  863. @@ -539,8 +536,6 @@
  864. return NULL;
  865. }
  866. - avcodec_get_context_defaults3(rv->c, rv->codec);
  867. -
  868. rv->c->width = width;
  869. rv->c->height = height;
  870. rv->c->gop_size = 10;
  871. @@ -791,7 +786,7 @@
  872. AVFormatContext *iFormatCtx;
  873. AVCodecContext *iCodecCtx;
  874. - AVCodec *iCodec;
  875. + const AVCodec *iCodec;
  876. AVStream *iStream;
  877. int videoStream;
  878. --- blender-3.0.1/source/blender/imbuf/intern/util.c
  879. +++ blender-3.0.1-fixed/source/blender/imbuf/util.c
  880. @@ -267,7 +267,7 @@
  881. AVFormatContext *pFormatCtx = NULL;
  882. unsigned int i;
  883. int videoStream;
  884. - AVCodec *pCodec;
  885. + const AVCodec *pCodec;
  886. if (BLI_path_extension_check_n(filepath,
  887. ".swf",
  888. --- blender-3.0.1/source/blender/makesdna/DNA_scene_types.h
  889. +++ blender-3.0.1-fixed/source/blender/makesdna/DNA_scene_types.h
  890. @@ -157,7 +157,6 @@
  891. int audio_bitrate;
  892. int audio_mixrate;
  893. int audio_channels;
  894. - char _pad0[4];
  895. float audio_volume;
  896. int gop_size;
  897. /** Only used if FFMPEG_USE_MAX_B_FRAMES flag is set. */
  898. @@ -172,9 +171,7 @@
  899. int rc_buffer_size;
  900. int mux_packet_size;
  901. int mux_rate;
  902. - char _pad1[4];
  903. -
  904. - IDProperty *properties;
  905. + void *_pad1;
  906. } FFMpegCodecData;
  907. /* ************************************************************* */
  908. --- blender-3.0.1/source/blender/makesrna/intern/rna_scene.c
  909. +++ blender-3.0.1-fixed/source/blender/makesrna/intern/rna_scene.c
  910. @@ -1469,18 +1469,6 @@
  911. else {
  912. rd->ffcodecdata.flags &= ~FFMPEG_LOSSLESS_OUTPUT;
  913. }
  914. -
  915. - BKE_ffmpeg_codec_settings_verify(rd);
  916. -}
  917. -
  918. -static void rna_FFmpegSettings_codec_settings_update(Main *UNUSED(bmain),
  919. - Scene *UNUSED(scene_unused),
  920. - PointerRNA *ptr)
  921. -{
  922. - Scene *scene = (Scene *)ptr->owner_id;
  923. - RenderData *rd = &scene->r;
  924. -
  925. - BKE_ffmpeg_codec_settings_verify(rd);
  926. }
  927. # endif
  928. @@ -5682,17 +5670,13 @@
  929. RNA_def_property_enum_items(prop, ffmpeg_format_items);
  930. RNA_def_property_enum_default(prop, FFMPEG_MKV);
  931. RNA_def_property_ui_text(prop, "Container", "Output file container");
  932. - RNA_def_property_update(
  933. - prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_FFmpegSettings_codec_settings_update");
  934. prop = RNA_def_property(srna, "codec", PROP_ENUM, PROP_NONE);
  935. RNA_def_property_enum_bitflag_sdna(prop, NULL, "codec");
  936. RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
  937. RNA_def_property_enum_items(prop, ffmpeg_codec_items);
  938. RNA_def_property_enum_default(prop, AV_CODEC_ID_H264);
  939. RNA_def_property_ui_text(prop, "Video Codec", "FFmpeg codec to use for video output");
  940. - RNA_def_property_update(
  941. - prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_FFmpegSettings_codec_settings_update");
  942. prop = RNA_def_property(srna, "video_bitrate", PROP_INT, PROP_NONE);
  943. RNA_def_property_int_sdna(prop, NULL, "video_bitrate");