]> git.sesse.net Git - casparcg/blob - modules/ffmpeg/producer/util/util.cpp
2.1.0: Put "array" into its own file, common/memory/array.
[casparcg] / modules / ffmpeg / producer / util / util.cpp
1 /*\r
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 * This file is part of CasparCG (www.casparcg.com).\r
5 *\r
6 * CasparCG is free software: you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation, either version 3 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * CasparCG is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 * Author: Robert Nagy, ronag89@gmail.com\r
20 */\r
21 \r
22 #include "../../stdafx.h"\r
23 \r
24 #include "util.h"\r
25 \r
26 #include "flv.h"\r
27 \r
28 #include "../tbb_avcodec.h"\r
29 #include "../../ffmpeg_error.h"\r
30 \r
31 #include <tbb/concurrent_unordered_map.h>\r
32 #include <tbb/concurrent_queue.h>\r
33 \r
34 #include <core/frame/frame_transform.h>\r
35 #include <core/frame/frame_factory.h>\r
36 #include <core/frame/frame.h>\r
37 #include <core/producer/frame_producer.h>\r
38 \r
39 #include <common/except.h>\r
40 #include <common/memory/array.h>\r
41 \r
42 #include <tbb/parallel_for.h>\r
43 \r
44 #include <common/assert.h>\r
45 #include <boost/filesystem.hpp>\r
46 #include <boost/lexical_cast.hpp>\r
47 \r
48 #include <asmlib.h>\r
49 \r
50 #if defined(_MSC_VER)\r
51 #pragma warning (push)\r
52 #pragma warning (disable : 4244)\r
53 #endif\r
54 extern "C" \r
55 {\r
56         #include <libswscale/swscale.h>\r
57         #include <libavcodec/avcodec.h>\r
58         #include <libavformat/avformat.h>\r
59 }\r
60 #if defined(_MSC_VER)\r
61 #pragma warning (pop)\r
62 #endif\r
63 \r
64 namespace caspar { namespace ffmpeg {\r
65                 \r
66 std::shared_ptr<core::audio_buffer> flush_audio()\r
67 {\r
68         static std::shared_ptr<core::audio_buffer> audio(new core::audio_buffer());\r
69         return audio;\r
70 }\r
71 \r
72 std::shared_ptr<core::audio_buffer> empty_audio()\r
73 {\r
74         static std::shared_ptr<core::audio_buffer> audio(new core::audio_buffer());\r
75         return audio;\r
76 }\r
77 \r
78 std::shared_ptr<AVFrame>                        flush_video()\r
79 {\r
80         static std::shared_ptr<AVFrame> video(avcodec_alloc_frame(), av_free);\r
81         return video;\r
82 }\r
83 \r
84 std::shared_ptr<AVFrame>                        empty_video()\r
85 {\r
86         static std::shared_ptr<AVFrame> video(avcodec_alloc_frame(), av_free);\r
87         return video;\r
88 }\r
89 \r
90 core::field_mode get_mode(const AVFrame& frame)\r
91 {\r
92         if(!frame.interlaced_frame)\r
93                 return core::field_mode::progressive;\r
94 \r
95         return frame.top_field_first ? core::field_mode::upper : core::field_mode::lower;\r
96 }\r
97 \r
98 core::pixel_format get_pixel_format(PixelFormat pix_fmt)\r
99 {\r
100         switch(pix_fmt)\r
101         {\r
102         case CASPAR_PIX_FMT_LUMA:       return core::pixel_format::luma;\r
103         case PIX_FMT_GRAY8:                     return core::pixel_format::gray;\r
104         case PIX_FMT_BGRA:                      return core::pixel_format::bgra;\r
105         case PIX_FMT_ARGB:                      return core::pixel_format::argb;\r
106         case PIX_FMT_RGBA:                      return core::pixel_format::rgba;\r
107         case PIX_FMT_ABGR:                      return core::pixel_format::abgr;\r
108         case PIX_FMT_YUV444P:           return core::pixel_format::ycbcr;\r
109         case PIX_FMT_YUV422P:           return core::pixel_format::ycbcr;\r
110         case PIX_FMT_YUV420P:           return core::pixel_format::ycbcr;\r
111         case PIX_FMT_YUV411P:           return core::pixel_format::ycbcr;\r
112         case PIX_FMT_YUV410P:           return core::pixel_format::ycbcr;\r
113         case PIX_FMT_YUVA420P:          return core::pixel_format::ycbcra;\r
114         default:                                        return core::pixel_format::invalid;\r
115         }\r
116 }\r
117 \r
118 core::pixel_format_desc pixel_format_desc(PixelFormat pix_fmt, int width, int height)\r
119 {\r
120         // Get linesizes\r
121         AVPicture dummy_pict;   \r
122         avpicture_fill(&dummy_pict, nullptr, pix_fmt == CASPAR_PIX_FMT_LUMA ? PIX_FMT_GRAY8 : pix_fmt, width, height);\r
123 \r
124         core::pixel_format_desc desc = get_pixel_format(pix_fmt);\r
125                 \r
126         switch(desc.format.value())\r
127         {\r
128         case core::pixel_format::gray:\r
129         case core::pixel_format::luma:\r
130                 {\r
131                         desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[0], height, 1));                                               \r
132                         return desc;\r
133                 }\r
134         case core::pixel_format::bgra:\r
135         case core::pixel_format::argb:\r
136         case core::pixel_format::rgba:\r
137         case core::pixel_format::abgr:\r
138                 {\r
139                         desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[0]/4, height, 4));                                             \r
140                         return desc;\r
141                 }\r
142         case core::pixel_format::ycbcr:\r
143         case core::pixel_format::ycbcra:\r
144                 {               \r
145                         // Find chroma height\r
146                         int size2 = static_cast<int>(dummy_pict.data[2] - dummy_pict.data[1]);\r
147                         int h2 = size2/dummy_pict.linesize[1];                  \r
148 \r
149                         desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[0], height, 1));\r
150                         desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[1], h2, 1));\r
151                         desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[2], h2, 1));\r
152 \r
153                         if(desc.format == core::pixel_format::ycbcra)                                           \r
154                                 desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[3], height, 1));       \r
155                         return desc;\r
156                 }               \r
157         default:                \r
158                 desc.format = core::pixel_format::invalid;\r
159                 return desc;\r
160         }\r
161 }\r
162 \r
163 int make_alpha_format(int format)\r
164 {\r
165         switch(get_pixel_format(static_cast<PixelFormat>(format)).value())\r
166         {\r
167         case core::pixel_format::ycbcr:\r
168         case core::pixel_format::ycbcra:\r
169                 return CASPAR_PIX_FMT_LUMA;\r
170         default:\r
171                 return format;\r
172         }\r
173 }\r
174 \r
175 core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, double fps, const spl::shared_ptr<core::frame_factory>& frame_factory, int flags)\r
176 {                       \r
177         static tbb::concurrent_unordered_map<int, tbb::concurrent_queue<std::shared_ptr<SwsContext>>> sws_contexts_;\r
178         \r
179         if(decoded_frame->width < 1 || decoded_frame->height < 1)\r
180                 return frame_factory->create_frame(tag, core::pixel_format_desc(core::pixel_format::invalid));\r
181 \r
182         const auto width  = decoded_frame->width;\r
183         const auto height = decoded_frame->height;\r
184         auto desc                 = pixel_format_desc(static_cast<PixelFormat>(decoded_frame->format), width, height);\r
185         \r
186         if(flags & core::frame_producer::flags::alpha_only)\r
187                 desc = pixel_format_desc(static_cast<PixelFormat>(make_alpha_format(decoded_frame->format)), width, height);\r
188         \r
189         if(desc.format == core::pixel_format::invalid)\r
190         {\r
191                 auto pix_fmt = static_cast<PixelFormat>(decoded_frame->format);\r
192                 auto target_pix_fmt = PIX_FMT_BGRA;\r
193 \r
194                 if(pix_fmt == PIX_FMT_UYVY422)\r
195                         target_pix_fmt = PIX_FMT_YUV422P;\r
196                 else if(pix_fmt == PIX_FMT_YUYV422)\r
197                         target_pix_fmt = PIX_FMT_YUV422P;\r
198                 else if(pix_fmt == PIX_FMT_UYYVYY411)\r
199                         target_pix_fmt = PIX_FMT_YUV411P;\r
200                 else if(pix_fmt == PIX_FMT_YUV420P10)\r
201                         target_pix_fmt = PIX_FMT_YUV420P;\r
202                 else if(pix_fmt == PIX_FMT_YUV422P10)\r
203                         target_pix_fmt = PIX_FMT_YUV422P;\r
204                 else if(pix_fmt == PIX_FMT_YUV444P10)\r
205                         target_pix_fmt = PIX_FMT_YUV444P;\r
206                 \r
207                 auto target_desc = pixel_format_desc(target_pix_fmt, width, height);\r
208 \r
209                 auto write = frame_factory->create_frame(tag, target_desc, fps, get_mode(*decoded_frame));\r
210 \r
211                 std::shared_ptr<SwsContext> sws_context;\r
212 \r
213                 //CASPAR_LOG(warning) << "Hardware accelerated color transform not supported.";\r
214 \r
215                 int key = ((width << 22) & 0xFFC00000) | ((height << 6) & 0x003FC000) | ((pix_fmt << 7) & 0x00007F00) | ((target_pix_fmt << 0) & 0x0000007F);\r
216                         \r
217                 auto& pool = sws_contexts_[key];\r
218                                                 \r
219                 if(!pool.try_pop(sws_context))\r
220                 {\r
221                         double param;\r
222                         sws_context.reset(sws_getContext(width, height, pix_fmt, width, height, target_pix_fmt, SWS_BILINEAR, nullptr, nullptr, &param), sws_freeContext);\r
223                 }\r
224                         \r
225                 if(!sws_context)\r
226                 {\r
227                         BOOST_THROW_EXCEPTION(operation_failed() << msg_info("Could not create software scaling context.") << \r
228                                                                         boost::errinfo_api_function("sws_getContext"));\r
229                 }       \r
230                 \r
231                 spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      \r
232                 avcodec_get_frame_defaults(av_frame.get());                     \r
233                 if(target_pix_fmt == PIX_FMT_BGRA)\r
234                 {\r
235                         auto size = avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), write.image_data(0).begin(), PIX_FMT_BGRA, width, height);\r
236                         CASPAR_VERIFY(size == write.image_data(0).size()); \r
237                 }\r
238                 else\r
239                 {\r
240                         av_frame->width  = width;\r
241                         av_frame->height = height;\r
242                         for(int n = 0; n < target_desc.planes.size(); ++n)\r
243                         {\r
244                                 av_frame->data[n]               = write.image_data(n).begin();\r
245                                 av_frame->linesize[n]   = target_desc.planes[n].linesize;\r
246                         }\r
247                 }\r
248 \r
249                 sws_scale(sws_context.get(), decoded_frame->data, decoded_frame->linesize, 0, height, av_frame->data, av_frame->linesize);      \r
250                 pool.push(sws_context); \r
251 \r
252                 return std::move(write);\r
253         }\r
254         else\r
255         {\r
256                 auto write = frame_factory->create_frame(tag, desc, fps, get_mode(*decoded_frame));\r
257                 \r
258                 for(int n = 0; n < static_cast<int>(desc.planes.size()); ++n)\r
259                 {\r
260                         auto plane            = desc.planes[n];\r
261                         auto result           = write.image_data(n).begin();\r
262                         auto decoded          = decoded_frame->data[n];\r
263                         auto decoded_linesize = decoded_frame->linesize[n];\r
264                         \r
265                         CASPAR_ASSERT(decoded);\r
266                         CASPAR_ASSERT(write.image_data(n).begin());\r
267 \r
268                         // Copy line by line since ffmpeg sometimes pads each line.\r
269                         tbb::affinity_partitioner ap;\r
270                         tbb::parallel_for(tbb::blocked_range<int>(0, desc.planes[n].height), [&](const tbb::blocked_range<int>& r)\r
271                         {\r
272                                 for(int y = r.begin(); y != r.end(); ++y)\r
273                                         A_memcpy(result + y*plane.linesize, decoded + y*decoded_linesize, plane.linesize);\r
274                         }, ap);\r
275                 }\r
276         \r
277                 return std::move(write);\r
278         }\r
279 }\r
280 \r
281 spl::shared_ptr<AVFrame> make_av_frame(core::mutable_frame& frame)\r
282 {\r
283         std::array<uint8_t*, 4> data = {};\r
284         for(int n = 0; n < frame.pixel_format_desc().planes.size(); ++n)\r
285                 data[n] = frame.image_data(n).begin();\r
286 \r
287         return make_av_frame(data, frame.pixel_format_desc());\r
288 }\r
289 \r
290 spl::shared_ptr<AVFrame> make_av_frame(std::array<uint8_t*, 4> data, const core::pixel_format_desc& pix_desc)\r
291 {\r
292         spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      \r
293         avcodec_get_frame_defaults(av_frame.get());\r
294         \r
295         auto planes              = pix_desc.planes;\r
296         auto format              = pix_desc.format.value();\r
297 \r
298         av_frame->width  = planes[0].width;\r
299         av_frame->height = planes[0].height;\r
300         for(int n = 0; n < planes.size(); ++n)  \r
301         {\r
302                 av_frame->data[n]         = data[n];\r
303                 av_frame->linesize[n] = planes[n].linesize;     \r
304         }\r
305         switch(format)\r
306         {\r
307         case core::pixel_format::rgba:\r
308                 av_frame->format = PIX_FMT_RGBA; \r
309                 break;\r
310         case core::pixel_format::argb:\r
311                 av_frame->format = PIX_FMT_ARGB; \r
312                 break;\r
313         case core::pixel_format::bgra:\r
314                 av_frame->format = PIX_FMT_BGRA; \r
315                 break;\r
316         case core::pixel_format::abgr:\r
317                 av_frame->format = PIX_FMT_ABGR; \r
318                 break;\r
319         case core::pixel_format::gray:\r
320                 av_frame->format = PIX_FMT_GRAY8; \r
321                 break;\r
322         case core::pixel_format::ycbcr:\r
323         {\r
324                 int y_w = planes[0].width;\r
325                 int y_h = planes[0].height;\r
326                 int c_w = planes[1].width;\r
327                 int c_h = planes[1].height;\r
328 \r
329                 if(c_h == y_h && c_w == y_w)\r
330                         av_frame->format = PIX_FMT_YUV444P;\r
331                 else if(c_h == y_h && c_w*2 == y_w)\r
332                         av_frame->format = PIX_FMT_YUV422P;\r
333                 else if(c_h == y_h && c_w*4 == y_w)\r
334                         av_frame->format = PIX_FMT_YUV411P;\r
335                 else if(c_h*2 == y_h && c_w*2 == y_w)\r
336                         av_frame->format = PIX_FMT_YUV420P;\r
337                 else if(c_h*2 == y_h && c_w*4 == y_w)\r
338                         av_frame->format = PIX_FMT_YUV410P;\r
339 \r
340                 break;\r
341         }\r
342         case core::pixel_format::ycbcra:\r
343                 av_frame->format = PIX_FMT_YUVA420P;\r
344                 break;\r
345         }\r
346         return av_frame;\r
347 }\r
348 \r
349 bool is_sane_fps(AVRational time_base)\r
350 {\r
351         double fps = static_cast<double>(time_base.den) / static_cast<double>(time_base.num);\r
352         return fps > 20.0 && fps < 65.0;\r
353 }\r
354 \r
355 AVRational fix_time_base(AVRational time_base)\r
356 {\r
357         if(time_base.num == 1)\r
358                 time_base.num = static_cast<int>(std::pow(10.0, static_cast<int>(std::log10(static_cast<float>(time_base.den)))-1));    \r
359                         \r
360         if(!is_sane_fps(time_base))\r
361         {\r
362                 auto tmp = time_base;\r
363                 tmp.den /= 2;\r
364                 if(is_sane_fps(tmp))\r
365                         time_base = tmp;\r
366         }\r
367 \r
368         return time_base;\r
369 }\r
370 \r
371 double read_fps(AVFormatContext& context, double fail_value)\r
372 {                                               \r
373         auto video_index = av_find_best_stream(&context, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);\r
374         auto audio_index = av_find_best_stream(&context, AVMEDIA_TYPE_AUDIO, -1, -1, 0, 0);\r
375         \r
376         if(video_index > -1)\r
377         {\r
378                 const auto video_context = context.streams[video_index]->codec;\r
379                 const auto video_stream  = context.streams[video_index];\r
380                                                 \r
381                 AVRational time_base = video_context->time_base;\r
382 \r
383                 if(boost::filesystem::path(context.filename).extension().string() == ".flv")\r
384                 {\r
385                         try\r
386                         {\r
387                                 auto meta = read_flv_meta_info(context.filename);\r
388                                 return boost::lexical_cast<double>(meta["framerate"]);\r
389                         }\r
390                         catch(...)\r
391                         {\r
392                                 return 0.0;\r
393                         }\r
394                 }\r
395                 else\r
396                 {\r
397                         time_base.num *= video_context->ticks_per_frame;\r
398 \r
399                         if(!is_sane_fps(time_base))\r
400                         {                       \r
401                                 time_base = fix_time_base(time_base);\r
402 \r
403                                 if(!is_sane_fps(time_base) && audio_index > -1)\r
404                                 {\r
405                                         auto& audio_context = *context.streams[audio_index]->codec;\r
406                                         auto& audio_stream  = *context.streams[audio_index];\r
407 \r
408                                         double duration_sec = audio_stream.duration / static_cast<double>(audio_context.sample_rate);\r
409                                                                 \r
410                                         time_base.num = static_cast<int>(duration_sec*100000.0);\r
411                                         time_base.den = static_cast<int>(video_stream->nb_frames*100000);\r
412                                 }\r
413                         }\r
414                 }\r
415                 \r
416                 double fps = static_cast<double>(time_base.den) / static_cast<double>(time_base.num);\r
417 \r
418                 double closest_fps = 0.0;\r
419                 for(int n = 0; n < core::video_format::count; ++n)\r
420                 {\r
421                         auto format = core::video_format_desc(core::video_format(n));\r
422 \r
423                         double diff1 = std::abs(format.fps - fps);\r
424                         double diff2 = std::abs(closest_fps - fps);\r
425 \r
426                         if(diff1 < diff2)\r
427                                 closest_fps = format.fps;\r
428                 }\r
429         \r
430                 return closest_fps;\r
431         }\r
432 \r
433         return fail_value;      \r
434 }\r
435 \r
436 void fix_meta_data(AVFormatContext& context)\r
437 {\r
438         auto video_index = av_find_best_stream(&context, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);\r
439 \r
440         if(video_index > -1)\r
441         {\r
442                 auto video_stream   = context.streams[video_index];\r
443                 auto video_context  = context.streams[video_index]->codec;\r
444                                                 \r
445                 if(boost::filesystem::path(context.filename).extension().string() == ".flv")\r
446                 {\r
447                         try\r
448                         {\r
449                                 auto meta = read_flv_meta_info(context.filename);\r
450                                 double fps = boost::lexical_cast<double>(meta["framerate"]);\r
451                                 video_stream->nb_frames = static_cast<int64_t>(boost::lexical_cast<double>(meta["duration"])*fps);\r
452                         }\r
453                         catch(...){}\r
454                 }\r
455                 else\r
456                 {\r
457                         auto stream_time = video_stream->time_base;\r
458                         auto duration    = video_stream->duration;\r
459                         auto codec_time  = video_context->time_base;\r
460                         auto ticks               = video_context->ticks_per_frame;\r
461 \r
462                         if(video_stream->nb_frames == 0)\r
463                                 video_stream->nb_frames = (duration*stream_time.num*codec_time.den)/(stream_time.den*codec_time.num*ticks);     \r
464                 }\r
465         }\r
466 }\r
467 \r
468 spl::shared_ptr<AVPacket> create_packet()\r
469 {\r
470         spl::shared_ptr<AVPacket> packet(new AVPacket, [](AVPacket* p)\r
471         {\r
472                 av_free_packet(p);\r
473                 delete p;\r
474         });\r
475         \r
476         av_init_packet(packet.get());\r
477         return packet;\r
478 }\r
479 \r
480 spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index)\r
481 {       \r
482         AVCodec* decoder;\r
483         index = THROW_ON_ERROR2(av_find_best_stream(&context, type, -1, -1, &decoder, 0), "");\r
484         //if(strcmp(decoder->name, "prores") == 0 && decoder->next && strcmp(decoder->next->name, "prores_lgpl") == 0)\r
485         //      decoder = decoder->next;\r
486 \r
487         THROW_ON_ERROR2(tbb_avcodec_open(context.streams[index]->codec, decoder), "");\r
488         return spl::shared_ptr<AVCodecContext>(context.streams[index]->codec, tbb_avcodec_close);\r
489 }\r
490 \r
491 spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename)\r
492 {\r
493         AVFormatContext* weak_context = nullptr;\r
494         THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(filename).c_str(), nullptr, nullptr), filename);\r
495         spl::shared_ptr<AVFormatContext> context(weak_context, av_close_input_file);                    \r
496         THROW_ON_ERROR2(avformat_find_stream_info(weak_context, nullptr), filename);\r
497         fix_meta_data(*context);\r
498         return context;\r
499 }\r
500 \r
501 std::wstring print_mode(int width, int height, double fps, bool interlaced)\r
502 {\r
503         std::wostringstream fps_ss;\r
504         fps_ss << std::fixed << std::setprecision(2) << (!interlaced ? fps : 2.0 * fps);\r
505 \r
506         return boost::lexical_cast<std::wstring>(width) + L"x" + boost::lexical_cast<std::wstring>(height) + (!interlaced ? L"p" : L"i") + fps_ss.str();\r
507 }\r
508 \r
509 bool is_valid_file(const std::wstring filename)\r
510 {                       \r
511         if(boost::filesystem::path(filename).extension() == ".m2t")\r
512                 return true;\r
513 \r
514         std::ifstream file(filename);\r
515 \r
516         std::vector<unsigned char> buf;\r
517         for(auto file_it = std::istreambuf_iterator<char>(file); file_it != std::istreambuf_iterator<char>() && buf.size() < 2048; ++file_it)\r
518                 buf.push_back(*file_it);\r
519 \r
520         if(buf.empty())\r
521                 return nullptr;\r
522 \r
523         AVProbeData pb;\r
524         pb.filename = u8(filename).c_str();\r
525         pb.buf          = buf.data();\r
526         pb.buf_size = static_cast<int>(buf.size());\r
527 \r
528         int score = 0;\r
529         return av_probe_input_format2(&pb, true, &score) != nullptr;\r
530 }\r
531 \r
532 std::wstring probe_stem(const std::wstring stem)\r
533 {\r
534         auto stem2 = boost::filesystem::path(stem);\r
535         auto dir = stem2.parent_path();\r
536         for(auto it = boost::filesystem::directory_iterator(dir); it != boost::filesystem::directory_iterator(); ++it)\r
537         {\r
538                 if(boost::iequals(it->path().stem().wstring(), stem2.filename().wstring()) && is_valid_file(it->path().wstring()))\r
539                         return it->path().wstring();\r
540         }\r
541         return L"";\r
542 }\r
543 //\r
544 //void av_dup_frame(AVFrame* frame)\r
545 //{\r
546 //      AVFrame* new_frame = avcodec_alloc_frame();\r
547 //\r
548 //\r
549 //      const uint8_t *src_data[4] = {0};\r
550 //      memcpy(const_cast<uint8_t**>(&src_data[0]), frame->data, 4);\r
551 //      const int src_linesizes[4] = {0};\r
552 //      memcpy(const_cast<int*>(&src_linesizes[0]), frame->linesize, 4);\r
553 //\r
554 //      av_image_alloc(new_frame->data, new_frame->linesize, new_frame->width, new_frame->height, frame->format, 16);\r
555 //\r
556 //      av_image_copy(new_frame->data, new_frame->linesize, src_data, src_linesizes, frame->format, new_frame->width, new_frame->height);\r
557 //\r
558 //      frame =\r
559 //}\r
560 \r
561 }}