@@ -200,6 +200,41 @@ static bool create_video_stream(struct ffmpeg_data *data)
200
200
data -> config .video_encoder ))
201
201
return false;
202
202
203
+ closest_format = data -> config .format ;
204
+ if (data -> vcodec -> pix_fmts ) {
205
+ const int has_alpha = closest_format == AV_PIX_FMT_BGRA ;
206
+ closest_format = avcodec_find_best_pix_fmt_of_list (
207
+ data -> vcodec -> pix_fmts , closest_format , has_alpha ,
208
+ NULL );
209
+ }
210
+
211
+ context = avcodec_alloc_context3 (data -> vcodec );
212
+ context -> bit_rate = (int64_t )data -> config .video_bitrate * 1000 ;
213
+ context -> width = data -> config .scale_width ;
214
+ context -> height = data -> config .scale_height ;
215
+ context -> time_base = (AVRational ){ovi .fps_den , ovi .fps_num };
216
+ context -> framerate = (AVRational ){ovi .fps_num , ovi .fps_den };
217
+ context -> gop_size = data -> config .gop_size ;
218
+ context -> pix_fmt = closest_format ;
219
+ context -> color_range = data -> config .color_range ;
220
+ context -> color_primaries = data -> config .color_primaries ;
221
+ context -> color_trc = data -> config .color_trc ;
222
+ context -> colorspace = data -> config .colorspace ;
223
+ context -> chroma_sample_location = determine_chroma_location (
224
+ closest_format , data -> config .colorspace );
225
+ context -> thread_count = 0 ;
226
+
227
+ data -> video -> time_base = context -> time_base ;
228
+ data -> video -> avg_frame_rate = (AVRational ){ovi .fps_num , ovi .fps_den };
229
+
230
+ if (data -> output -> oformat -> flags & AVFMT_GLOBALHEADER )
231
+ context -> flags |= AV_CODEC_FLAG_GLOBAL_HEADER ;
232
+
233
+ data -> video_ctx = context ;
234
+
235
+ if (!open_video_codec (data ))
236
+ return false;
237
+
203
238
const enum AVColorTransferCharacteristic trc = data -> config .color_trc ;
204
239
const bool pq = trc == AVCOL_TRC_SMPTE2084 ;
205
240
const bool hlg = trc == AVCOL_TRC_ARIB_STD_B67 ;
@@ -253,41 +288,6 @@ static bool create_video_stream(struct ffmpeg_data *data)
253
288
#endif
254
289
}
255
290
256
- closest_format = data -> config .format ;
257
- if (data -> vcodec -> pix_fmts ) {
258
- const int has_alpha = closest_format == AV_PIX_FMT_BGRA ;
259
- closest_format = avcodec_find_best_pix_fmt_of_list (
260
- data -> vcodec -> pix_fmts , closest_format , has_alpha ,
261
- NULL );
262
- }
263
-
264
- context = avcodec_alloc_context3 (data -> vcodec );
265
- context -> bit_rate = (int64_t )data -> config .video_bitrate * 1000 ;
266
- context -> width = data -> config .scale_width ;
267
- context -> height = data -> config .scale_height ;
268
- context -> time_base = (AVRational ){ovi .fps_den , ovi .fps_num };
269
- context -> framerate = (AVRational ){ovi .fps_num , ovi .fps_den };
270
- context -> gop_size = data -> config .gop_size ;
271
- context -> pix_fmt = closest_format ;
272
- context -> color_range = data -> config .color_range ;
273
- context -> color_primaries = data -> config .color_primaries ;
274
- context -> color_trc = data -> config .color_trc ;
275
- context -> colorspace = data -> config .colorspace ;
276
- context -> chroma_sample_location = determine_chroma_location (
277
- closest_format , data -> config .colorspace );
278
- context -> thread_count = 0 ;
279
-
280
- data -> video -> time_base = context -> time_base ;
281
- data -> video -> avg_frame_rate = (AVRational ){ovi .fps_num , ovi .fps_den };
282
-
283
- if (data -> output -> oformat -> flags & AVFMT_GLOBALHEADER )
284
- context -> flags |= AV_CODEC_FLAG_GLOBAL_HEADER ;
285
-
286
- data -> video_ctx = context ;
287
-
288
- if (!open_video_codec (data ))
289
- return false;
290
-
291
291
if (context -> pix_fmt != data -> config .format ||
292
292
data -> config .width != data -> config .scale_width ||
293
293
data -> config .height != data -> config .scale_height ) {
0 commit comments