12 #include "mwindow.inc"
14 #include "videodevice.inc"
15 #include "mainerror.h"
26 N_("Microsoft MPEG-4")
30 N_("Uncompressed RGB")
31 N_("Uncompressed RGBA")
32 N_("YUV 4:2:0 Planar")
33 N_("Component Y'CbCr 8-bit 4:2:2 (yuv2)")
34 N_("Component Y'CbCr 8-bit 4:2:2 (2vuy)")
35 N_("YUV 4:1:1 Packed")
36 N_("Component Y'CbCr 8-bit 4:4:4")
37 N_("Component Y'CbCrA 8-bit 4:4:4:4")
38 N_("Component Y'CbCr 10-bit 4:4:4")
52 #define DIVX_NAME "MPEG-4"
53 #define HV64_NAME "Dual H.264"
54 #define MP4V_NAME "MPEG-4 Video"
55 #define H264_NAME "H.264"
56 #define H263_NAME "H.263"
57 #define HV60_NAME "Dual MPEG-4"
58 #define DIV3_NAME "Microsoft MPEG-4"
60 #define PNG_NAME "PNG"
61 #define PNGA_NAME "PNG with Alpha"
62 #define RGB_NAME "Uncompressed RGB"
63 #define RGBA_NAME "Uncompressed RGBA"
64 #define YUV420_NAME "YUV 4:2:0 Planar"
65 #define YUV422_NAME "Component Y'CbCr 8-bit 4:2:2 (yuv2)"
66 #define TWOVUY_NAME "Component Y'CbCr 8-bit 4:2:2 (2vuy)"
67 #define YUV411_NAME "YUV 4:1:1 Packed"
68 #define YUV444_NAME "Component Y'CbCr 8-bit 4:4:4"
69 #define YUVA4444_NAME "Component Y'CbCrA 8-bit 4:4:4:4"
70 #define YUV444_10BIT_NAME "Component Y'CbCr 10-bit 4:4:4"
71 #define QTJPEG_NAME "JPEG Photo"
72 #define MJPA_NAME "Motion JPEG A"
74 #define TWOS_NAME "Twos complement"
75 #define RAW_NAME "Unsigned"
76 #define IMA4_NAME "IMA-4"
77 #define ULAW_NAME "U-Law"
78 //#define VORBIS_NAME "Vorbis"
79 #define MP3_NAME "MP3"
80 #define MP4A_NAME "MPEG-4 Audio"
81 #define VORBIS_NAME "OGG Vorbis"
87 FileMOV::FileMOV(Asset *asset, File *file)
88 : FileBase(asset, file)
91 if(asset->format == FILE_UNKNOWN)
92 asset->format = FILE_MOV;
93 asset->byte_order = 0;
95 threadframe_lock = new Mutex("FileMOV::threadframe_lock");
103 delete threadframe_lock;
107 void FileMOV::get_parameters(BC_WindowBase *parent_window,
109 BC_WindowBase* &format_window,
112 char *locked_compressor)
117 MOVConfigAudio *window = new MOVConfigAudio(parent_window, asset);
118 format_window = window;
119 window->create_objects();
120 window->run_window();
126 MOVConfigVideo *window = new MOVConfigVideo(parent_window,
129 format_window = window;
130 window->create_objects();
131 window->run_window();
136 void FileMOV::fix_codecs(Asset *asset)
138 if(!strcasecmp(asset->vcodec, QUICKTIME_DV) ||
139 !strcasecmp(asset->vcodec, QUICKTIME_DVSD) ||
140 !strcasecmp(asset->vcodec, QUICKTIME_DVCP))
142 // printf("AF: %i, AH: %i, VC: %s\n", asset->format, asset->height, asset->vcodec);
143 if (asset->format == FILE_AVI)
144 strcpy (asset->vcodec, QUICKTIME_DVSD);
145 else if (asset->format == FILE_MOV && asset->height == 576)
146 strcpy (asset->vcodec, QUICKTIME_DVCP);
147 else if (asset->format == FILE_MOV && asset->height == 480)
148 strcpy (asset->vcodec, QUICKTIME_DV);
153 int FileMOV::check_codec_params(Asset *asset)
155 if(!strcasecmp(asset->vcodec, QUICKTIME_DV) ||
156 !strcasecmp(asset->vcodec, QUICKTIME_DVSD) ||
157 !strcasecmp(asset->vcodec, QUICKTIME_DVCP))
160 if (!(asset->height == 576 && asset->width == 720) &&
161 !(asset->height == 480 && asset->width == 720))
163 eprintf("DV in Quicktime container does not support following resolution: %ix%i\nAllowed resolutions are 720x576 (PAL) and 720x480 (NTSC)\n", asset->width, asset->height);
170 int FileMOV::check_sig(Asset *asset)
172 return quicktime_check_sig(asset->path);
176 int FileMOV::reset_parameters_derived()
180 quicktime_atracks = 0;
181 quicktime_vtracks = 0;
184 frames_correction = 0;
185 samples_correction = 0;
191 // Just create the Quicktime objects since this routine is also called
193 int FileMOV::open_file(int rd, int wr)
199 if(suffix_number == 0) strcpy(prefix_path, asset->path);
201 if(!(fd = quicktime_open(asset->path, rd, wr)))
203 eprintf("Error while opening file \"%s\". \n%m\n", asset->path);
207 quicktime_set_cpus(fd, file->cpus);
209 if(rd) format_to_asset();
214 if (check_codec_params(asset))
217 // Set decoding parameter
218 quicktime_set_parameter(fd, "divx_use_deblocking", &asset->divx_use_deblocking);
220 // Set timecode offset
221 quicktime_set_frame_start(fd, asset->tcstart);
226 int FileMOV::close_file()
228 //printf("FileMOV::close_file 1 %s\n", asset->path);
231 if(wr) quicktime_set_framerate(fd, asset->frame_rate);
235 //printf("FileMOV::close_file 1\n");
238 for(int i = 0; i < file->cpus; i++)
240 threads[i]->stop_encoding();
247 //printf("FileMOV::close_file 1\n");
248 threadframes.remove_all_objects();
253 for(int i = 0; i < asset->channels; i++)
254 delete [] temp_float[i];
255 delete [] temp_float;
258 //printf("FileMOV::close_file 1\n");
260 FileBase::close_file();
261 //printf("FileMOV::close_file 2\n");
265 void FileMOV::set_frame_start(int64_t offset)
267 quicktime_set_frame_start(fd, offset);
270 void FileMOV::asset_to_format()
277 // Fix up the Quicktime file.
278 quicktime_set_copyright(fd, _("Made with Cinelerra for Linux"));
279 quicktime_set_info(fd, "Quicktime for Linux");
281 if(asset->audio_data)
283 quicktime_atracks = quicktime_set_audio(fd,
288 quicktime_set_parameter(fd, "vorbis_vbr", &asset->vorbis_vbr);
289 quicktime_set_parameter(fd, "vorbis_min_bitrate", &asset->vorbis_min_bitrate);
290 quicktime_set_parameter(fd, "vorbis_bitrate", &asset->vorbis_bitrate);
291 quicktime_set_parameter(fd, "vorbis_max_bitrate", &asset->vorbis_max_bitrate);
292 quicktime_set_parameter(fd, "mp3_bitrate", &asset->mp3_bitrate);
293 quicktime_set_parameter(fd, "mp4a_bitrate", &asset->mp4a_bitrate);
296 if(asset->video_data)
299 // Set up the alpha channel compressors
300 if(!strcmp(asset->vcodec, MOV_RGBA))
302 strcpy(string, QUICKTIME_RAW);
306 if(!strcmp(asset->vcodec, MOV_PNGA))
308 strcpy(string, QUICKTIME_PNG);
312 if(!strcmp(asset->vcodec, QUICKTIME_YUVA4444))
314 strcpy(string, asset->vcodec);
319 strcpy(string, asset->vcodec);
324 quicktime_vtracks = quicktime_set_video(fd,
333 for(int i = 0; i < asset->layers; i++)
334 quicktime_set_depth(fd, depth, i);
336 quicktime_set_parameter(fd, "jpeg_quality", &asset->jpeg_quality);
338 // set the compression parameters if there are any
339 quicktime_set_parameter(fd, "divx_bitrate", &asset->divx_bitrate);
340 quicktime_set_parameter(fd, "divx_rc_period", &asset->divx_rc_period);
341 quicktime_set_parameter(fd, "divx_rc_reaction_ratio", &asset->divx_rc_reaction_ratio);
342 quicktime_set_parameter(fd, "divx_rc_reaction_period", &asset->divx_rc_reaction_period);
343 quicktime_set_parameter(fd, "divx_max_key_interval", &asset->divx_max_key_interval);
344 quicktime_set_parameter(fd, "divx_max_quantizer", &asset->divx_max_quantizer);
345 quicktime_set_parameter(fd, "divx_min_quantizer", &asset->divx_min_quantizer);
346 quicktime_set_parameter(fd, "divx_quantizer", &asset->divx_quantizer);
347 quicktime_set_parameter(fd, "divx_quality", &asset->divx_quality);
348 quicktime_set_parameter(fd, "divx_fix_bitrate", &asset->divx_fix_bitrate);
350 quicktime_set_parameter(fd, "ffmpeg_bitrate", &asset->ms_bitrate);
351 quicktime_set_parameter(fd, "ffmpeg_bitrate_tolerance", &asset->ms_bitrate_tolerance);
352 quicktime_set_parameter(fd, "ffmpeg_interlaced", &asset->ms_interlaced);
353 quicktime_set_parameter(fd, "ffmpeg_quantizer", &asset->ms_quantization);
354 quicktime_set_parameter(fd, "ffmpeg_gop_size", &asset->ms_gop_size);
355 quicktime_set_parameter(fd, "ffmpeg_fix_bitrate", &asset->ms_fix_bitrate);
357 quicktime_set_parameter(fd, "h264_bitrate", &asset->h264_bitrate);
358 quicktime_set_parameter(fd, "h264_quantizer", &asset->h264_quantizer);
359 quicktime_set_parameter(fd, "h264_fix_bitrate", &asset->h264_fix_bitrate);
364 if(wr && asset->format == FILE_AVI)
366 quicktime_set_avi(fd, 1);
371 void FileMOV::format_to_asset()
375 if(quicktime_is_avi(fd)) asset->format = FILE_AVI;
376 asset->audio_data = quicktime_has_audio(fd);
377 if(asset->audio_data)
380 int qt_tracks = quicktime_audio_tracks(fd);
381 for(int i = 0; i < qt_tracks; i++)
382 asset->channels += quicktime_track_channels(fd, i);
384 if(!asset->sample_rate)
385 asset->sample_rate = quicktime_sample_rate(fd, 0);
386 asset->bits = quicktime_audio_bits(fd, 0);
387 asset->audio_length = quicktime_audio_length(fd, 0);
388 strncpy(asset->acodec, quicktime_audio_compressor(fd, 0), 4);
391 // determine if the video can be read before declaring video data
392 if(quicktime_has_video(fd) && quicktime_supported_video(fd, 0))
393 asset->video_data = 1;
395 if(asset->video_data)
397 depth = quicktime_video_depth(fd, 0);
398 asset->layers = quicktime_video_tracks(fd);
399 asset->width = quicktime_video_width(fd, 0);
400 asset->height = quicktime_video_height(fd, 0);
401 asset->video_length = quicktime_video_length(fd, 0);
402 // Don't want a user configured frame rate to get destroyed
403 if(!asset->frame_rate)
404 asset->frame_rate = quicktime_frame_rate(fd, 0);
405 if(!asset->interlace_mode)
406 asset->interlace_mode = quicktime_video_interlacemode(fd, 0);
408 strncpy(asset->vcodec, quicktime_video_compressor(fd, 0), 4);
410 // If DV stream, get the timecode
411 // This should become part of libquicktime functionality... for all formats
412 if(match4(asset->vcodec, QUICKTIME_DV))
415 dv_decoder_t *tmp_decoder = dv_decoder_new(0,0,0);
416 VFrame *frame = new VFrame(0, 0, 0, BC_COMPRESSED);
419 set_video_position(0);
421 if(dv_parse_header(tmp_decoder, frame->get_data()) > -1)
423 dv_parse_packs(tmp_decoder, frame->get_data());
424 dv_get_timestamp(tmp_decoder, tc);
425 // printf("Timestamp %s\n", tc);
427 float seconds = Units::text_to_seconds(tc,
428 1, // Use 1 as sample rate, doesn't matter
432 // Set tcstart if it hasn't been set yet, this is a bit problematic
433 // FIXME: The problem arises if file has nonzero tcstart and user manualy sets it to zero - every time project will load it will be set to nonzero
434 if (asset->tcstart == 0)
435 asset->tcstart = int64_t(seconds * asset->frame_rate);
438 dv_decoder_free(tmp_decoder);
446 int64_t FileMOV::get_memory_usage()
450 int64_t result = quicktime_memory_usage(fd);
451 //printf("FileMOV::get_memory_usage 1 %d\n", result);
457 int FileMOV::colormodel_supported(int colormodel)
462 int FileMOV::get_best_colormodel(Asset *asset, int driver)
469 case PLAYBACK_X11_XV:
470 case PLAYBACK_ASYNCHRONOUS:
471 if(match4(asset->vcodec, QUICKTIME_YUV420)) return BC_YUV420P;
472 if(match4(asset->vcodec, QUICKTIME_YUV422)) return BC_YUV422;
473 if(match4(asset->vcodec, QUICKTIME_2VUY)) return BC_YUV422;
474 if(match4(asset->vcodec, QUICKTIME_JPEG)) return BC_YUV420P;
475 if(match4(asset->vcodec, QUICKTIME_MJPA)) return BC_YUV422P;
476 if(match4(asset->vcodec, QUICKTIME_DV)) return BC_YUV422;
477 if(match4(asset->vcodec, QUICKTIME_DVSD)) return BC_YUV422;
478 if(match4(asset->vcodec, QUICKTIME_HV60)) return BC_YUV420P;
479 if(match4(asset->vcodec, QUICKTIME_DIVX)) return BC_YUV420P;
480 if(match4(asset->vcodec, QUICKTIME_DVCP)) return BC_YUV422;
481 if(match4(asset->vcodec, QUICKTIME_DVSD)) return BC_YUV422;
482 if(match4(asset->vcodec, QUICKTIME_MP4V)) return BC_YUV420P;
483 if(match4(asset->vcodec, QUICKTIME_H263)) return BC_YUV420P;
484 if(match4(asset->vcodec, QUICKTIME_H264)) return BC_YUV420P;
485 if(match4(asset->vcodec, QUICKTIME_HV64)) return BC_YUV420P;
486 if(match4(asset->vcodec, QUICKTIME_DIV3) ||
487 match4(asset->vcodec, QUICKTIME_SVQ3)) return BC_YUV420P;
489 case PLAYBACK_X11_GL:
490 if(match4(asset->vcodec, QUICKTIME_YUV420) ||
491 match4(asset->vcodec, QUICKTIME_YUV422) ||
492 match4(asset->vcodec, QUICKTIME_2VUY) ||
493 match4(asset->vcodec, QUICKTIME_JPEG) ||
494 match4(asset->vcodec, QUICKTIME_MJPA) ||
495 match4(asset->vcodec, QUICKTIME_DV) ||
496 match4(asset->vcodec, QUICKTIME_DVCP) ||
497 match4(asset->vcodec, QUICKTIME_DVSD) ||
498 match4(asset->vcodec, QUICKTIME_HV60) ||
499 match4(asset->vcodec, QUICKTIME_DIVX) ||
500 match4(asset->vcodec, QUICKTIME_DVSD) ||
501 match4(asset->vcodec, QUICKTIME_MP4V) ||
502 match4(asset->vcodec, QUICKTIME_H263) ||
503 match4(asset->vcodec, QUICKTIME_H264) ||
504 match4(asset->vcodec, QUICKTIME_HV64) ||
505 match4(asset->vcodec, QUICKTIME_DIV3) ||
506 match4(asset->vcodec, QUICKTIME_DVSD)) return BC_YUV888;
508 case PLAYBACK_DV1394:
509 case PLAYBACK_FIREWIRE:
510 if(match4(asset->vcodec, QUICKTIME_DV) ||
511 match4(asset->vcodec, QUICKTIME_DVSD) ||
512 match4(asset->vcodec, QUICKTIME_DVCP)) return BC_COMPRESSED;
517 if(match4(asset->vcodec, QUICKTIME_MJPA))
518 return BC_COMPRESSED;
524 if(!strncasecmp(asset->vcodec, QUICKTIME_YUV420, 4)) return BC_YUV422;
526 if(!strncasecmp(asset->vcodec, QUICKTIME_YUV422, 4)) return BC_YUV422;
528 if(!strncasecmp(asset->vcodec, QUICKTIME_YUV411, 4)) return BC_YUV411P;
530 if(!strncasecmp(asset->vcodec, QUICKTIME_JPEG, 4)) return BC_YUV420P;
532 if(!strncasecmp(asset->vcodec, QUICKTIME_MJPA, 4)) return BC_YUV422P;
534 if(!strncasecmp(asset->vcodec, QUICKTIME_HV60, 4)) return BC_YUV420P;
536 if(!strncasecmp(asset->vcodec, QUICKTIME_DIVX, 4)) return BC_YUV420P;
538 if(!strncasecmp(asset->vcodec, QUICKTIME_H263, 4)) return BC_YUV420P;
540 if(!strncasecmp(asset->vcodec, QUICKTIME_DIV3, 4)) return BC_YUV420P;
544 case VIDEO4LINUX2JPEG:
545 if(!strncasecmp(asset->vcodec, QUICKTIME_MJPA, 4))
546 return BC_COMPRESSED;
550 case CAPTURE_FIREWIRE:
551 case CAPTURE_IEC61883:
552 if(!strncasecmp(asset->vcodec, QUICKTIME_DV, 4) ||
553 !strncasecmp(asset->vcodec, QUICKTIME_DVSD, 4) ||
554 !strncasecmp(asset->vcodec, QUICKTIME_DVCP, 4))
555 return BC_COMPRESSED;
563 int FileMOV::can_copy_from(Edit *edit, int64_t position)
567 //printf("FileMOV::can_copy_from 1 %d %s %s\n", edit->asset->format, edit->asset->vcodec, this->asset->vcodec);
568 if(edit->asset->format == FILE_JPEG_LIST &&
569 match4(this->asset->vcodec, QUICKTIME_JPEG))
572 if((edit->asset->format == FILE_MOV ||
573 edit->asset->format == FILE_AVI))
575 //printf("FileMOV::can_copy_from %s %s\n", edit->asset->vcodec, this->asset->vcodec);
576 if(match4(edit->asset->vcodec, this->asset->vcodec))
578 // there are combinations where the same codec has multiple fourcc codes
582 if (match4(edit->asset->vcodec, QUICKTIME_DV) ||
583 match4(edit->asset->vcodec, QUICKTIME_DVSD) ||
584 match4(edit->asset->vcodec, QUICKTIME_DVCP))
586 if (match4(this->asset->vcodec, QUICKTIME_DV) ||
587 match4(this->asset->vcodec, QUICKTIME_DVSD) ||
588 match4(this->asset->vcodec, QUICKTIME_DVCP))
590 if (is_this_dv && is_edit_dv)
594 if(edit->asset->format == FILE_RAWDV)
596 if(match4(this->asset->vcodec, QUICKTIME_DV) ||
597 match4(this->asset->vcodec, QUICKTIME_DVSD) ||
598 match4(this->asset->vcodec, QUICKTIME_DVCP))
607 int64_t FileMOV::get_audio_length()
610 int64_t result = quicktime_audio_length(fd, 0) + samples_correction;
615 int FileMOV::set_audio_position(int64_t x)
618 // quicktime sets positions for each track seperately so store position in audio_position
619 if(x >= 0 && x < asset->audio_length)
620 return quicktime_set_audio_position(fd, x, 0);
625 int FileMOV::set_video_position(int64_t x)
628 if(x >= 0 && x < asset->video_length)
630 int result = quicktime_set_video_position(fd, x, file->current_layer);
637 void FileMOV::new_audio_temp(int64_t len)
639 if(temp_allocated && temp_allocated < len)
641 for(int i = 0; i < asset->channels; i++)
642 delete [] temp_float[i];
643 delete [] temp_float;
649 temp_allocated = len;
650 temp_float = new float*[asset->channels];
651 for(int i = 0; i < asset->channels; i++)
652 temp_float[i] = new float[len];
658 int FileMOV::write_samples(double **buffer, int64_t len)
662 int result = 0, track_channels = 0;
667 if(quicktime_supported_audio(fd, 0))
669 // Use Quicktime's compressor. (Always used)
670 // Allocate temp buffer
673 // Copy to float buffer
674 for(i = 0; i < asset->channels; i++)
676 for(j = 0; j < len; j++)
678 temp_float[i][j] = buffer[i][j];
682 // Because of the way Quicktime's compressors work we want to limit the chunk
683 // size to speed up decompression.
685 channel_ptr = new float*[asset->channels];
687 for(j = 0; j < len && !result; )
689 chunk_size = asset->sample_rate;
690 if(j + chunk_size > len) chunk_size = len - j;
692 for(i = 0; i < asset->channels; i++)
694 channel_ptr[i] = &temp_float[i][j];
697 result = quicktime_encode_audio(fd, 0, channel_ptr, chunk_size);
698 j += asset->sample_rate;
701 delete [] channel_ptr;
706 int FileMOV::write_frames(VFrame ***frames, int len)
708 //printf("FileMOV::write_frames 1\n");
709 int i, j, k, result = 0;
710 int default_compressor = 1;
713 for(i = 0; i < asset->layers && !result; i++)
720 // Fix direct copy cases for format conversions.
721 if(frames[i][0]->get_color_model() == BC_COMPRESSED)
723 default_compressor = 0;
724 for(j = 0; j < len && !result; j++)
726 VFrame *frame = frames[i][j];
730 // Special handling for DIVX
731 // Determine keyframe status.
732 // Write VOL header in the first frame if none exists
733 if(!strcmp(asset->vcodec, QUICKTIME_DIVX) ||
734 !strcmp(asset->vcodec, QUICKTIME_H263) ||
735 !strcmp(asset->vcodec, QUICKTIME_HV60))
737 if(quicktime_mpeg4_is_key(frame->get_data(),
738 frame->get_compressed_size(),
740 quicktime_insert_keyframe(fd, file->current_frame + j, i);
744 if(!(file->current_frame + j) &&
745 !quicktime_mpeg4_has_vol(frame->get_data()))
747 VFrame *temp_frame = new VFrame;
749 temp_frame->allocate_compressed_data(frame->get_compressed_size() +
751 int bytes = quicktime_mpeg4_write_vol(temp_frame->get_data(),
756 memcpy(temp_frame->get_data() + bytes,
758 frame->get_compressed_size());
759 temp_frame->set_compressed_size(frame->get_compressed_size() + bytes);
761 result = quicktime_write_frame(fd,
762 temp_frame->get_data(),
763 temp_frame->get_compressed_size(),
772 result = quicktime_write_frame(fd,
774 frame->get_compressed_size(),
779 // Determine keyframe status
780 if(!strcmp(asset->vcodec, QUICKTIME_H264) ||
781 !strcmp(asset->vcodec, QUICKTIME_HV64) ||
782 !strcmp(asset->vcodec, QUICKTIME_MP4V))
784 if(frame->get_keyframe() || file->current_frame + j == 0)
785 quicktime_insert_keyframe(fd, file->current_frame + j, i);
788 result = quicktime_write_frame(fd,
790 frame->get_compressed_size(),
794 if(!strcmp(asset->vcodec, QUICKTIME_DIV3))
796 if(quicktime_mpeg4_is_key(frame->get_data(),
797 frame->get_compressed_size(),
799 quicktime_insert_keyframe(fd, file->current_frame + j, i);
800 result = quicktime_write_frame(fd,
802 frame->get_compressed_size(),
806 if(!strcmp(asset->vcodec, QUICKTIME_MJPA))
810 // Create extra space for markers
811 if(frame->get_compressed_allocated() - frame->get_compressed_size() < 0x100)
812 frame->allocate_compressed_data(frame->get_compressed_size() + 0x100);
814 unsigned char *data = frame->get_data();
815 long data_size = frame->get_compressed_size();
816 long data_allocated = frame->get_compressed_allocated();
818 // Sometimes get 0 length frames
821 if(asset->format == FILE_MOV)
823 mjpeg_insert_quicktime_markers(&data,
831 mjpeg_insert_avi_markers(&data,
837 frame->set_compressed_size(data_size);
838 result = quicktime_write_frame(fd,
840 frame->get_compressed_size(),
845 eprintf("data_size=%d\n", data_size);
849 result = quicktime_write_frame(fd,
851 frame->get_compressed_size(),
858 if(match4(asset->vcodec, QUICKTIME_YUV420) ||
859 match4(asset->vcodec, QUICKTIME_2VUY) ||
860 match4(asset->vcodec, QUICKTIME_YUV422) ||
861 match4(asset->vcodec, QUICKTIME_RAW))
863 // Direct copy planes where possible
864 default_compressor = 0;
865 for(j = 0; j < len && !result; j++)
867 VFrame *frame = frames[i][j];
868 //printf("FileMOV::write_frames 1 %d\n", frame->get_color_model());
869 quicktime_set_cmodel(fd, frame->get_color_model());
870 if(cmodel_is_planar(frame->get_color_model()))
872 unsigned char *planes[3];
873 planes[0] = frame->get_y();
874 planes[1] = frame->get_u();
875 planes[2] = frame->get_v();
876 result = quicktime_encode_video(fd, planes, i);
880 result = quicktime_encode_video(fd, frame->get_rows(), i);
881 //printf("FileMOV::write_frames 2 %d\n", result);
883 //printf("FileMOV::write_frames 2\n");
888 (match4(asset->vcodec, QUICKTIME_JPEG) ||
889 match4(asset->vcodec, QUICKTIME_MJPA)))
891 default_compressor = 0;
892 // Compress symmetrically on an SMP system.
893 ThreadStruct *threadframe;
894 int fields = match4(asset->vcodec, QUICKTIME_MJPA) ? 2 : 1;
896 // Set up threads for symmetric compression.
899 threads = new FileMOVThread*[file->cpus];
900 for(j = 0; j < file->cpus; j++)
902 threads[j] = new FileMOVThread(this, fields);
903 threads[j]->start_encoding();
907 // Set up the frame structures for asynchronous compression.
908 // The mjpeg object must exist in each threadframe because it is where the output
910 while(threadframes.total < len)
912 threadframes.append(threadframe = new ThreadStruct);
915 // Load thread frame structures with new frames.
916 for(j = 0; j < len; j++)
918 VFrame *frame = frames[i][j];
919 threadframes.values[j]->input = frame;
920 threadframes.values[j]->completion_lock->lock("FileMOV::write_frames 1");
922 total_threadframes = len;
923 current_threadframe = 0;
925 // Start the threads compressing
926 for(j = 0; j < file->cpus; j++)
928 threads[j]->encode_buffer();
932 // Write the frames as they're finished
933 for(j = 0; j < len; j++)
935 threadframes.values[j]->completion_lock->lock("FileMOV::write_frames 1");
936 threadframes.values[j]->completion_lock->unlock();
939 result = quicktime_write_frame(fd,
940 threadframes.values[j]->output,
941 threadframes.values[j]->output_size,
947 if(default_compressor)
949 //printf("FileMOV::write_frames 3\n");
950 // Use the library's built in compressor.
951 for(j = 0; j < len && !result; j++)
953 //printf("FileMOV::write_frames 4\n");
954 VFrame *frame = frames[i][j];
955 quicktime_set_cmodel(fd, frame->get_color_model());
956 //printf("FileMOV::write_frames 5\n");
957 if(cmodel_is_planar(frame->get_color_model()))
959 unsigned char *planes[3];
960 planes[0] = frame->get_y();
961 planes[1] = frame->get_u();
962 planes[2] = frame->get_v();
963 result = quicktime_encode_video(fd, planes, i);
967 result = quicktime_encode_video(fd, frame->get_rows(), i);
971 //printf("FileMOV::write_frames 4\n");
975 //printf("FileMOV::write_frames 100 %d\n", result);
981 int FileMOV::read_frame(VFrame *frame)
986 switch(frame->get_color_model())
989 frame->allocate_compressed_data(quicktime_frame_size(fd, file->current_frame, file->current_layer));
990 frame->set_compressed_size(quicktime_frame_size(fd, file->current_frame, file->current_layer));
991 frame->set_keyframe((quicktime_get_keyframe_before(fd,
993 file->current_layer) == file->current_frame));
994 //printf("FileMOV::read_frame 1 %lld %d\n", file->current_frame, frame->get_keyframe());
995 result = !quicktime_read_frame(fd,
997 file->current_layer);
1004 unsigned char *row_pointers[3];
1005 row_pointers[0] = frame->get_y();
1006 row_pointers[1] = frame->get_u();
1007 row_pointers[2] = frame->get_v();
1009 quicktime_set_cmodel(fd, frame->get_color_model());
1010 result = quicktime_decode_video(fd,
1012 file->current_layer);
1018 quicktime_set_cmodel(fd, frame->get_color_model());
1019 result = quicktime_decode_video(fd,
1021 file->current_layer);
1022 //for(int i = 0; i < 10000; i++) frame->get_rows()[0][i] = 0xff;
1027 eprintf("quicktime_read_frame/quicktime_decode_video failed, result:\n");
1037 int64_t FileMOV::compressed_frame_size()
1040 return quicktime_frame_size(fd, file->current_frame, file->current_layer);
1043 int FileMOV::read_compressed_frame(VFrame *buffer)
1048 result = quicktime_read_frame(fd, buffer->get_data(), file->current_layer);
1049 buffer->set_compressed_size(result);
1050 buffer->set_keyframe((quicktime_get_keyframe_before(fd,
1051 file->current_frame,
1052 file->current_layer) == file->current_frame));
1057 int FileMOV::write_compressed_frame(VFrame *buffer)
1062 result = quicktime_write_frame(fd,
1064 buffer->get_compressed_size(),
1065 file->current_layer);
1071 int FileMOV::read_raw(VFrame *frame,
1072 float in_x1, float in_y1, float in_x2, float in_y2,
1073 float out_x1, float out_y1, float out_x2, float out_y2,
1074 int use_float, int interpolate)
1076 int64_t i, color_channels, result = 0;
1079 quicktime_set_video_position(fd, file->current_frame, file->current_layer);
1080 // Develop importing strategy
1081 switch(frame->get_color_model())
1084 result = quicktime_decode_video(fd, frame->get_rows(), file->current_layer);
1090 case BC_RGBA16161616:
1098 case BC_YUVA16161616:
1107 int FileMOV::read_samples(double *buffer, int64_t len)
1109 int qt_track, qt_channel;
1113 if(quicktime_track_channels(fd, 0) > file->current_channel &&
1114 quicktime_supported_audio(fd, 0))
1117 //printf("FileMOV::read_samples 2 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
1118 new_audio_temp(len);
1120 //printf("FileMOV::read_samples 3 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
1121 if(quicktime_decode_audio(fd, 0, temp_float[0], len, file->current_channel))
1123 eprintf("quicktime_decode_audio failed\n");
1128 for(int i = 0; i < len; i++) buffer[i] = temp_float[0][i];
1131 // if(file->current_channel == 0)
1132 // for(int i = 0; i < len; i++)
1135 // value = (int16_t)(temp_float[0][i] * 32767);
1136 // fwrite(&value, 2, 1, stdout);
1138 //printf("FileMOV::read_samples 4 %ld %ld\n", file->current_sample, quicktime_audio_position(fd, 0));
1145 char* FileMOV::strtocompression(char *string)
1147 if(!strcasecmp(string, _(DIVX_NAME))) return QUICKTIME_DIVX;
1148 if(!strcasecmp(string, _(H264_NAME))) return QUICKTIME_H264;
1149 if(!strcasecmp(string, _(HV64_NAME))) return QUICKTIME_HV64;
1150 if(!strcasecmp(string, _(MP4V_NAME))) return QUICKTIME_MP4V;
1151 if(!strcasecmp(string, _(H263_NAME))) return QUICKTIME_H263;
1152 if(!strcasecmp(string, _(HV60_NAME))) return QUICKTIME_HV60;
1153 if(!strcasecmp(string, _(DIV3_NAME))) return QUICKTIME_DIV3;
1154 // Students say QUICKTIME_DV is required for compression even though
1155 // QUICKTIME_DVSD is produced by other software
1156 // if(!strcasecmp(string, _(DV_NAME))) return QUICKTIME_DVSD;
1157 if(!strcasecmp(string, _(DV_NAME))) return QUICKTIME_DV;
1158 if(!strcasecmp(string, _(PNG_NAME))) return QUICKTIME_PNG;
1159 if(!strcasecmp(string, _(PNGA_NAME))) return MOV_PNGA;
1160 if(!strcasecmp(string, _(RGB_NAME))) return QUICKTIME_RAW;
1161 if(!strcasecmp(string, _(RGBA_NAME))) return MOV_RGBA;
1162 if(!strcasecmp(string, _(QTJPEG_NAME))) return QUICKTIME_JPEG;
1163 if(!strcasecmp(string, _(MJPA_NAME))) return QUICKTIME_MJPA;
1164 if(!strcasecmp(string, _(YUV420_NAME))) return QUICKTIME_YUV420;
1165 if(!strcasecmp(string, _(YUV411_NAME))) return QUICKTIME_YUV411;
1166 if(!strcasecmp(string, _(YUV422_NAME))) return QUICKTIME_YUV422;
1167 if(!strcasecmp(string, _(TWOVUY_NAME))) return QUICKTIME_2VUY;
1168 if(!strcasecmp(string, _(YUV444_NAME))) return QUICKTIME_YUV444;
1169 if(!strcasecmp(string, _(YUVA4444_NAME))) return QUICKTIME_YUVA4444;
1170 if(!strcasecmp(string, _(YUV444_10BIT_NAME))) return QUICKTIME_YUV444_10bit;
1172 if(!strcasecmp(string, _(TWOS_NAME))) return QUICKTIME_TWOS;
1173 if(!strcasecmp(string, _(RAW_NAME))) return QUICKTIME_RAW;
1174 if(!strcasecmp(string, _(IMA4_NAME))) return QUICKTIME_IMA4;
1175 if(!strcasecmp(string, _(ULAW_NAME))) return QUICKTIME_ULAW;
1176 if(!strcasecmp(string, _(MP3_NAME))) return QUICKTIME_MP3;
1177 if(!strcasecmp(string, _(MP4A_NAME))) return QUICKTIME_MP4A;
1178 if(!strcasecmp(string, _(VORBIS_NAME))) return QUICKTIME_VORBIS;
1182 return QUICKTIME_RAW;
1185 char* FileMOV::compressiontostr(char *string)
1187 if(match4(string, QUICKTIME_H263)) return _(H263_NAME);
1188 if(match4(string, QUICKTIME_H264)) return _(H264_NAME);
1189 if(match4(string, QUICKTIME_HV64)) return _(HV64_NAME);
1190 if(match4(string, QUICKTIME_DIVX)) return _(DIVX_NAME);
1191 if(match4(string, QUICKTIME_MP4V)) return _(MP4V_NAME);
1192 if(match4(string, QUICKTIME_HV60)) return _(HV60_NAME);
1193 if(match4(string, QUICKTIME_DIV3)) return _(DIV3_NAME);
1194 if(match4(string, QUICKTIME_DV)) return _(DV_NAME);
1195 if(match4(string, QUICKTIME_DVCP)) return _(DV_NAME);
1196 if(match4(string, QUICKTIME_DVSD)) return _(DV_NAME);
1197 if(match4(string, MOV_PNGA)) return _(PNGA_NAME);
1198 if(match4(string, QUICKTIME_RAW)) return _(RGB_NAME);
1199 if(match4(string, MOV_RGBA)) return _(RGBA_NAME);
1200 if(match4(string, QUICKTIME_JPEG)) return _(QTJPEG_NAME);
1201 if(match4(string, QUICKTIME_MJPA)) return _(MJPA_NAME);
1202 if(match4(string, QUICKTIME_YUV420)) return _(YUV420_NAME);
1203 if(match4(string, QUICKTIME_YUV411)) return _(YUV411_NAME);
1204 if(match4(string, QUICKTIME_YUV422)) return _(YUV422_NAME);
1205 if(match4(string, QUICKTIME_2VUY)) return _(TWOVUY_NAME);
1206 if(match4(string, QUICKTIME_YUV444)) return _(YUV444_NAME);
1207 if(match4(string, QUICKTIME_YUVA4444)) return _(YUVA4444_NAME);
1208 if(match4(string, QUICKTIME_YUV444_10bit)) return _(YUV444_10BIT_NAME);
1214 if(match4(string, QUICKTIME_TWOS)) return _(TWOS_NAME);
1215 if(match4(string, QUICKTIME_RAW)) return _(RAW_NAME);
1216 if(match4(string, QUICKTIME_IMA4)) return _(IMA4_NAME);
1217 if(match4(string, QUICKTIME_ULAW)) return _(ULAW_NAME);
1218 if(match4(string, QUICKTIME_MP3)) return _(MP3_NAME);
1219 if(match4(string, QUICKTIME_MP4A)) return _(MP4A_NAME);
1220 if(match4(string, QUICKTIME_VORBIS)) return _(VORBIS_NAME);
1224 return _("Unknown");
1231 ThreadStruct::ThreadStruct()
1235 output_allocated = 0;
1237 completion_lock = new Condition(1, "ThreadStruct::completion_lock");
1240 ThreadStruct::~ThreadStruct()
1242 if(output) delete [] output;
1243 delete completion_lock;
1246 void ThreadStruct::load_output(mjpeg_t *mjpeg)
1248 if(output_allocated < mjpeg_output_size(mjpeg))
1255 output_allocated = mjpeg_output_size(mjpeg);
1256 output = new unsigned char[output_allocated];
1259 output_size = mjpeg_output_size(mjpeg);
1260 memcpy(output, mjpeg_output_buffer(mjpeg), output_size);
1264 FileMOVThread::FileMOVThread(FileMOV *filemov, int fields) : Thread()
1266 this->filemov = filemov;
1267 this->fields = fields;
1269 input_lock = new Condition(1, "FileMOVThread::input_lock");
1272 FileMOVThread::~FileMOVThread()
1277 int FileMOVThread::start_encoding()
1279 mjpeg = mjpeg_new(filemov->asset->width,
1280 filemov->asset->height,
1282 mjpeg_set_quality(mjpeg, filemov->asset->jpeg_quality);
1283 mjpeg_set_float(mjpeg, 0);
1286 input_lock->lock("FileMOVThread::start_encoding");
1290 int FileMOVThread::stop_encoding()
1293 input_lock->unlock();
1295 if(mjpeg) mjpeg_delete(mjpeg);
1298 int FileMOVThread::encode_buffer()
1300 input_lock->unlock();
1303 void FileMOVThread::run()
1307 input_lock->lock("FileMOVThread::run");
1311 // Get a frame to compress.
1312 filemov->threadframe_lock->lock("FileMOVThread::stop_encoding");
1313 if(filemov->current_threadframe < filemov->total_threadframes)
1315 // Frame is available to process.
1316 input_lock->unlock();
1317 threadframe = filemov->threadframes.values[filemov->current_threadframe];
1318 VFrame *frame = threadframe->input;
1320 filemov->current_threadframe++;
1321 filemov->threadframe_lock->unlock();
1323 mjpeg_compress(mjpeg,
1328 frame->get_color_model(),
1333 unsigned char *data = mjpeg_output_buffer(mjpeg);
1334 long data_size = mjpeg_output_size(mjpeg);
1335 long data_allocated = mjpeg_output_allocated(mjpeg);
1338 if(filemov->asset->format == FILE_MOV)
1340 mjpeg_insert_quicktime_markers(&data,
1348 mjpeg_insert_avi_markers(&data,
1354 mjpeg_set_output_size(mjpeg, data_size);
1356 threadframe->load_output(mjpeg);
1357 threadframe->completion_lock->unlock();
1360 filemov->threadframe_lock->unlock();
1370 MOVConfigAudio::MOVConfigAudio(BC_WindowBase *parent_window, Asset *asset)
1371 : BC_Window(PROGRAM_NAME ": Audio Compression",
1372 parent_window->get_abs_cursor_x(1),
1373 parent_window->get_abs_cursor_y(1),
1377 this->parent_window = parent_window;
1378 this->asset = asset;
1379 compression_popup = 0;
1383 MOVConfigAudio::~MOVConfigAudio()
1385 if(compression_popup) delete compression_popup;
1386 if(bits_popup) delete bits_popup;
1387 compression_items.remove_all_objects();
1391 void MOVConfigAudio::reset()
1396 vorbis_min_bitrate = 0;
1398 vorbis_max_bitrate = 0;
1405 int MOVConfigAudio::create_objects()
1410 if(asset->format == FILE_MOV)
1412 compression_items.append(new BC_ListBoxItem(_(TWOS_NAME)));
1413 compression_items.append(new BC_ListBoxItem(_(RAW_NAME)));
1414 compression_items.append(new BC_ListBoxItem(_(IMA4_NAME)));
1415 compression_items.append(new BC_ListBoxItem(_(MP3_NAME)));
1416 compression_items.append(new BC_ListBoxItem(_(ULAW_NAME)));
1417 compression_items.append(new BC_ListBoxItem(_(VORBIS_NAME)));
1418 compression_items.append(new BC_ListBoxItem(_(MP4A_NAME)));
1422 compression_items.append(new BC_ListBoxItem(_(TWOS_NAME)));
1423 compression_items.append(new BC_ListBoxItem(_(MP3_NAME)));
1424 compression_items.append(new BC_ListBoxItem(_(VORBIS_NAME)));
1425 compression_items.append(new BC_ListBoxItem(_(MP4A_NAME)));
1428 add_tool(new BC_Title(x, y, _("Compression:")));
1430 compression_popup = new MOVConfigAudioPopup(this, x, y);
1431 compression_popup->create_objects();
1433 update_parameters();
1435 add_subwindow(new BC_OKButton(this));
1439 void MOVConfigAudio::update_parameters()
1442 if(bits_title) delete bits_title;
1443 if(bits_popup) delete bits_popup;
1444 if(dither) delete dither;
1445 if(vorbis_min_bitrate) delete vorbis_min_bitrate;
1446 if(vorbis_bitrate) delete vorbis_bitrate;
1447 if(vorbis_max_bitrate) delete vorbis_max_bitrate;
1448 if(vorbis_vbr) delete vorbis_vbr;
1449 if(mp3_bitrate) delete mp3_bitrate;
1450 delete mp4a_bitrate;
1451 delete mp4a_quantqual;
1457 if(!strcasecmp(asset->acodec, QUICKTIME_TWOS) ||
1458 !strcasecmp(asset->acodec, QUICKTIME_RAW))
1460 add_subwindow(bits_title = new BC_Title(x, y, _("Bits per channel:")));
1461 bits_popup = new BitsPopup(this,
1470 bits_popup->create_objects();
1472 add_subwindow(dither = new BC_CheckBox(x, y, &asset->dither, _("Dither")));
1475 if(!strcasecmp(asset->acodec, QUICKTIME_IMA4))
1479 if(!strcasecmp(asset->acodec, QUICKTIME_MP3))
1481 mp3_bitrate = new MOVConfigAudioNum(this,
1485 &asset->mp3_bitrate);
1486 mp3_bitrate->set_increment(1000);
1487 mp3_bitrate->create_objects();
1490 if(!strcasecmp(asset->acodec, QUICKTIME_ULAW))
1494 if(!strcasecmp(asset->acodec, QUICKTIME_VORBIS))
1496 add_subwindow(vorbis_vbr = new MOVConfigAudioToggle(this,
1497 _("Variable bitrate"),
1500 &asset->vorbis_vbr));
1502 vorbis_min_bitrate = new MOVConfigAudioNum(this,
1506 &asset->vorbis_min_bitrate);
1507 vorbis_min_bitrate->set_increment(1000);
1509 vorbis_bitrate = new MOVConfigAudioNum(this,
1513 &asset->vorbis_bitrate);
1514 vorbis_bitrate->set_increment(1000);
1516 vorbis_max_bitrate = new MOVConfigAudioNum(this,
1520 &asset->vorbis_max_bitrate);
1521 vorbis_max_bitrate->set_increment(1000);
1525 vorbis_min_bitrate->create_objects();
1526 vorbis_bitrate->create_objects();
1527 vorbis_max_bitrate->create_objects();
1530 if(!strcasecmp(asset->acodec, QUICKTIME_MP4A))
1532 mp4a_bitrate = new MOVConfigAudioNum(this,
1536 &asset->mp4a_bitrate);
1537 mp4a_bitrate->set_increment(1000);
1538 mp4a_bitrate->create_objects();
1541 mp4a_quantqual = new MOVConfigAudioNum(this,
1542 _("Quantization Quality (%):"),
1545 &asset->mp4a_quantqual);
1546 mp4a_quantqual->set_increment(1);
1547 mp4a_quantqual->create_objects();
1551 int MOVConfigAudio::close_event()
1561 MOVConfigAudioToggle::MOVConfigAudioToggle(MOVConfigAudio *popup,
1566 : BC_CheckBox(x, y, *output, title_text)
1568 this->popup = popup;
1569 this->output = output;
1571 int MOVConfigAudioToggle::handle_event()
1573 *output = get_value();
1581 MOVConfigAudioNum::MOVConfigAudioNum(MOVConfigAudio *popup, char *title_text, int x, int y, int *output)
1582 : BC_TumbleTextBox(popup,
1586 popup->get_w() - 150,
1590 this->popup = popup;
1591 this->title_text = title_text;
1592 this->output = output;
1597 MOVConfigAudioNum::~MOVConfigAudioNum()
1599 if(!popup->get_deleting()) delete title;
1602 void MOVConfigAudioNum::create_objects()
1604 popup->add_subwindow(title = new BC_Title(x, y, title_text));
1605 BC_TumbleTextBox::create_objects();
1608 int MOVConfigAudioNum::handle_event()
1610 *output = atol(get_text());
1621 MOVConfigAudioPopup::MOVConfigAudioPopup(MOVConfigAudio *popup, int x, int y)
1622 : BC_PopupTextBox(popup,
1623 &popup->compression_items,
1624 FileMOV::compressiontostr(popup->asset->acodec),
1630 this->popup = popup;
1633 int MOVConfigAudioPopup::handle_event()
1635 strcpy(popup->asset->acodec, FileMOV::strtocompression(get_text()));
1636 popup->update_parameters();
1656 MOVConfigVideo::MOVConfigVideo(BC_WindowBase *parent_window,
1658 char *locked_compressor)
1659 : BC_Window(PROGRAM_NAME ": Video Compression",
1660 parent_window->get_abs_cursor_x(1),
1661 parent_window->get_abs_cursor_y(1),
1665 this->parent_window = parent_window;
1666 this->asset = asset;
1667 this->locked_compressor = locked_compressor;
1668 compression_popup = 0;
1673 MOVConfigVideo::~MOVConfigVideo()
1675 if(compression_popup) delete compression_popup;
1676 compression_items.remove_all_objects();
1679 int MOVConfigVideo::create_objects()
1683 if(asset->format == FILE_MOV)
1685 compression_items.append(new BC_ListBoxItem(_(H264_NAME)));
1686 compression_items.append(new BC_ListBoxItem(_(HV64_NAME)));
1687 // compression_items.append(new BC_ListBoxItem(_(DIVX_NAME)));
1688 compression_items.append(new BC_ListBoxItem(_(MP4V_NAME)));
1689 compression_items.append(new BC_ListBoxItem(_(HV60_NAME)));
1690 compression_items.append(new BC_ListBoxItem(_(DIV3_NAME)));
1691 compression_items.append(new BC_ListBoxItem(_(DV_NAME)));
1692 compression_items.append(new BC_ListBoxItem(_(QTJPEG_NAME)));
1693 compression_items.append(new BC_ListBoxItem(_(MJPA_NAME)));
1694 compression_items.append(new BC_ListBoxItem(_(PNG_NAME)));
1695 compression_items.append(new BC_ListBoxItem(_(PNGA_NAME)));
1696 compression_items.append(new BC_ListBoxItem(_(RGB_NAME)));
1697 compression_items.append(new BC_ListBoxItem(_(RGBA_NAME)));
1698 compression_items.append(new BC_ListBoxItem(_(YUV420_NAME)));
1699 compression_items.append(new BC_ListBoxItem(_(YUV422_NAME)));
1700 compression_items.append(new BC_ListBoxItem(_(TWOVUY_NAME)));
1701 compression_items.append(new BC_ListBoxItem(_(YUV444_NAME)));
1702 compression_items.append(new BC_ListBoxItem(_(YUVA4444_NAME)));
1703 compression_items.append(new BC_ListBoxItem(_(YUV444_10BIT_NAME)));
1707 compression_items.append(new BC_ListBoxItem(_(H264_NAME)));
1708 compression_items.append(new BC_ListBoxItem(_(HV64_NAME)));
1709 // compression_items.append(new BC_ListBoxItem(_(DIVX_NAME)));
1710 compression_items.append(new BC_ListBoxItem(_(MP4V_NAME)));
1711 compression_items.append(new BC_ListBoxItem(_(HV60_NAME)));
1712 compression_items.append(new BC_ListBoxItem(_(DIV3_NAME)));
1713 compression_items.append(new BC_ListBoxItem(_(DV_NAME)));
1714 compression_items.append(new BC_ListBoxItem(_(QTJPEG_NAME)));
1715 compression_items.append(new BC_ListBoxItem(_(MJPA_NAME)));
1716 compression_items.append(new BC_ListBoxItem(_(PNG_NAME)));
1719 add_subwindow(new BC_Title(x, y, _("Compression:")));
1722 if(!locked_compressor)
1724 compression_popup = new MOVConfigVideoPopup(this, x, y);
1725 compression_popup->create_objects();
1729 add_subwindow(new BC_Title(x,
1731 FileMOV::compressiontostr(locked_compressor),
1740 update_parameters();
1742 add_subwindow(new BC_OKButton(this));
1746 int MOVConfigVideo::close_event()
1753 void MOVConfigVideo::reset()
1756 jpeg_quality_title = 0;
1760 divx_rc_reaction_ratio = 0;
1761 divx_rc_reaction_period = 0;
1762 divx_max_key_interval = 0;
1763 divx_max_quantizer = 0;
1764 divx_min_quantizer = 0;
1767 divx_fix_bitrate = 0;
1772 h264_fix_bitrate = 0;
1776 ms_bitrate_tolerance = 0;
1777 ms_quantization = 0;
1784 void MOVConfigVideo::update_parameters()
1788 delete jpeg_quality_title;
1789 delete jpeg_quality;
1792 if(divx_bitrate) delete divx_bitrate;
1793 if(divx_rc_period) delete divx_rc_period;
1794 if(divx_rc_reaction_ratio) delete divx_rc_reaction_ratio;
1795 if(divx_rc_reaction_period) delete divx_rc_reaction_period;
1796 if(divx_max_key_interval) delete divx_max_key_interval;
1797 if(divx_max_quantizer) delete divx_max_quantizer;
1798 if(divx_min_quantizer) delete divx_min_quantizer;
1799 if(divx_quantizer) delete divx_quantizer;
1800 if(divx_quality) delete divx_quality;
1801 if(divx_fix_quant) delete divx_fix_quant;
1802 if(divx_fix_bitrate) delete divx_fix_bitrate;
1804 if(ms_bitrate) delete ms_bitrate;
1805 if(ms_bitrate_tolerance) delete ms_bitrate_tolerance;
1806 if(ms_interlaced) delete ms_interlaced;
1807 if(ms_quantization) delete ms_quantization;
1808 if(ms_gop_size) delete ms_gop_size;
1809 if(ms_fix_bitrate) delete ms_fix_bitrate;
1810 if(ms_fix_quant) delete ms_fix_quant;
1812 delete h264_bitrate;
1813 delete h264_quantizer;
1814 delete h264_fix_bitrate;
1815 delete h264_fix_quant;
1820 char *vcodec = asset->vcodec;
1821 if(locked_compressor) vcodec = locked_compressor;
1825 if(!strcmp(vcodec, QUICKTIME_H264) ||
1826 !strcmp(vcodec, QUICKTIME_HV64))
1828 int x = param_x, y = param_y;
1829 h264_bitrate = new MOVConfigVideoNum(this,
1833 &asset->h264_bitrate);
1834 h264_bitrate->set_increment(1000000);
1835 h264_bitrate->create_objects();
1836 add_subwindow(h264_fix_bitrate = new MOVConfigVideoFixBitrate(x + 260,
1838 &asset->h264_fix_bitrate,
1841 h264_quantizer = new MOVConfigVideoNum(this,
1847 &asset->h264_quantizer);
1848 h264_quantizer->create_objects();
1849 add_subwindow(h264_fix_quant = new MOVConfigVideoFixQuant(x + 260,
1851 &asset->h264_fix_bitrate,
1853 h264_fix_bitrate->opposite = h264_fix_quant;
1854 h264_fix_quant->opposite = h264_fix_bitrate;
1857 // ffmpeg parameters
1858 if(!strcmp(vcodec, QUICKTIME_MP4V) ||
1859 !strcmp(vcodec, QUICKTIME_DIV3))
1861 int x = param_x, y = param_y;
1862 ms_bitrate = new MOVConfigVideoNum(this,
1866 &asset->ms_bitrate);
1867 ms_bitrate->set_increment(1000000);
1868 ms_bitrate->create_objects();
1869 add_subwindow(ms_fix_bitrate = new MOVConfigVideoFixBitrate(x + 260,
1871 &asset->ms_fix_bitrate,
1875 ms_bitrate_tolerance = new MOVConfigVideoNum(this,
1876 _("Bitrate tolerance:"),
1879 &asset->ms_bitrate_tolerance);
1880 ms_bitrate_tolerance->create_objects();
1882 ms_quantization = new MOVConfigVideoNum(this,
1886 &asset->ms_quantization);
1887 ms_quantization->create_objects();
1888 add_subwindow(ms_fix_quant = new MOVConfigVideoFixQuant(x + 260,
1890 &asset->ms_fix_bitrate,
1892 ms_fix_bitrate->opposite = ms_fix_quant;
1893 ms_fix_quant->opposite = ms_fix_bitrate;
1897 add_subwindow(ms_interlaced = new MOVConfigVideoCheckBox(_("Interlaced"),
1900 &asset->ms_interlaced));
1902 ms_gop_size = new MOVConfigVideoNum(this,
1903 _("Keyframe interval:"),
1906 &asset->ms_gop_size);
1907 ms_gop_size->create_objects();
1910 // OpenDivx parameters
1911 if(!strcmp(vcodec, QUICKTIME_DIVX) ||
1912 !strcmp(vcodec, QUICKTIME_H263) ||
1913 !strcmp(vcodec, QUICKTIME_HV60))
1915 int x = param_x, y = param_y;
1916 divx_bitrate = new MOVConfigVideoNum(this,
1920 &asset->divx_bitrate);
1921 divx_bitrate->set_increment(1000000);
1922 divx_bitrate->create_objects();
1923 add_subwindow(divx_fix_bitrate =
1924 new MOVConfigVideoFixBitrate(x + 260,
1926 &asset->divx_fix_bitrate,
1929 divx_quantizer = new MOVConfigVideoNum(this,
1933 &asset->divx_quantizer);
1934 divx_quantizer->create_objects();
1935 add_subwindow(divx_fix_quant =
1936 new MOVConfigVideoFixQuant(x + 260,
1938 &asset->divx_fix_bitrate,
1940 divx_fix_quant->opposite = divx_fix_bitrate;
1941 divx_fix_bitrate->opposite = divx_fix_quant;
1943 divx_rc_period = new MOVConfigVideoNum(this,
1947 &asset->divx_rc_period);
1948 divx_rc_period->create_objects();
1950 divx_rc_reaction_ratio = new MOVConfigVideoNum(this,
1951 _("Reaction Ratio:"),
1954 &asset->divx_rc_reaction_ratio);
1955 divx_rc_reaction_ratio->create_objects();
1957 divx_rc_reaction_period = new MOVConfigVideoNum(this,
1958 _("Reaction Period:"),
1961 &asset->divx_rc_reaction_period);
1962 divx_rc_reaction_period->create_objects();
1964 divx_max_key_interval = new MOVConfigVideoNum(this,
1965 _("Max Key Interval:"),
1968 &asset->divx_max_key_interval);
1969 divx_max_key_interval->create_objects();
1971 divx_max_quantizer = new MOVConfigVideoNum(this,
1972 _("Max Quantizer:"),
1975 &asset->divx_max_quantizer);
1976 divx_max_quantizer->create_objects();
1978 divx_min_quantizer = new MOVConfigVideoNum(this,
1979 _("Min Quantizer:"),
1982 &asset->divx_min_quantizer);
1983 divx_min_quantizer->create_objects();
1985 divx_quality = new MOVConfigVideoNum(this,
1989 &asset->divx_quality);
1990 divx_quality->create_objects();
1993 if(!strcmp(vcodec, QUICKTIME_JPEG) ||
1994 !strcmp(vcodec, QUICKTIME_MJPA))
1996 add_subwindow(jpeg_quality_title = new BC_Title(param_x, param_y, _("Quality:")));
1997 add_subwindow(jpeg_quality = new BC_ISlider(param_x + 80,
2004 asset->jpeg_quality,
2007 &asset->jpeg_quality));
2015 MOVConfigVideoNum::MOVConfigVideoNum(MOVConfigVideo *popup, char *title_text, int x, int y, int *output)
2016 : BC_TumbleTextBox(popup,
2024 this->popup = popup;
2025 this->title_text = title_text;
2026 this->output = output;
2031 MOVConfigVideoNum::MOVConfigVideoNum(MOVConfigVideo *popup,
2038 : BC_TumbleTextBox(popup,
2046 this->popup = popup;
2047 this->title_text = title_text;
2048 this->output = output;
2053 MOVConfigVideoNum::~MOVConfigVideoNum()
2055 if(!popup->get_deleting()) delete title;
2058 void MOVConfigVideoNum::create_objects()
2060 popup->add_subwindow(title = new BC_Title(x, y, title_text));
2061 BC_TumbleTextBox::create_objects();
2064 int MOVConfigVideoNum::handle_event()
2066 *output = atol(get_text());
2076 MOVConfigVideoCheckBox::MOVConfigVideoCheckBox(char *title_text, int x, int y, int *output)
2077 : BC_CheckBox(x, y, *output, title_text)
2079 this->output = output;
2082 int MOVConfigVideoCheckBox::handle_event()
2084 *output = get_value();
2093 MOVConfigVideoFixBitrate::MOVConfigVideoFixBitrate(int x,
2102 this->output = output;
2103 this->value = value;
2106 int MOVConfigVideoFixBitrate::handle_event()
2109 opposite->update(0);
2118 MOVConfigVideoFixQuant::MOVConfigVideoFixQuant(int x,
2125 _("Fix quantization"))
2127 this->output = output;
2128 this->value = value;
2131 int MOVConfigVideoFixQuant::handle_event()
2134 opposite->update(0);
2142 MOVConfigVideoPopup::MOVConfigVideoPopup(MOVConfigVideo *popup, int x, int y)
2143 : BC_PopupTextBox(popup,
2144 &popup->compression_items,
2145 FileMOV::compressiontostr(popup->asset->vcodec),
2151 this->popup = popup;
2154 int MOVConfigVideoPopup::handle_event()
2156 strcpy(popup->asset->vcodec, FileMOV::strtocompression(get_text()));
2157 popup->update_parameters();