2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
24 #include <core/video_format.h>
28 namespace caspar { namespace ffmpeg {
37 deinterlace_bob_reinterlace,
43 template< typename CharT, typename TraitsT >
44 std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream<CharT, TraitsT>& o, display_mode value)
48 case simple: return o << L"simple";
49 case duplicate: return o << L"duplicate";
50 case half: return o << L"half";
51 case interlace: return o << L"interlace";
52 case deinterlace_bob: return o << L"deinterlace_bob";
53 case deinterlace_bob_reinterlace: return o << L"deinterlace_bob_reinterlace";
54 case deinterlace: return o << L"deinterlace";
55 default: return o << L"invalid";
59 static display_mode get_display_mode(const core::field_mode in_mode, double in_fps, const core::field_mode out_mode, double out_fps)
61 static const auto epsilon = 2.0;
63 if(in_fps < 20.0 || in_fps > 80.0)
65 //if(out_mode != core::field_mode::progressive && in_mode == core::field_mode::progressive)
66 // return display_mode::interlace;
68 if(out_mode == core::field_mode::progressive && in_mode != core::field_mode::progressive)
71 return display_mode::deinterlace;
73 return display_mode::deinterlace_bob;
77 if(std::abs(in_fps - out_fps) < epsilon)
79 if(in_mode != core::field_mode::progressive && out_mode == core::field_mode::progressive)
80 return display_mode::deinterlace;
81 //else if(in_mode == core::field_mode::progressive && out_mode != core::field_mode::progressive)
82 // simple(); // interlace_duplicate();
84 return display_mode::simple;
86 else if(std::abs(in_fps/2.0 - out_fps) < epsilon)
88 if(in_mode != core::field_mode::progressive)
89 return display_mode::invalid;
91 if(out_mode != core::field_mode::progressive)
92 return display_mode::interlace;
94 return display_mode::half;
96 else if(std::abs(in_fps - out_fps/2.0) < epsilon)
98 if(out_mode != core::field_mode::progressive)
99 return display_mode::invalid;
101 if(in_mode != core::field_mode::progressive)
102 return display_mode::deinterlace_bob;
104 return display_mode::duplicate;
107 return display_mode::invalid;