@@ -235,17 +235,26 @@ static int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFra
235235
236236 if (response >= 0 ) {
237237 logging (
238- "Frame %d (type=%c, size=%d bytes) pts %d key_frame %d [DTS %d]" ,
238+ "Frame %d (type=%c, size=%d bytes, format=%d ) pts %d key_frame %d [DTS %d]" ,
239239 pCodecContext -> frame_number ,
240240 av_get_picture_type_char (pFrame -> pict_type ),
241241 pFrame -> pkt_size ,
242+ pFrame -> format ,
242243 pFrame -> pts ,
243244 pFrame -> key_frame ,
244245 pFrame -> coded_picture_number
245246 );
246247
247248 char frame_filename [1024 ];
248249 snprintf (frame_filename , sizeof (frame_filename ), "%s-%d.pgm" , "frame" , pCodecContext -> frame_number );
250+ // Check if the frame is a planar YUV 4:2:0, 12bpp
251+ // That is the format of the provided .mp4 file
252+ // RGB formats will definitely not give a gray image
253+ // Other YUV image may do so, but untested, so give a warning
254+ if (pFrame -> format != AV_PIX_FMT_YUV420P )
255+ {
256+ logging ("Warning: the generated file may not be a grayscale image, but could e.g. be just the R component if the video format is RGB" );
257+ }
249258 // save a grayscale frame into a .pgm file
250259 save_gray_frame (pFrame -> data [0 ], pFrame -> linesize [0 ], pFrame -> width , pFrame -> height , frame_filename );
251260 }
0 commit comments