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