9 #include "filesystem.h"
11 #include "quicktime.h"
12 #include "interlacemodes.h"
20 : ListItem<Asset>(), GarbageObject("Asset")
25 Asset::Asset(Asset &asset)
26 : ListItem<Asset>(), GarbageObject("Asset")
32 Asset::Asset(const char *path)
33 : ListItem<Asset>(), GarbageObject("Asset")
36 strcpy(this->path, path);
39 Asset::Asset(const int plugin_type, const char *plugin_title)
40 : ListItem<Asset>(), GarbageObject("Asset")
47 delete [] index_offsets;
48 delete [] index_sizes;
49 // Don't delete index buffer since it is shared with the index thread.
53 int Asset::init_values()
56 strcpy(folder, MEDIA_FOLDER);
58 // Has to be unknown for file probing to succeed
59 format = FILE_UNKNOWN;
76 strcpy(vcodec, QUICKTIME_YUV2);
77 strcpy(acodec, QUICKTIME_TWOS);
80 interlace_autofixoption = BC_ILACE_AUTOFIXOPTION_AUTO;
81 interlace_mode = BC_ILACE_MODE_UNDETECTED;
82 interlace_fixmethod = BC_ILACE_FIXMETHOD_NONE;
88 vorbis_min_bitrate = -1;
89 vorbis_bitrate = 128000;
90 vorbis_max_bitrate = -1;
92 theora_fix_bitrate = 1;
93 theora_bitrate = 860000;
96 theora_keyframe_frequency = 64;
97 theora_keyframe_force_frequency = 64;
102 mp4a_bitrate = 256000;
103 mp4a_quantqual = 100;
108 vmpeg_iframe_distance = 45;
109 vmpeg_pframe_distance = 0;
110 vmpeg_progressive = 0;
112 vmpeg_bitrate = 1000000;
113 vmpeg_derivative = 1;
114 vmpeg_quantization = 15;
116 vmpeg_fix_bitrate = 0;
119 vmpeg_field_order = 0;
121 // Divx parameters. BC_Hash from encore2
122 divx_bitrate = 2000000;
124 divx_rc_reaction_ratio = 45;
125 divx_rc_reaction_period = 10;
126 divx_max_key_interval = 250;
127 divx_max_quantizer = 31;
128 divx_min_quantizer = 1;
131 divx_fix_bitrate = 1;
132 divx_use_deblocking = 1;
134 h264_bitrate = 2000000;
136 h264_fix_bitrate = 0;
138 ms_bitrate = 1000000;
139 ms_bitrate_tolerance = 500000;
140 ms_quantization = 10;
152 tiff_compression = 0;
170 int Asset::reset_index()
172 index_status = INDEX_NOTTESTED;
173 index_start = old_index_end = index_end = 0;
182 int Asset::reset_timecode()
184 strcpy(reel_name, "cin0000");
193 void Asset::copy_from(Asset *asset, int do_index)
195 copy_location(asset);
196 copy_format(asset, do_index);
199 void Asset::copy_location(Asset *asset)
201 strcpy(this->path, asset->path);
202 strcpy(this->folder, asset->folder);
205 void Asset::copy_format(Asset *asset, int do_index)
207 if(do_index) update_index(asset);
209 audio_data = asset->audio_data;
210 format = asset->format;
211 channels = asset->channels;
212 sample_rate = asset->sample_rate;
214 byte_order = asset->byte_order;
215 signed_ = asset->signed_;
216 header = asset->header;
217 dither = asset->dither;
218 mp3_bitrate = asset->mp3_bitrate;
219 mp4a_bitrate = asset->mp4a_bitrate;
220 mp4a_quantqual = asset->mp4a_quantqual;
221 use_header = asset->use_header;
222 aspect_ratio = asset->aspect_ratio;
223 interlace_autofixoption = asset->interlace_autofixoption;
224 interlace_mode = asset->interlace_mode;
225 interlace_fixmethod = asset->interlace_fixmethod;
227 video_data = asset->video_data;
228 layers = asset->layers;
229 frame_rate = asset->frame_rate;
230 width = asset->width;
231 height = asset->height;
232 strcpy(vcodec, asset->vcodec);
233 strcpy(acodec, asset->acodec);
235 this->audio_length = asset->audio_length;
236 this->video_length = asset->video_length;
239 ampeg_bitrate = asset->ampeg_bitrate;
240 ampeg_derivative = asset->ampeg_derivative;
243 vorbis_vbr = asset->vorbis_vbr;
244 vorbis_min_bitrate = asset->vorbis_min_bitrate;
245 vorbis_bitrate = asset->vorbis_bitrate;
246 vorbis_max_bitrate = asset->vorbis_max_bitrate;
249 theora_fix_bitrate = asset->theora_fix_bitrate;
250 theora_bitrate = asset->theora_bitrate;
251 theora_quality = asset->theora_quality;
252 theora_sharpness = asset->theora_sharpness;
253 theora_keyframe_frequency = asset->theora_keyframe_frequency;
254 theora_keyframe_force_frequency = asset->theora_keyframe_frequency;
257 jpeg_quality = asset->jpeg_quality;
260 vmpeg_iframe_distance = asset->vmpeg_iframe_distance;
261 vmpeg_pframe_distance = asset->vmpeg_pframe_distance;
262 vmpeg_progressive = asset->vmpeg_progressive;
263 vmpeg_denoise = asset->vmpeg_denoise;
264 vmpeg_bitrate = asset->vmpeg_bitrate;
265 vmpeg_derivative = asset->vmpeg_derivative;
266 vmpeg_quantization = asset->vmpeg_quantization;
267 vmpeg_cmodel = asset->vmpeg_cmodel;
268 vmpeg_fix_bitrate = asset->vmpeg_fix_bitrate;
269 vmpeg_seq_codes = asset->vmpeg_seq_codes;
270 vmpeg_preset = asset->vmpeg_preset;
271 vmpeg_field_order = asset->vmpeg_field_order;
274 divx_bitrate = asset->divx_bitrate;
275 divx_rc_period = asset->divx_rc_period;
276 divx_rc_reaction_ratio = asset->divx_rc_reaction_ratio;
277 divx_rc_reaction_period = asset->divx_rc_reaction_period;
278 divx_max_key_interval = asset->divx_max_key_interval;
279 divx_max_quantizer = asset->divx_max_quantizer;
280 divx_min_quantizer = asset->divx_min_quantizer;
281 divx_quantizer = asset->divx_quantizer;
282 divx_quality = asset->divx_quality;
283 divx_fix_bitrate = asset->divx_fix_bitrate;
284 divx_use_deblocking = asset->divx_use_deblocking;
286 h264_bitrate = asset->h264_bitrate;
287 h264_quantizer = asset->h264_quantizer;
288 h264_fix_bitrate = asset->h264_fix_bitrate;
291 ms_bitrate = asset->ms_bitrate;
292 ms_bitrate_tolerance = asset->ms_bitrate_tolerance;
293 ms_interlaced = asset->ms_interlaced;
294 ms_quantization = asset->ms_quantization;
295 ms_gop_size = asset->ms_gop_size;
296 ms_fix_bitrate = asset->ms_fix_bitrate;
299 ac3_bitrate = asset->ac3_bitrate;
301 png_use_alpha = asset->png_use_alpha;
302 exr_use_alpha = asset->exr_use_alpha;
303 exr_compression = asset->exr_compression;
305 tiff_cmodel = asset->tiff_cmodel;
306 tiff_compression = asset->tiff_compression;
308 strcpy(pipe, asset->pipe);
309 use_pipe = asset->use_pipe;
311 // FUTURE: should this be here or in copy_from()?
312 strcpy(prefix, asset->prefix);
314 strcpy(reel_name, asset->reel_name);
315 reel_number = asset->reel_number;
316 tcstart = asset->tcstart;
317 tcend = asset->tcend;
318 tcformat = asset->tcformat;
321 int64_t Asset::get_index_offset(int channel)
323 if(channel < channels && index_offsets)
324 return index_offsets[channel];
329 int64_t Asset::get_index_size(int channel)
331 if(channel < channels && index_sizes)
332 return index_sizes[channel];
338 char* Asset::get_compression_text(int audio, int video)
347 return quicktime_acodec_title(acodec);
361 return quicktime_vcodec_title(vcodec);
370 Asset& Asset::operator=(Asset &asset)
372 copy_location(&asset);
373 copy_format(&asset, 1);
378 int Asset::equivalent(Asset &asset,
382 int result = (!strcmp(asset.path, path) &&
383 format == asset.format);
385 if(test_audio && result)
387 result = (channels == asset.channels &&
388 sample_rate == asset.sample_rate &&
389 bits == asset.bits &&
390 byte_order == asset.byte_order &&
391 signed_ == asset.signed_ &&
392 header == asset.header &&
393 dither == asset.dither &&
394 !strcmp(acodec, asset.acodec));
398 if(test_video && result)
400 result = (layers == asset.layers &&
401 frame_rate == asset.frame_rate &&
402 asset.interlace_autofixoption == interlace_autofixoption &&
403 asset.interlace_mode == interlace_mode &&
404 interlace_fixmethod == asset.interlace_fixmethod &&
405 width == asset.width &&
406 height == asset.height &&
407 !strcmp(vcodec, asset.vcodec) &&
408 strcmp(reel_name, asset.reel_name) == 0 &&
409 reel_number == asset.reel_number &&
410 tcstart == asset.tcstart &&
411 tcend == asset.tcend &&
412 tcformat == asset.tcformat);
418 int Asset::operator==(Asset &asset)
421 return equivalent(asset,
426 int Asset::operator!=(Asset &asset)
428 return !(*this == asset);
431 int Asset::test_path(const char *path)
433 if(!strcasecmp(this->path, path))
439 int Asset::test_plugin_title(const char *path)
443 int Asset::read(FileXML *file,
448 // Check for relative path.
451 char new_path[BCTEXTLEN];
452 char asset_directory[BCTEXTLEN];
453 char input_directory[BCTEXTLEN];
456 strcpy(new_path, path);
457 fs.set_current_dir("");
459 fs.extract_dir(asset_directory, path);
462 // Take path of XML file.
463 if(!asset_directory[0])
465 fs.extract_dir(input_directory, file->filename);
467 // Input file has a path
468 if(input_directory[0])
470 fs.join_names(path, input_directory, new_path);
478 result = file->read_tag();
481 if(file->tag.title_is("/ASSET"))
486 if(file->tag.title_is("AUDIO"))
491 if(file->tag.title_is("AUDIO_OMIT"))
496 if(file->tag.title_is("FORMAT"))
498 char *string = file->tag.get_property("TYPE");
499 format = File::strtoformat(string);
501 file->tag.get_property("USE_HEADER", use_header);
504 if(file->tag.title_is("FOLDER"))
506 strcpy(folder, file->read_text());
509 if(file->tag.title_is("VIDEO"))
514 if(file->tag.title_is("VIDEO_OMIT"))
519 if(file->tag.title_is("INDEX"))
526 //printf("Asset::read 2\n");
530 int Asset::read_audio(FileXML *file)
532 if(file->tag.title_is("AUDIO")) audio_data = 1;
533 channels = file->tag.get_property("CHANNELS", 2);
534 // This is loaded from the index file after the EDL but this
535 // should be overridable in the EDL.
536 if(!sample_rate) sample_rate = file->tag.get_property("RATE", 44100);
537 bits = file->tag.get_property("BITS", 16);
538 byte_order = file->tag.get_property("BYTE_ORDER", 1);
539 signed_ = file->tag.get_property("SIGNED", 1);
540 header = file->tag.get_property("HEADER", 0);
541 dither = file->tag.get_property("DITHER", 0);
543 audio_length = file->tag.get_property("AUDIO_LENGTH", 0);
545 file->tag.get_property("ACODEC", acodec);
549 // ampeg_bitrate = file->tag.get_property("AMPEG_BITRATE", ampeg_bitrate);
550 // ampeg_derivative = file->tag.get_property("AMPEG_DERIVATIVE", ampeg_derivative);
552 // vorbis_vbr = file->tag.get_property("VORBIS_VBR", vorbis_vbr);
553 // vorbis_min_bitrate = file->tag.get_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
554 // vorbis_bitrate = file->tag.get_property("VORBIS_BITRATE", vorbis_bitrate);
555 // vorbis_max_bitrate = file->tag.get_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
557 // mp3_bitrate = file->tag.get_property("MP3_BITRATE", mp3_bitrate);
562 tcend = audio_length;
569 int Asset::read_video(FileXML *file)
571 char string[BCTEXTLEN];
573 if(file->tag.title_is("VIDEO")) video_data = 1;
574 height = file->tag.get_property("HEIGHT", height);
575 width = file->tag.get_property("WIDTH", width);
576 layers = file->tag.get_property("LAYERS", layers);
577 // This is loaded from the index file after the EDL but this
578 // should be overridable in the EDL.
579 if(!frame_rate) frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
581 file->tag.get_property("VCODEC", vcodec);
583 video_length = file->tag.get_property("VIDEO_LENGTH", 0);
585 interlace_autofixoption = file->tag.get_property("INTERLACE_AUTOFIX",0);
587 ilacemode_to_xmltext(string, BC_ILACE_MODE_NOTINTERLACED);
588 interlace_mode = ilacemode_from_xmltext(file->tag.get_property("INTERLACE_MODE",string), BC_ILACE_MODE_NOTINTERLACED);
590 ilacefixmethod_to_xmltext(string, BC_ILACE_FIXMETHOD_NONE);
591 interlace_fixmethod = ilacefixmethod_from_xmltext(file->tag.get_property("INTERLACE_FIXMETHOD",string), BC_ILACE_FIXMETHOD_NONE);
593 file->tag.get_property("REEL_NAME", reel_name);
594 reel_number = file->tag.get_property("REEL_NUMBER", reel_number);
595 tcstart = file->tag.get_property("TCSTART", tcstart);
596 tcend = file->tag.get_property("TCEND", tcend);
597 tcformat = file->tag.get_property("TCFORMAT", tcformat);
602 int Asset::read_index(FileXML *file)
604 delete [] index_offsets;
605 index_offsets = new int64_t[channels];
606 delete [] index_sizes;
607 index_sizes = new int64_t[channels];
608 for(int i = 0; i < channels; i++)
610 index_offsets[i] = 0;
614 int current_offset = 0;
615 int current_size = 0;
618 index_zoom = file->tag.get_property("ZOOM", 1);
619 index_bytes = file->tag.get_property("BYTES", (int64_t)0);
623 result = file->read_tag();
626 if(file->tag.title_is("/INDEX"))
631 if(file->tag.title_is("OFFSET"))
633 if(current_offset < channels)
635 index_offsets[current_offset++] = file->tag.get_property("FLOAT", 0);
636 //printf("Asset::read_index %d %d\n", current_offset - 1, index_offsets[current_offset - 1]);
640 if(file->tag.title_is("SIZE"))
642 if(current_size < channels)
644 index_sizes[current_size++] = file->tag.get_property("FLOAT", 0);
652 int Asset::write_index(char *path, int data_bytes)
655 if(!(file = fopen(path, "wb")))
657 // failed to create it
658 printf(_("Asset::write_index Couldn't write index file %s to disk.\n"), path);
663 // Pad index start position
664 fwrite((char*)&(index_start), sizeof(int64_t), 1, file);
666 index_status = INDEX_READY;
667 // Write encoding information
671 xml.write_to_file(file);
672 index_start = ftell(file);
673 fseek(file, 0, SEEK_SET);
675 fwrite((char*)&(index_start), sizeof(int64_t), 1, file);
676 fseek(file, index_start, SEEK_SET);
686 // Force reread of header
687 index_status = INDEX_NOTTESTED;
688 // index_status = INDEX_READY;
689 index_end = audio_length;
694 // Output path is the path of the output file if name truncation is desired.
695 // It is a "" if complete names should be used.
697 int Asset::write(FileXML *file,
701 char new_path[BCTEXTLEN];
702 char asset_directory[BCTEXTLEN];
703 char output_directory[BCTEXTLEN];
706 // Make path relative
707 fs.extract_dir(asset_directory, path);
708 if(output_path && output_path[0])
709 fs.extract_dir(output_directory, output_path);
711 output_directory[0] = 0;
713 // Asset and EDL are in same directory. Extract just the name.
714 if(!strcmp(asset_directory, output_directory))
716 fs.extract_name(new_path, path);
720 strcpy(new_path, path);
723 file->tag.set_title("ASSET");
724 file->tag.set_property("SRC", new_path);
726 file->append_newline();
728 file->tag.set_title("FOLDER");
730 file->append_text(folder);
731 file->tag.set_title("/FOLDER");
733 file->append_newline();
735 // Write the format information
736 file->tag.set_title("FORMAT");
738 file->tag.set_property("TYPE",
739 File::formattostr(format));
740 file->tag.set_property("USE_HEADER", use_header);
743 file->tag.set_title("/FORMAT");
745 file->append_newline();
747 // Requiring data to exist caused batch render to lose settings.
748 // But the only way to know if an asset doesn't have audio or video data
749 // is to not write the block.
750 // So change the block name if the asset doesn't have the data.
751 /* if(audio_data) */ write_audio(file);
752 /* if(video_data) */ write_video(file);
753 if(index_status == 0 && include_index) write_index(file); // index goes after source
755 file->tag.set_title("/ASSET");
757 file->append_newline();
761 int Asset::write_audio(FileXML *file)
763 // Let the reader know if the asset has the data by naming the block.
765 file->tag.set_title("AUDIO");
767 file->tag.set_title("AUDIO_OMIT");
768 // Necessary for PCM audio
769 file->tag.set_property("CHANNELS", channels);
770 file->tag.set_property("RATE", sample_rate);
771 file->tag.set_property("BITS", bits);
772 file->tag.set_property("BYTE_ORDER", byte_order);
773 file->tag.set_property("SIGNED", signed_);
774 file->tag.set_property("HEADER", header);
775 file->tag.set_property("DITHER", dither);
777 file->tag.set_property("ACODEC", acodec);
779 file->tag.set_property("AUDIO_LENGTH", audio_length);
783 // Rely on defaults operations for these.
785 // file->tag.set_property("AMPEG_BITRATE", ampeg_bitrate);
786 // file->tag.set_property("AMPEG_DERIVATIVE", ampeg_derivative);
788 // file->tag.set_property("VORBIS_VBR", vorbis_vbr);
789 // file->tag.set_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
790 // file->tag.set_property("VORBIS_BITRATE", vorbis_bitrate);
791 // file->tag.set_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
793 // file->tag.set_property("MP3_BITRATE", mp3_bitrate);
800 file->tag.set_title("/AUDIO");
802 file->tag.set_title("/AUDIO_OMIT");
804 file->append_newline();
808 int Asset::write_video(FileXML *file)
810 char string[BCTEXTLEN];
813 file->tag.set_title("VIDEO");
815 file->tag.set_title("VIDEO_OMIT");
816 file->tag.set_property("HEIGHT", height);
817 file->tag.set_property("WIDTH", width);
818 file->tag.set_property("LAYERS", layers);
819 file->tag.set_property("FRAMERATE", frame_rate);
821 file->tag.set_property("VCODEC", vcodec);
823 file->tag.set_property("VIDEO_LENGTH", video_length);
825 file->tag.set_property("INTERLACE_AUTOFIX", interlace_autofixoption);
827 ilacemode_to_xmltext(string, interlace_mode);
828 file->tag.set_property("INTERLACE_MODE", string);
830 ilacefixmethod_to_xmltext(string, interlace_fixmethod);
831 file->tag.set_property("INTERLACE_FIXMETHOD", string);
834 file->tag.set_property("REEL_NAME", reel_name);
835 file->tag.set_property("REEL_NUMBER", reel_number);
836 file->tag.set_property("TCSTART", tcstart);
837 file->tag.set_property("TCEND", tcend);
838 file->tag.set_property("TCFORMAT", tcformat);
842 file->tag.set_title("/VIDEO");
844 file->tag.set_title("/VIDEO_OMIT");
847 file->append_newline();
851 int Asset::write_index(FileXML *file)
853 file->tag.set_title("INDEX");
854 file->tag.set_property("ZOOM", index_zoom);
855 file->tag.set_property("BYTES", index_bytes);
857 file->append_newline();
861 for(int i = 0; i < channels; i++)
863 file->tag.set_title("OFFSET");
864 file->tag.set_property("FLOAT", index_offsets[i]);
866 file->tag.set_title("/OFFSET");
868 file->tag.set_title("SIZE");
869 file->tag.set_property("FLOAT", index_sizes[i]);
871 file->tag.set_title("/SIZE");
876 file->append_newline();
877 file->tag.set_title("/INDEX");
879 file->append_newline();
886 char* Asset::construct_param(char *param, char *prefix, char *return_value)
889 sprintf(return_value, "%s%s", prefix, param);
891 strcpy(return_value, param);
895 #define UPDATE_DEFAULT(x, y) defaults->update(construct_param(x, prefix, string), y);
896 #define GET_DEFAULT(x, y) defaults->get(construct_param(x, prefix, string), y);
898 void Asset::load_defaults(BC_Hash *defaults,
906 char string[BCTEXTLEN];
908 // Can't save codec here because it's specific to render, record, and effect.
909 // The codec has to be UNKNOWN for file probing to work.
913 GET_DEFAULT("PATH", path);
918 GET_DEFAULT("AUDIO_CODEC", acodec);
919 GET_DEFAULT("VIDEO_CODEC", vcodec);
924 format = GET_DEFAULT("FORMAT", format);
929 audio_data = GET_DEFAULT("AUDIO", 1);
930 video_data = GET_DEFAULT("VIDEO", 1);
935 bits = GET_DEFAULT("BITS", 16);
936 dither = GET_DEFAULT("DITHER", 0);
937 signed_ = GET_DEFAULT("SIGNED", 1);
938 byte_order = GET_DEFAULT("BYTE_ORDER", 1);
941 // NOTE: this should never be saved
942 strcpy(this->prefix, prefix ? prefix : "");
944 ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
945 ampeg_derivative = GET_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
947 vorbis_vbr = GET_DEFAULT("VORBIS_VBR", vorbis_vbr);
948 vorbis_min_bitrate = GET_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
949 vorbis_bitrate = GET_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
950 vorbis_max_bitrate = GET_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
952 theora_fix_bitrate = GET_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
953 theora_bitrate = GET_DEFAULT("THEORA_BITRATE", theora_bitrate);
954 theora_quality = GET_DEFAULT("THEORA_QUALITY", theora_quality);
955 theora_sharpness = GET_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
956 theora_keyframe_frequency = GET_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
957 theora_keyframe_force_frequency = GET_DEFAULT("THEORA_FORCE_KEYFRAME_FEQUENCY", theora_keyframe_force_frequency);
961 mp3_bitrate = GET_DEFAULT("MP3_BITRATE", mp3_bitrate);
962 mp4a_bitrate = GET_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
963 mp4a_quantqual = GET_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
965 jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
966 aspect_ratio = GET_DEFAULT("ASPECT_RATIO", aspect_ratio);
968 interlace_autofixoption = BC_ILACE_AUTOFIXOPTION_AUTO;
969 interlace_mode = BC_ILACE_MODE_UNDETECTED;
970 interlace_fixmethod = BC_ILACE_FIXMETHOD_UPONE;
972 // MPEG format information
973 vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
974 vmpeg_pframe_distance = GET_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
975 vmpeg_progressive = GET_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
976 vmpeg_denoise = GET_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
977 vmpeg_bitrate = GET_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
978 vmpeg_derivative = GET_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
979 vmpeg_quantization = GET_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
980 vmpeg_cmodel = GET_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
981 vmpeg_fix_bitrate = GET_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
982 vmpeg_seq_codes = GET_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
983 vmpeg_preset = GET_DEFAULT("VMPEG_PRESET", vmpeg_preset);
984 vmpeg_field_order = GET_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
986 h264_bitrate = GET_DEFAULT("H264_BITRATE", h264_bitrate);
987 h264_quantizer = GET_DEFAULT("H264_QUANTIZER", h264_quantizer);
988 h264_fix_bitrate = GET_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
991 divx_bitrate = GET_DEFAULT("DIVX_BITRATE", divx_bitrate);
992 divx_rc_period = GET_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
993 divx_rc_reaction_ratio = GET_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
994 divx_rc_reaction_period = GET_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
995 divx_max_key_interval = GET_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
996 divx_max_quantizer = GET_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
997 divx_min_quantizer = GET_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
998 divx_quantizer = GET_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
999 divx_quality = GET_DEFAULT("DIVX_QUALITY", divx_quality);
1000 divx_fix_bitrate = GET_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
1001 divx_use_deblocking = GET_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
1003 theora_fix_bitrate = GET_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
1004 theora_bitrate = GET_DEFAULT("THEORA_BITRATE", theora_bitrate);
1005 theora_quality = GET_DEFAULT("THEORA_QUALITY", theora_quality);
1006 theora_sharpness = GET_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
1007 theora_keyframe_frequency = GET_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
1008 theora_keyframe_force_frequency = GET_DEFAULT("THEORA_FORCE_KEYFRAME_FEQUENCY", theora_keyframe_force_frequency);
1011 ms_bitrate = GET_DEFAULT("MS_BITRATE", ms_bitrate);
1012 ms_bitrate_tolerance = GET_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
1013 ms_interlaced = GET_DEFAULT("MS_INTERLACED", ms_interlaced);
1014 ms_quantization = GET_DEFAULT("MS_QUANTIZATION", ms_quantization);
1015 ms_gop_size = GET_DEFAULT("MS_GOP_SIZE", ms_gop_size);
1016 ms_fix_bitrate = GET_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
1018 ac3_bitrate = GET_DEFAULT("AC3_BITRATE", ac3_bitrate);
1020 png_use_alpha = GET_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
1021 exr_use_alpha = GET_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
1022 exr_compression = GET_DEFAULT("EXR_COMPRESSION", exr_compression);
1023 tiff_cmodel = GET_DEFAULT("TIFF_CMODEL", tiff_cmodel);
1024 tiff_compression = GET_DEFAULT("TIFF_COMPRESSION", tiff_compression);
1026 GET_DEFAULT("REEL_NAME", reel_name);
1027 reel_number = GET_DEFAULT("REEL_NUMBER", reel_number);
1028 tcstart = GET_DEFAULT("TCSTART", tcstart);
1029 tcend = GET_DEFAULT("TCEND", tcend);
1030 tcformat = GET_DEFAULT("TCFORMAT", tcformat);
1032 load_format_defaults(defaults);
1035 // FUTURE: put more of the format specific variables in here
1036 void Asset::load_format_defaults(BC_Hash *defaults) {
1037 char temp[BCTEXTLEN];
1038 char string[BCTEXTLEN];
1039 if (! format) return;
1041 // NOTE: old value is used if no init value set before GET_DEFAULT
1043 // override the defaults with those for this format
1044 sprintf(temp, "FORMAT_%s_USE_PIPE", FILE_FORMAT_PREFIX(format));
1046 use_pipe = GET_DEFAULT(temp, use_pipe);
1048 sprintf(temp, "FORMAT_%s_PIPE", FILE_FORMAT_PREFIX(format));
1050 GET_DEFAULT(temp, pipe);
1052 sprintf(temp, "FORMAT_%s_PATH", FILE_FORMAT_PREFIX(format));
1054 GET_DEFAULT(temp, path);
1058 void Asset::save_defaults(BC_Hash *defaults,
1066 char string[BCTEXTLEN];
1068 UPDATE_DEFAULT("PATH", path);
1072 UPDATE_DEFAULT("FORMAT", format);
1077 UPDATE_DEFAULT("AUDIO", audio_data);
1078 UPDATE_DEFAULT("VIDEO", video_data);
1083 UPDATE_DEFAULT("AUDIO_CODEC", acodec);
1084 UPDATE_DEFAULT("VIDEO_CODEC", vcodec);
1086 UPDATE_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
1087 UPDATE_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
1089 UPDATE_DEFAULT("VORBIS_VBR", vorbis_vbr);
1090 UPDATE_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
1091 UPDATE_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
1092 UPDATE_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
1095 UPDATE_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
1096 UPDATE_DEFAULT("THEORA_BITRATE", theora_bitrate);
1097 UPDATE_DEFAULT("THEORA_QUALITY", theora_quality);
1098 UPDATE_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
1099 UPDATE_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
1100 UPDATE_DEFAULT("THEORA_FORCE_KEYFRAME_FEQUENCY", theora_keyframe_force_frequency);
1104 UPDATE_DEFAULT("MP3_BITRATE", mp3_bitrate);
1105 UPDATE_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
1106 UPDATE_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
1112 UPDATE_DEFAULT("JPEG_QUALITY", jpeg_quality);
1113 UPDATE_DEFAULT("ASPECT_RATIO", aspect_ratio);
1115 // MPEG format information
1116 UPDATE_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
1117 UPDATE_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
1118 UPDATE_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
1119 UPDATE_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
1120 UPDATE_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
1121 UPDATE_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
1122 UPDATE_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
1123 UPDATE_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
1124 UPDATE_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
1125 UPDATE_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
1126 UPDATE_DEFAULT("VMPEG_PRESET", vmpeg_preset);
1127 UPDATE_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
1129 UPDATE_DEFAULT("H264_BITRATE", h264_bitrate);
1130 UPDATE_DEFAULT("H264_QUANTIZER", h264_quantizer);
1131 UPDATE_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
1133 UPDATE_DEFAULT("DIVX_BITRATE", divx_bitrate);
1134 UPDATE_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
1135 UPDATE_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
1136 UPDATE_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
1137 UPDATE_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
1138 UPDATE_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
1139 UPDATE_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
1140 UPDATE_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
1141 UPDATE_DEFAULT("DIVX_QUALITY", divx_quality);
1142 UPDATE_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
1143 UPDATE_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
1146 UPDATE_DEFAULT("MS_BITRATE", ms_bitrate);
1147 UPDATE_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
1148 UPDATE_DEFAULT("MS_INTERLACED", ms_interlaced);
1149 UPDATE_DEFAULT("MS_QUANTIZATION", ms_quantization);
1150 UPDATE_DEFAULT("MS_GOP_SIZE", ms_gop_size);
1151 UPDATE_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
1153 UPDATE_DEFAULT("AC3_BITRATE", ac3_bitrate);
1156 UPDATE_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
1157 UPDATE_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
1158 UPDATE_DEFAULT("EXR_COMPRESSION", exr_compression);
1159 UPDATE_DEFAULT("TIFF_CMODEL", tiff_cmodel);
1160 UPDATE_DEFAULT("TIFF_COMPRESSION", tiff_compression);
1165 UPDATE_DEFAULT("BITS", bits);
1166 UPDATE_DEFAULT("DITHER", dither);
1167 UPDATE_DEFAULT("SIGNED", signed_);
1168 UPDATE_DEFAULT("BYTE_ORDER", byte_order);
1171 UPDATE_DEFAULT("REEL_NAME", reel_name);
1172 UPDATE_DEFAULT("REEL_NUMBER", reel_number);
1173 UPDATE_DEFAULT("TCSTART", tcstart);
1174 UPDATE_DEFAULT("TCEND", tcend);
1175 UPDATE_DEFAULT("TCFORMAT", tcformat);
1177 save_format_defaults(defaults);
1181 // FUTURE: put more of the format specific variables in here
1182 void Asset::save_format_defaults(BC_Hash *defaults) {
1183 char temp[BCTEXTLEN];
1184 char string[BCTEXTLEN];
1185 if (! format) return;
1187 sprintf(temp, "FORMAT_%s_USE_PIPE", FILE_FORMAT_PREFIX(format));
1188 UPDATE_DEFAULT(temp, use_pipe);
1190 sprintf(temp, "FORMAT_%s_PIPE", FILE_FORMAT_PREFIX(format));
1191 UPDATE_DEFAULT(temp, pipe);
1193 sprintf(temp, "FORMAT_%s_PATH", FILE_FORMAT_PREFIX(format));
1194 UPDATE_DEFAULT(temp, path);
1198 int Asset::update_path(char *new_path)
1200 strcpy(path, new_path);
1204 double Asset::total_length_framealigned(double fps)
1206 if (video_data && audio_data) {
1207 double aud = floor(( (double)audio_length / sample_rate) * fps) / fps;
1208 double vid = floor(( (double)video_length / frame_rate) * fps) / fps;
1209 return MIN(aud,vid);
1213 return (double)audio_length / sample_rate;
1216 return (double)video_length / frame_rate;
1219 void Asset::update_index(Asset *asset)
1221 //printf("Asset::update_index 1 %d\n", index_status);
1222 index_status = asset->index_status;
1223 index_zoom = asset->index_zoom; // zoom factor of index data
1224 index_start = asset->index_start; // byte start of index data in the index file
1225 index_bytes = asset->index_bytes; // Total bytes in source file for comparison before rebuilding the index
1226 index_end = asset->index_end;
1227 old_index_end = asset->old_index_end; // values for index build
1229 delete [] index_offsets;
1230 delete [] index_sizes;
1234 if(asset->index_offsets)
1236 index_offsets = new int64_t[asset->channels];
1237 index_sizes = new int64_t[asset->channels];
1240 for(i = 0; i < asset->channels; i++)
1242 // offsets of channels in index file in floats
1243 index_offsets[i] = asset->index_offsets[i];
1244 index_sizes[i] = asset->index_sizes[i];
1247 index_buffer = asset->index_buffer; // pointer
1250 int Asset::set_timecode(char *tc, int format, int end)
1254 hr = ((int) tc[0] - 48) * 10 + (int) tc[1] - 48;
1255 min = ((int) tc[3] - 48) * 10 + (int) tc[4] - 48;
1256 sec = ((int) tc[6] - 48) * 10 + (int) tc[7] - 48;
1258 // This needs to be modified to handle drop-frame
1261 tcend = (int64_t) (((hr * 3600) + (min * 60) + sec) * frame_rate);
1263 tcstart = (int64_t) (((hr * 3600) + (min * 60) + sec) * frame_rate);
1271 printf(" asset::dump\n");
1272 printf(" %p %s\n", this, path);
1273 printf(" index_status %d\n", index_status);
1274 printf(" format %d\n", format);
1275 printf(" audio_data %d channels %d samplerate %d bits %d byte_order %d signed %d header %d dither %d acodec %c%c%c%c\n",
1276 audio_data, channels, sample_rate, bits, byte_order, signed_, header, dither, acodec[0], acodec[1], acodec[2], acodec[3]);
1277 printf(" audio_length %lld\n", audio_length);
1278 char string[BCTEXTLEN];
1279 ilacemode_to_xmltext(string, interlace_mode);
1280 printf(" video_data %d layers %d framerate %f width %d height %d vcodec %c%c%c%c aspect_ratio %f interlace_mode %s\n",
1281 video_data, layers, frame_rate, width, height, vcodec[0], vcodec[1], vcodec[2], vcodec[3], aspect_ratio, string);
1282 printf(" video_length %lld \n", video_length);
1283 printf(" reel_name %s reel_number %i tcstart %d tcend %d tcf %d\n",
1284 reel_name, reel_number, tcstart, tcend, tcformat);