// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/ffmpeg/ffmpeg_common.h" #include "base/logging.h" namespace media { static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; base::TimeDelta ConvertTimestamp(const AVRational& time_base, int64 timestamp) { int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); return base::TimeDelta::FromMicroseconds(microseconds); } VideoCodec CodecIDToVideoCodec(CodecID codec_id) { switch (codec_id) { case CODEC_ID_VC1: return kCodecVC1; case CODEC_ID_H264: return kCodecH264; case CODEC_ID_THEORA: return kCodecTheora; case CODEC_ID_MPEG2VIDEO: return kCodecMPEG2; case CODEC_ID_MPEG4: return kCodecMPEG4; case CODEC_ID_VP8: return kCodecVP8; default: NOTREACHED(); } return kUnknown; } CodecID VideoCodecToCodecID(VideoCodec video_codec) { switch (video_codec) { case kCodecVC1: return CODEC_ID_VC1; case kCodecH264: return CODEC_ID_H264; case kCodecTheora: return CODEC_ID_THEORA; case kCodecMPEG2: return CODEC_ID_MPEG2VIDEO; case kCodecMPEG4: return CODEC_ID_MPEG4; case kCodecVP8: return CODEC_ID_VP8; default: NOTREACHED(); } return CODEC_ID_NONE; } } // namespace media