render config sample/pixel fmt, piped files, ffmpeg raw yuv/rgb
[goodguy/history.git] / cinelerra-5.1 / cinelerra / filempeg.C
index 5c9b9bd3463cb0da38521906a08460ce45ac231a..9988673fe1215cfe1d41a9f64f2a2d8990205509 100644 (file)
@@ -105,10 +105,8 @@ FileMPEG::~FileMPEG()
 }
 
 void FileMPEG::get_parameters(BC_WindowBase *parent_window,
-       Asset *asset,
-       BC_WindowBase* &format_window,
-       int audio_options,
-       int video_options)
+       Asset *asset, BC_WindowBase* &format_window,
+       int audio_options, int video_options, EDL *edl)
 {
        if(audio_options && asset->format == FILE_AMPEG)
        {
@@ -495,7 +493,8 @@ int FileMPEG::open_file(int rd, int wr)
                        if(!result)
                        {
                                const char *exec_path = File::get_cinlib_path();
-                               sprintf(mjpeg_command, "%s/%s", exec_path, HVPEG_EXE);
+                               snprintf(mjpeg_command, sizeof(mjpeg_command),
+                                       "%s/%s", exec_path, HVPEG_EXE);
                                append_vcommand_line(mjpeg_command);
 
                                if(asset->aspect_ratio > 0)
@@ -545,7 +544,8 @@ int FileMPEG::open_file(int rd, int wr)
 //  this one is cinelerra-x.x.x/thirdparty/mjpegtools/mpeg2enc
                {
                        const char *exec_path = File::get_cinlib_path();
-                       sprintf(mjpeg_command, "%s/%s -v 0 ", exec_path, MJPEG_EXE);
+                       snprintf(mjpeg_command, sizeof(mjpeg_command),
+                               "%s/%s -v 0 ", exec_path, MJPEG_EXE);
 
 // Must disable interlacing if MPEG-1
                        switch (asset->vmpeg_preset)
@@ -560,18 +560,15 @@ int FileMPEG::open_file(int rd, int wr)
 // quantization of 1 when bitrate is fixed.  Perfectly intuitive.
                        if(asset->vmpeg_fix_bitrate)
                        {
-                               sprintf(string, " -b %d -q 1", asset->vmpeg_bitrate / 1000);
+                               snprintf(string, sizeof(string),
+                                       " -b %d -q 1", asset->vmpeg_bitrate / 1000);
                        }
                        else
                        {
-                               sprintf(string, " -b 0 -q %d", asset->vmpeg_quantization);
+                               snprintf(string, sizeof(string),
+                                       " -b 0 -q %d", asset->vmpeg_quantization);
                        }
-                       strcat(mjpeg_command, string);
-
-
-
-
-
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 // Aspect ratio
                        int aspect_ratio_code = -1;
@@ -599,7 +596,7 @@ int FileMPEG::open_file(int rd, int wr)
                                aspect_ratio_code = 2;
                        }
                        sprintf(string, " -a %d", aspect_ratio_code);
-                       strcat(mjpeg_command, string);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
 
@@ -623,43 +620,49 @@ int FileMPEG::open_file(int rd, int wr)
                                eprintf(_("Unsupported frame rate %f\n"), asset->frame_rate);
                        }
                        sprintf(string, " -F %d", frame_rate_code);
-                       strcat(mjpeg_command, string);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
 
 
 
-                       strcat(mjpeg_command,
-                               asset->vmpeg_progressive ? " -I 0" : " -I 1");
+                       strncat(mjpeg_command,
+                               asset->vmpeg_progressive ? " -I 0" : " -I 1",
+                               sizeof(mjpeg_command));
 
 
 
                        sprintf(string, " -M %d", file->cpus);
-                       strcat(mjpeg_command, string);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
                        if(!asset->vmpeg_progressive)
                        {
-                               strcat(mjpeg_command, asset->vmpeg_field_order ? " -z b" : " -z t");
+                               strncat(mjpeg_command,
+                                       asset->vmpeg_field_order ? " -z b" : " -z t",
+                                       sizeof(mjpeg_command));
                        }
 
 
-                       sprintf(string, " -f %d", asset->vmpeg_preset);
-                       strcat(mjpeg_command, string);
+                       snprintf(string, sizeof(string), " -f %d", asset->vmpeg_preset);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
-                       sprintf(string, " -g %d -G %d", asset->vmpeg_iframe_distance, asset->vmpeg_iframe_distance);
-                       strcat(mjpeg_command, string);
+                       snprintf(string, sizeof(string),
+                               " -g %d -G %d", asset->vmpeg_iframe_distance, asset->vmpeg_iframe_distance);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
-                       if(asset->vmpeg_seq_codes) strcat(mjpeg_command, " -s");
+                       if(asset->vmpeg_seq_codes)
+                               strncat(mjpeg_command, " -s", sizeof(mjpeg_command));
 
 
-                       sprintf(string, " -R %d", CLAMP(asset->vmpeg_pframe_distance, 0, 2));
-                       strcat(mjpeg_command, string);
+                       snprintf(string, sizeof(string),
+                               " -R %d", CLAMP(asset->vmpeg_pframe_distance, 0, 2));
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
-                       sprintf(string, " -o '%s'", asset->path);
-                       strcat(mjpeg_command, string);
+                       snprintf(string, sizeof(string), " -o '%s'", asset->path);
+                       strncat(mjpeg_command, string, sizeof(mjpeg_command));
 
 
 
@@ -781,7 +784,7 @@ int FileMPEG::toc_nail(void *vp, int track)
        if( mpeg->get_video_info(track, pid, framerate, width, height) ) return 1;
        if( pid < 0 || framerate <= 0 ) return 1;
        double position = framenum / framerate;
-//printf("t%d/%03x f"_LD", %dx%d %dx%d\n",track,pid,framenum,mw,mh,width,height);
+//printf("t%d/%03x f%jd, %dx%d %dx%d\n",track,pid,framenum,mw,mh,width,height);
        MWindow::commercials->get_frame(file, pid, position, tdat, mw, mh, width, height);
        return 0;
 }
@@ -792,7 +795,8 @@ int FileMPEG::create_toc(char *toc_path)
 // delete any existing toc files
        char toc_file[BCTEXTLEN];
        strcpy(toc_file, toc_path);
-       remove(toc_file);
+       if( strcmp(toc_file, asset->path) )
+               remove(toc_file);
        char *bp = strrchr(toc_file, '/');
        if( !bp ) bp = toc_file;
        char *sfx = strrchr(bp,'.');
@@ -992,7 +996,9 @@ int FileMPEG::get_best_colormodel(Asset *asset, int driver)
        switch(driver)
        {
                case PLAYBACK_X11:
-                       return BC_RGB888;
+//                     return BC_RGB888;
+// the direct X11 color model requires scaling in the codec
+                       return BC_BGR8888;
                case PLAYBACK_X11_XV:
                case PLAYBACK_ASYNCHRONOUS:
                        return zmpeg3_cmdl(asset->vmpeg_cmodel) > 0 ?
@@ -1317,12 +1323,8 @@ int FileMPEG::write_frames(VFrame ***frames, int len)
 
                                                if(!temp_frame)
                                                {
-                                                       temp_frame = new VFrame(0,
-                                                               -1,
-                                                               temp_w,
-                                                               temp_h,
-                                                               output_cmodel,
-                                                               -1);
+                                                       temp_frame = new VFrame(temp_w, temp_h,
+                                                                       output_cmodel, 0);
                                                }
 
                                                BC_CModels::transfer(temp_frame->get_rows(),
@@ -1368,12 +1370,8 @@ int FileMPEG::write_frames(VFrame ***frames, int len)
 //printf("FileMPEG::write_frames %d\n", __LINE__);sleep(1);
                                                if(!temp_frame)
                                                {
-                                                       temp_frame = new VFrame(0,
-                                                               -1,
-                                                               asset->width,
-                                                               asset->height,
-                                                               output_cmodel,
-                                                               -1);
+                                                       temp_frame = new VFrame(asset->width, asset->height,
+                                                                               output_cmodel, 0);
                                                }
 
 // printf("FileMPEG::write_frames %d temp_frame=%p %p %p %p frame=%p %p %p %p color_model=%p %p\n",