1 /*! ========================================================================
4 ** $Id: trgt_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
32 #include <ETL/stringf>
33 #include "trgt_ffmpeg.h"
41 /* === M A C R O S ========================================================= */
43 using namespace sinfg;
47 /* === G L O B A L S ======================================================= */
49 SINFG_TARGET_INIT(ffmpeg_trgt);
50 SINFG_TARGET_SET_NAME(ffmpeg_trgt,"ffmpeg");
51 SINFG_TARGET_SET_EXT(ffmpeg_trgt,"mpg");
52 SINFG_TARGET_SET_VERSION(ffmpeg_trgt,"0.1");
53 SINFG_TARGET_SET_CVS_ID(ffmpeg_trgt,"$Id: trgt_ffmpeg.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
55 /* === M E T H O D S ======================================================= */
57 ffmpeg_trgt::ffmpeg_trgt(const char *Filename)
67 ffmpeg_trgt::~ffmpeg_trgt()
77 delete [] color_buffer;
81 ffmpeg_trgt::set_rend_desc(RendDesc *given_desc)
83 //given_desc->set_pixel_format(PF_RGB);
85 // Make sure that the width and height
87 given_desc->set_w((given_desc->get_w()+4)/8*8);
88 given_desc->set_h((given_desc->get_h()+4)/8*8);
92 // 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60
93 float fps=given_desc->get_frame_rate();
95 given_desc->set_frame_rate(23.976);
96 if(fps>=24.0 && fps <25.0)
97 given_desc->set_frame_rate(24);
98 if(fps>=25.0 && fps <29.97)
99 given_desc->set_frame_rate(25);
100 if(fps>=29.97 && fps <30.0)
101 given_desc->set_frame_rate(29.97);
102 if(fps>=29.97 && fps <30.0)
103 given_desc->set_frame_rate(29.97);
104 if(fps>=30.0 && fps <50.0)
105 given_desc->set_frame_rate(30.0);
106 if(fps>=50.0 && fps <59.94)
107 given_desc->set_frame_rate(50);
109 given_desc->set_frame_rate(59.94);
120 imagecount=desc.get_frame_start();
121 if(desc.get_frame_end()-desc.get_frame_start()>0)
125 command=strprintf("ffmpeg -f imagepipe -an -r %f -i pipe: -loop -hq -title \"%s\" -y \"%s\"\n",desc.get_frame_rate(),get_canvas()->get_name().c_str(),filename.c_str());
127 file=popen(command.c_str(),"w");
133 sinfg::error(_("Unable to open pipe to ffmpeg"));
141 ffmpeg_trgt::end_frame()
143 //fprintf(file, " ");
149 ffmpeg_trgt::start_frame(sinfg::ProgressCallback *callback)
151 int w=desc.get_w(),h=desc.get_h();
156 fprintf(file, "P6\n");
157 fprintf(file, "%d %d\n", w, h);
158 fprintf(file, "%d\n", 255);
161 buffer=new unsigned char[3*w];
162 delete [] color_buffer;
163 color_buffer=new Color[w];
169 ffmpeg_trgt::start_scanline(int scanline)
175 ffmpeg_trgt::end_scanline()
180 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
182 if(!fwrite(buffer,1,desc.get_w()*3,file))