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