@@ -204,16 +204,15 @@ def to_x265_params(self) -> str:
204
204
return ""
205
205
206
206
# matrix-coefficients=<arg> Matrix coefficients (CICP) of input content:
207
- # identity, bt709, unspecified, fcc73, bt470bg, bt601, smpte240, ycgco, bt2020ncl, bt2020cl, smpte2085, chromncl, chromcl, ictcp
207
+ # identity, bt709, unspecified, fcc73, bt470bg, bt601, smpte240,
208
+ # ycgco, bt2020ncl, bt2020cl, smpte2085, chromncl, chromcl, ictcp
208
209
def to_libaom_av1_params (self ) -> str :
209
210
res = f"color-primaries={ self .color_primaries } :transfer-characteristics={ self .color_transfer } "
210
211
mc = libaom_get_matrix_coefficients (self .color_space )
211
212
if mc is not None :
212
213
res += f":matrix-coefficients={ mc } "
213
214
return res
214
215
215
-
216
-
217
216
# From Fastfix
218
217
# if (fastflix.current_video.color_space and "bt2020" in fastflix.current_video.color_space):
219
218
# svtav1_params.append(f"matrix-coefficients=9")
@@ -225,6 +224,51 @@ def to_libsvtav1_params(self) -> str:
225
224
return res
226
225
227
226
227
+ def parse_frame_data (frame_data : dict ):
228
+ color_params = ["pix_fmt" , "color_space" , "color_primaries" , "color_transfer" ]
229
+
230
+ missing_params = [x for x in color_params if x not in frame_data .keys ()]
231
+ if len (missing_params ) != 0 :
232
+ print (f"Missing { missing_params } parameters in frame metadata!" )
233
+ print ("Probably not an HDR stream!" )
234
+ print ("Exit!" )
235
+ return
236
+
237
+ color_data = ColorData (frame_data )
238
+ print ("Color Data:" )
239
+ print (color_data )
240
+ print ("" )
241
+
242
+ x265_params : str = color_data .to_x265_params ()
243
+ libaom_av1_params : str = color_data .to_libaom_av1_params ()
244
+ libsvtav1_params : str = color_data .to_libsvtav1_params ()
245
+
246
+ side_data_list = frame_data ["side_data_list" ]
247
+ for side_data in side_data_list :
248
+ if side_data ["side_data_type" ] == "Mastering display metadata" :
249
+ mastering_display_data = MasteringDisplayData (side_data )
250
+ x265_params += ":" + mastering_display_data .to_x265_params ()
251
+ libsvtav1_params += ":" + mastering_display_data .to_libsvtav1_params ()
252
+ print ("Mastering display metadata:" )
253
+ print (mastering_display_data )
254
+ print ("" )
255
+
256
+ elif side_data ["side_data_type" ] == "Content light level metadata" :
257
+ content_light_level_data = ContentLightLevelData (side_data )
258
+ x265_params += ":" + content_light_level_data .to_x265_params ()
259
+ libsvtav1_params += ":" + content_light_level_data .to_libsvtav1_params ()
260
+ print ("Content light level metadata:" )
261
+ print (content_light_level_data )
262
+ print ("" )
263
+
264
+ print (f"\n FFmpeg options: { color_data .to_ffmpeg_options ()} \n " )
265
+ print (f"x265 params: { x265_params } \n " )
266
+ print (f"libsvtav1 params: { libsvtav1_params } \n " )
267
+ print (f"libaom-av1 params: { libaom_av1_params } \n " )
268
+
269
+ print ("Done!" )
270
+
271
+
228
272
if __name__ == '__main__' :
229
273
230
274
# Initialize arguments parser
@@ -272,48 +316,23 @@ def to_libsvtav1_params(self) -> str:
272
316
"-select_streams" , str (arguments .input_stream ),
273
317
"-print_format" , "json" , "-show_frames" , "-read_intervals" , "%+#1" ,
274
318
"-show_entries" ,
319
+ "stream=codec_type:" +
275
320
"frame=pix_fmt,color_space,color_primaries,color_transfer,side_data_list" ,
276
321
"-i" , arguments .input_file ]
277
322
278
323
try :
279
324
result = subprocess .run (ffprobe_cmd , capture_output = True , encoding = "UTF-8" )
280
325
if result .returncode == 0 and result .stdout is not None :
281
326
metadata = json .loads (result .stdout )
282
- frame_data = metadata ["frames" ][0 ]
283
327
284
- color_data = ColorData (frame_data )
285
- print ("Color Data:" )
286
- print (color_data )
287
- print ("" )
328
+ stream_codec_type = metadata ["streams" ][0 ]["codec_type" ]
329
+ if stream_codec_type == "video" :
288
330
289
- x265_params : str = color_data .to_x265_params ()
290
- libaom_av1_params : str = color_data .to_libaom_av1_params ()
291
- libsvtav1_params : str = color_data .to_libsvtav1_params ()
292
-
293
- side_data_list = frame_data ["side_data_list" ]
294
- for side_data in side_data_list :
295
- if side_data ["side_data_type" ] == "Mastering display metadata" :
296
- mastering_display_data = MasteringDisplayData (side_data )
297
- x265_params += ":" + mastering_display_data .to_x265_params ()
298
- libsvtav1_params += ":" + mastering_display_data .to_libsvtav1_params ()
299
- print ("Mastering display metadata:" )
300
- print (mastering_display_data )
301
- print ("" )
302
-
303
- elif side_data ["side_data_type" ] == "Content light level metadata" :
304
- content_light_level_data = ContentLightLevelData (side_data )
305
- x265_params += ":" + content_light_level_data .to_x265_params ()
306
- libsvtav1_params += ":" + content_light_level_data .to_libsvtav1_params ()
307
- print ("Content light level metadata:" )
308
- print (content_light_level_data )
309
- print ("" )
310
-
311
- print (f"\n FFmpeg options: { color_data .to_ffmpeg_options ()} \n " )
312
- print (f"x265 params: { x265_params } \n " )
313
- print (f"libsvtav1 params: { libsvtav1_params } \n " )
314
- print (f"libaom-av1 params: { libaom_av1_params } \n " )
315
-
316
- print ("Done!" )
331
+ parse_frame_data (metadata ["frames" ][0 ])
332
+ else :
333
+ print (f"Selected stream type is \" { stream_codec_type } \" " )
334
+ print ("Not a video stream!" )
335
+ print ("Exit!" )
317
336
318
337
else :
319
338
print ("Error executing ffprobe binary!" )
0 commit comments