Index: media/ffmpeg/ffmpeg_common.cc |
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc |
index cb806c74812aba84ee66885a36f746f161ad0129..ba01afd0d60de6dc09f63289e7665f50bb88cbff 100644 |
--- a/media/ffmpeg/ffmpeg_common.cc |
+++ b/media/ffmpeg/ffmpeg_common.cc |
@@ -431,16 +431,20 @@ void AVStreamToVideoDecoderConfig( |
format = VideoFrame::YV12A; |
} |
- config->Initialize(codec, |
- profile, |
- format, |
- (stream->codec->colorspace == AVCOL_SPC_BT709) |
- ? VideoFrame::COLOR_SPACE_HD_REC709 |
- : VideoFrame::COLOR_SPACE_UNSPECIFIED, |
- coded_size, visible_rect, natural_size, |
- stream->codec->extradata, stream->codec->extradata_size, |
- is_encrypted, |
- record_stats); |
+ // Prefer the color space found by libavcodec if available. |
+ VideoFrame::ColorSpace color_space = |
+ AVColorSpaceToVideoFrameColorSpace(stream->codec->colorspace); |
+ if (color_space == VideoFrame::COLOR_SPACE_UNSPECIFIED) { |
+ // Otherwise, assume that SD video is usually Rec.601, and HD is usually |
+ // Rec.709. |
+ color_space = (natural_size.height() < 720) |
+ ? VideoFrame::COLOR_SPACE_SD_REC601 |
+ : VideoFrame::COLOR_SPACE_HD_REC709; |
+ } |
+ |
+ config->Initialize(codec, profile, format, color_space, coded_size, |
+ visible_rect, natural_size, stream->codec->extradata, |
+ stream->codec->extradata_size, is_encrypted, record_stats); |
} |
void VideoDecoderConfigToAVCodecContext( |
@@ -564,6 +568,22 @@ PixelFormat VideoFormatToPixelFormat(VideoFrame::Format video_format) { |
return PIX_FMT_NONE; |
} |
+VideoFrame::ColorSpace AVColorSpaceToVideoFrameColorSpace( |
+ AVColorSpace color_space) { |
+ switch (color_space) { |
+ case AVCOL_SPC_BT709: |
+ return VideoFrame::COLOR_SPACE_HD_REC709; |
+ case AVCOL_SPC_SMPTE170M: |
+ case AVCOL_SPC_BT470BG: |
+ return VideoFrame::COLOR_SPACE_SD_REC601; |
+ case AVCOL_SPC_UNSPECIFIED: |
+ break; |
+ default: |
+ DVLOG(1) << "Unknown AVColorSpace: " << color_space; |
+ } |
+ return VideoFrame::COLOR_SPACE_UNSPECIFIED; |
+} |
+ |
bool FFmpegUTCDateToTime(const char* date_utc, base::Time* out) { |
DCHECK(date_utc); |
DCHECK(out); |