remove old quicktime, replaced with current ffmpeg
[goodguy/history.git] / cinelerra-5.0 / cinelerra / asset.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  * 
19  */
20
21
22 #include "asset.h"
23 #include "assets.h"
24 #include "bchash.h"
25 #include "bcsignals.h"
26 #include "clip.h"
27 #include "edl.h"
28 #include "file.h"
29 #include "filesystem.h"
30 #include "filexml.h"
31 #include "format.inc"
32 #include "indexstate.h"
33
34 #include <stdio.h>
35 #include <string.h>
36
37
38 Asset::Asset()
39  : Indexable(1), ListItem<Asset>()
40 {
41         init_values();
42 }
43
44 Asset::Asset(Asset &asset)
45  : Indexable(1), ListItem<Asset>()
46 {
47         init_values();
48         this->copy_from(&asset, 1);
49 }
50
51 Asset::Asset(const char *path)
52  : Indexable(1), ListItem<Asset>()
53 {
54         init_values();
55         strcpy(this->path, path);
56 }
57
58 Asset::Asset(const int plugin_type, const char *plugin_title)
59  : Indexable(1), ListItem<Asset>()
60 {
61         init_values();
62 }
63
64 Asset::~Asset()
65 {
66 }
67
68 int Asset::init_values()
69 {
70         path[0] = 0;
71 // Has to be unknown for file probing to succeed
72         format = FILE_UNKNOWN;
73         fformat[0] = 0;
74         bits = 0;
75         byte_order = 0;
76         signed_ = 0;
77         header = 0;
78         dither = 0;
79         reset_audio();
80         reset_video();
81
82         strcpy(vcodec, "");
83         strcpy(acodec, "");
84
85         ff_audio_options[0] = 0;
86         ff_video_options[0] = 0;
87         ff_audio_bitrate = 0;
88         ff_video_bitrate = 0;
89         ff_video_quality = 0;
90
91         jpeg_quality = 100;
92         aspect_ratio = -1;
93
94         ampeg_bitrate = 256;
95         ampeg_derivative = 3;
96
97         vorbis_vbr = 0;
98         vorbis_min_bitrate = -1;
99         vorbis_bitrate = 128000;
100         vorbis_max_bitrate = -1;
101
102         theora_fix_bitrate = 1;
103         theora_bitrate = 860000;
104         theora_quality = 16;
105         theora_sharpness = 2;
106         theora_keyframe_frequency = 64;
107         theora_keyframe_force_frequency = 64;
108
109         mp3_bitrate = 256000;
110
111
112         mp4a_bitrate = 256000;
113         mp4a_quantqual = 100;
114
115
116
117 // mpeg parameters
118         vmpeg_iframe_distance = 45;
119         vmpeg_pframe_distance = 0;
120         vmpeg_progressive = 0;
121         vmpeg_denoise = 1;
122         vmpeg_bitrate = 1000000;
123         vmpeg_derivative = 1;
124         vmpeg_quantization = 15;
125         vmpeg_cmodel = BC_YUV420P;
126         vmpeg_fix_bitrate = 0;
127         vmpeg_seq_codes = 0;
128         vmpeg_preset = 0;
129         vmpeg_field_order = 0;
130
131 // Divx parameters.  BC_Hash from encore2
132         divx_bitrate = 2000000;
133         divx_rc_period = 50;
134         divx_rc_reaction_ratio = 45;
135         divx_rc_reaction_period = 10;
136         divx_max_key_interval = 250;
137         divx_max_quantizer = 31;
138         divx_min_quantizer = 1;
139         divx_quantizer = 5;
140         divx_quality = 5;
141         divx_fix_bitrate = 1;
142         divx_use_deblocking = 1;
143
144         h264_bitrate = 2000000;
145         h264_quantizer = 5;
146         h264_fix_bitrate = 0;
147
148         ms_bitrate = 1000000;
149         ms_bitrate_tolerance = 500000;
150         ms_quantization = 10;
151         ms_interlaced = 0;
152         ms_gop_size = 45;
153         ms_fix_bitrate = 1;
154
155         ac3_bitrate = 128;
156
157         png_use_alpha = 0;
158         exr_use_alpha = 0;
159         exr_compression = 0;
160
161         tiff_cmodel = 0;
162         tiff_compression = 0;
163
164         use_header = 1;
165
166         id = EDL::next_id();
167
168         return 0;
169 }
170
171 void Asset::reset_audio()
172 {
173         audio_data = 0;
174         channels = 0;
175         sample_rate = 0;
176         audio_length = 0;
177 }
178
179 void Asset::reset_video()
180 {
181         video_data = 0;
182         layers = 0;
183         actual_width = width = 0;
184         actual_height = height = 0;
185         video_length = 0;
186         vmpeg_cmodel = BC_YUV420P;
187         frame_rate = 0;
188         program = -1;
189 }
190
191
192 void Asset::boundaries()
193 {
194 //printf("Asset::boundaries %d %d %f\n", __LINE__, sample_rate, frame_rate);
195 // sample_rate & frame_rate are user defined
196 //      CLAMP(sample_rate, 1, 1000000);
197 //      CLAMP(frame_rate, 0.001, 1000000);
198         CLAMP(channels, 0, 16);
199         CLAMP(width, 0, 10000);
200         CLAMP(height, 0, 10000);
201 //printf("Asset::boundaries %d %d %f\n", __LINE__, sample_rate, frame_rate);
202 }
203
204
205 void Asset::reset_index()
206 {
207         index_state->reset();
208 }
209
210 void Asset::copy_from(Asset *asset, int do_index)
211 {
212         copy_location(asset);
213         copy_format(asset, do_index);
214 }
215
216 void Asset::copy_location(Asset *asset)
217 {
218         strcpy(this->path, asset->path);
219         strcpy(this->folder, asset->folder);
220 }
221
222 void Asset::copy_format(Asset *asset, int do_index)
223 {
224         if(do_index) update_index(asset);
225
226         audio_data = asset->audio_data;
227         format = asset->format;
228         strcpy(fformat, asset->fformat);
229         channels = asset->channels;
230         sample_rate = asset->sample_rate;
231         bits = asset->bits;
232         byte_order = asset->byte_order;
233         signed_ = asset->signed_;
234         header = asset->header;
235         dither = asset->dither;
236         mp3_bitrate = asset->mp3_bitrate;
237         mp4a_bitrate = asset->mp4a_bitrate;
238         mp4a_quantqual = asset->mp4a_quantqual;
239         use_header = asset->use_header;
240         aspect_ratio = asset->aspect_ratio;
241
242         video_data = asset->video_data;
243         layers = asset->layers;
244         program = asset->program;
245         frame_rate = asset->frame_rate;
246         width = asset->width;
247         height = asset->height;
248         actual_width = asset->actual_width;
249         actual_height = asset->actual_height;
250         strcpy(vcodec, asset->vcodec);
251         strcpy(acodec, asset->acodec);
252
253         strcpy(ff_audio_options, asset->ff_audio_options);
254         strcpy(ff_video_options, asset->ff_video_options);
255         ff_audio_bitrate = asset->ff_audio_bitrate;
256         ff_video_bitrate = asset->ff_video_bitrate;
257         ff_video_quality = asset->ff_video_quality;
258
259         this->audio_length = asset->audio_length;
260         this->video_length = asset->video_length;
261
262
263         ampeg_bitrate = asset->ampeg_bitrate;
264         ampeg_derivative = asset->ampeg_derivative;
265
266
267         vorbis_vbr = asset->vorbis_vbr;
268         vorbis_min_bitrate = asset->vorbis_min_bitrate;
269         vorbis_bitrate = asset->vorbis_bitrate;
270         vorbis_max_bitrate = asset->vorbis_max_bitrate;
271
272         
273         theora_fix_bitrate = asset->theora_fix_bitrate;
274         theora_bitrate = asset->theora_bitrate;
275         theora_quality = asset->theora_quality;
276         theora_sharpness = asset->theora_sharpness;
277         theora_keyframe_frequency = asset->theora_keyframe_frequency;
278         theora_keyframe_force_frequency = asset->theora_keyframe_frequency;
279
280
281         jpeg_quality = asset->jpeg_quality;
282
283 // mpeg parameters
284         vmpeg_iframe_distance = asset->vmpeg_iframe_distance;
285         vmpeg_pframe_distance = asset->vmpeg_pframe_distance;
286         vmpeg_progressive = asset->vmpeg_progressive;
287         vmpeg_denoise = asset->vmpeg_denoise;
288         vmpeg_bitrate = asset->vmpeg_bitrate;
289         vmpeg_derivative = asset->vmpeg_derivative;
290         vmpeg_quantization = asset->vmpeg_quantization;
291         vmpeg_cmodel = asset->vmpeg_cmodel;
292         vmpeg_fix_bitrate = asset->vmpeg_fix_bitrate;
293         vmpeg_seq_codes = asset->vmpeg_seq_codes;
294         vmpeg_preset = asset->vmpeg_preset;
295         vmpeg_field_order = asset->vmpeg_field_order;
296
297
298         divx_bitrate = asset->divx_bitrate;
299         divx_rc_period = asset->divx_rc_period;
300         divx_rc_reaction_ratio = asset->divx_rc_reaction_ratio;
301         divx_rc_reaction_period = asset->divx_rc_reaction_period;
302         divx_max_key_interval = asset->divx_max_key_interval;
303         divx_max_quantizer = asset->divx_max_quantizer;
304         divx_min_quantizer = asset->divx_min_quantizer;
305         divx_quantizer = asset->divx_quantizer;
306         divx_quality = asset->divx_quality;
307         divx_fix_bitrate = asset->divx_fix_bitrate;
308         divx_use_deblocking = asset->divx_use_deblocking;
309
310         h264_bitrate = asset->h264_bitrate;
311         h264_quantizer = asset->h264_quantizer;
312         h264_fix_bitrate = asset->h264_fix_bitrate;
313
314
315         ms_bitrate = asset->ms_bitrate;
316         ms_bitrate_tolerance = asset->ms_bitrate_tolerance;
317         ms_interlaced = asset->ms_interlaced;
318         ms_quantization = asset->ms_quantization;
319         ms_gop_size = asset->ms_gop_size;
320         ms_fix_bitrate = asset->ms_fix_bitrate;
321
322         
323         ac3_bitrate = asset->ac3_bitrate;
324         
325         png_use_alpha = asset->png_use_alpha;
326         exr_use_alpha = asset->exr_use_alpha;
327         exr_compression = asset->exr_compression;
328
329         tiff_cmodel = asset->tiff_cmodel;
330         tiff_compression = asset->tiff_compression;
331 }
332
333 int64_t Asset::get_index_offset(int channel)
334 {
335         return index_state->get_index_offset(channel);
336 }
337
338 int64_t Asset::get_index_size(int channel)
339 {
340         return index_state->get_index_size(channel);
341 }
342
343
344 char* Asset::get_compression_text(int audio, int video)
345 {
346         if(audio) {
347                 switch(format) {
348                 case FILE_FFMPEG:
349                         if( acodec[0] ) return acodec;
350                         break;
351                 }
352         }
353         if(video) {
354                 switch(format) {
355                 case FILE_FFMPEG:
356                         if( vcodec[0] ) return vcodec;
357                         break;
358                 }
359         }
360         return 0;
361 }
362
363 Asset& Asset::operator=(Asset &asset)
364 {
365 printf("Asset::operator=\n");
366         copy_location(&asset);
367         copy_format(&asset, 1);
368         return *this;
369 }
370
371
372 int Asset::equivalent(Asset &asset, 
373         int test_audio, 
374         int test_video)
375 {
376         int result = (!strcmp(asset.path, path) &&
377                 format == asset.format);
378
379         if(result && format == FILE_FFMPEG)
380                 result = !strcmp(fformat, asset.fformat);
381
382         if(test_audio && result)
383         {
384                 result = (channels == asset.channels && 
385                         sample_rate == asset.sample_rate && 
386                         bits == asset.bits && 
387                         byte_order == asset.byte_order && 
388                         signed_ == asset.signed_ && 
389                         header == asset.header && 
390                         dither == asset.dither &&
391                         !strcmp(acodec, asset.acodec));
392                 if(result && format == FILE_FFMPEG)
393                         result = !strcmp(ff_audio_options, asset.ff_audio_options) &&
394                                 ff_audio_bitrate == asset.ff_audio_bitrate;
395                                 
396         }
397
398
399         if(test_video && result)
400         {
401                 result = (layers == asset.layers && 
402                         program == asset.program && 
403                         frame_rate == asset.frame_rate &&
404                         width == asset.width &&
405                         height == asset.height &&
406                         !strcmp(vcodec, asset.vcodec));
407                 if(result && format == FILE_FFMPEG)
408                         result = !strcmp(ff_video_options, asset.ff_video_options) &&
409                                 ff_video_bitrate == asset.ff_video_bitrate &&
410                                 ff_video_quality == asset.ff_video_quality;
411         }
412
413         return result;
414 }
415
416 int Asset::operator==(Asset &asset)
417 {
418
419         return equivalent(asset, 
420                 1, 
421                 1);
422 }
423
424 int Asset::operator!=(Asset &asset)
425 {
426         return !(*this == asset);
427 }
428
429 int Asset::test_path(const char *path)
430 {
431         if(!strcasecmp(this->path, path)) 
432                 return 1; 
433         else 
434                 return 0;
435 }
436
437 int Asset::test_plugin_title(const char *path)
438 {
439         return 0;
440 }
441
442 int Asset::read(FileXML *file, 
443         int expand_relative)
444 {
445         int result = 0;
446
447 // Check for relative path.
448         if(expand_relative)
449         {
450                 char new_path[BCTEXTLEN];
451                 char asset_directory[BCTEXTLEN];
452                 char input_directory[BCTEXTLEN];
453                 FileSystem fs;
454
455                 strcpy(new_path, path);
456                 fs.set_current_dir("");
457
458                 fs.extract_dir(asset_directory, path);
459
460 // No path in asset.
461 // Take path of XML file.
462                 if(!asset_directory[0])
463                 {
464                         fs.extract_dir(input_directory, file->filename);
465
466 // Input file has a path
467                         if(input_directory[0])
468                         {
469                                 fs.join_names(path, input_directory, new_path);
470                         }
471                 }
472         }
473
474
475         while(!result)
476         {
477                 result = file->read_tag();
478                 if(!result)
479                 {
480                         if(file->tag.title_is("/ASSET"))
481                         {
482                                 result = 1;
483                         }
484                         else
485                         if(file->tag.title_is("AUDIO"))
486                         {
487                                 read_audio(file);
488                         }
489                         else
490                         if(file->tag.title_is("AUDIO_OMIT"))
491                         {
492                                 read_audio(file);
493                         }
494                         else
495                         if(file->tag.title_is("FORMAT"))
496                         {
497                                 const char *string = file->tag.get_property("TYPE");
498                                 format = File::strtoformat(string);
499                                 use_header = 
500                                         file->tag.get_property("USE_HEADER", use_header);
501                                 file->tag.get_property("FFORMAT", fformat);
502                         }
503                         else
504                         if(file->tag.title_is("FOLDER"))
505                         {
506                                 strcpy(folder, file->read_text());
507                         }
508                         else
509                         if(file->tag.title_is("VIDEO"))
510                         {
511                                 read_video(file);
512                         }
513                         else
514                         if(file->tag.title_is("VIDEO_OMIT"))
515                         {
516                                 read_video(file);
517                         }
518                         else
519                         if(file->tag.title_is("INDEX"))
520                         {
521                                 read_index(file);
522                         }
523                 }
524         }
525
526         boundaries();
527 //printf("Asset::read 2\n");
528         return 0;
529 }
530
531 int Asset::read_audio(FileXML *file)
532 {
533         if(file->tag.title_is("AUDIO")) audio_data = 1;
534         channels = file->tag.get_property("CHANNELS", 2);
535 // This is loaded from the index file after the EDL but this 
536 // should be overridable in the EDL.
537         if(!sample_rate) sample_rate = file->tag.get_property("RATE", 44100);
538         bits = file->tag.get_property("BITS", 16);
539         byte_order = file->tag.get_property("BYTE_ORDER", 1);
540         signed_ = file->tag.get_property("SIGNED", 1);
541         header = file->tag.get_property("HEADER", 0);
542         dither = file->tag.get_property("DITHER", 0);
543
544         audio_length = file->tag.get_property("AUDIO_LENGTH", (int64_t)0);
545         acodec[0] = 0;
546         file->tag.get_property("ACODEC", acodec);
547
548         return 0;
549 }
550
551 int Asset::read_video(FileXML *file)
552 {
553         if(file->tag.title_is("VIDEO")) video_data = 1;
554         actual_height = file->tag.get_property("ACTUAL_HEIGHT", actual_height);
555         actual_width = file->tag.get_property("ACTUAL_WIDTH", actual_width);
556         height = file->tag.get_property("HEIGHT", height);
557         width = file->tag.get_property("WIDTH", width);
558         layers = file->tag.get_property("LAYERS", layers);
559         program = file->tag.get_property("PROGRAM", program);
560 // This is loaded from the index file after the EDL but this 
561 // should be overridable in the EDL.
562         if(EQUIV(frame_rate, 0)) frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
563         vcodec[0] = 0;
564         file->tag.get_property("VCODEC", vcodec);
565
566         video_length = file->tag.get_property("VIDEO_LENGTH", (int64_t)0);
567
568         return 0;
569 }
570
571 int Asset::read_index(FileXML *file)
572 {
573         index_state->read_xml(file, channels);
574         return 0;
575 }
576
577 int Asset::write_index(const char *path, int data_bytes)
578 {
579         return index_state->write_index(path, data_bytes, this, audio_length);
580 }
581
582 // Output path is the path of the output file if name truncation is desired.
583 // It is a "" if complete names should be used.
584
585 int Asset::write(FileXML *file, 
586         int include_index, 
587         const char *output_path)
588 {
589         char new_path[BCTEXTLEN];
590         char asset_directory[BCTEXTLEN];
591         char output_directory[BCTEXTLEN];
592         FileSystem fs;
593
594 // Make path relative
595         fs.extract_dir(asset_directory, path);
596         if(output_path && output_path[0]) 
597                 fs.extract_dir(output_directory, output_path);
598         else
599                 output_directory[0] = 0;
600
601 // Asset and EDL are in same directory.  Extract just the name.
602         if(!strcmp(asset_directory, output_directory))
603         {
604                 fs.extract_name(new_path, path);
605         }
606         else
607         {
608                 strcpy(new_path, path);
609         }
610
611         file->tag.set_title("ASSET");
612         file->tag.set_property("SRC", new_path);
613         file->append_tag();
614         file->append_newline();
615
616         file->tag.set_title("FOLDER");
617         file->append_tag();
618         file->append_text(folder);
619         file->tag.set_title("/FOLDER");
620         file->append_tag();
621         file->append_newline();
622
623 // Write the format information
624         file->tag.set_title("FORMAT");
625
626         file->tag.set_property("TYPE", 
627                 File::formattostr(format));
628         file->tag.set_property("USE_HEADER", use_header);
629         file->tag.set_property("FFORMAT", fformat);
630
631         file->append_tag();
632         file->append_newline();
633
634 // Requiring data to exist caused batch render to lose settings.
635 // But the only way to know if an asset doesn't have audio or video data 
636 // is to not write the block.
637 // So change the block name if the asset doesn't have the data.
638         write_audio(file);
639         write_video(file);
640 // index goes after source
641         if(index_state->index_status == INDEX_READY && include_index) 
642                 write_index(file);  
643
644         file->tag.set_title("/ASSET");
645         file->append_tag();
646         file->append_newline();
647         return 0;
648 }
649
650 int Asset::write_audio(FileXML *file)
651 {
652 // Let the reader know if the asset has the data by naming the block.
653         if(audio_data)
654                 file->tag.set_title("AUDIO");
655         else
656                 file->tag.set_title("AUDIO_OMIT");
657 // Necessary for PCM audio
658         file->tag.set_property("CHANNELS", channels);
659         file->tag.set_property("RATE", sample_rate);
660         file->tag.set_property("BITS", bits);
661         file->tag.set_property("BYTE_ORDER", byte_order);
662         file->tag.set_property("SIGNED", signed_);
663         file->tag.set_property("HEADER", header);
664         file->tag.set_property("DITHER", dither);
665         if(acodec[0])
666                 file->tag.set_property("ACODEC", acodec);
667         
668         file->tag.set_property("AUDIO_LENGTH", audio_length);
669
670
671
672 // Rely on defaults operations for these.
673
674 //      file->tag.set_property("AMPEG_BITRATE", ampeg_bitrate);
675 //      file->tag.set_property("AMPEG_DERIVATIVE", ampeg_derivative);
676 // 
677 //      file->tag.set_property("VORBIS_VBR", vorbis_vbr);
678 //      file->tag.set_property("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
679 //      file->tag.set_property("VORBIS_BITRATE", vorbis_bitrate);
680 //      file->tag.set_property("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
681 // 
682 //      file->tag.set_property("MP3_BITRATE", mp3_bitrate);
683 // 
684
685
686
687         file->append_tag();
688         file->append_newline();
689         return 0;
690 }
691
692 int Asset::write_video(FileXML *file)
693 {
694         if(video_data)
695                 file->tag.set_title("VIDEO");
696         else
697                 file->tag.set_title("VIDEO_OMIT");
698         file->tag.set_property("ACTUAL_HEIGHT", actual_height);
699         file->tag.set_property("ACTUAL_WIDTH", actual_width);
700         file->tag.set_property("HEIGHT", height);
701         file->tag.set_property("WIDTH", width);
702         file->tag.set_property("LAYERS", layers);
703         file->tag.set_property("PROGRAM", program);
704         file->tag.set_property("FRAMERATE", frame_rate);
705         if(vcodec[0])
706                 file->tag.set_property("VCODEC", vcodec);
707
708         file->tag.set_property("VIDEO_LENGTH", video_length);
709
710
711
712
713         file->append_tag();
714         file->append_newline();
715         return 0;
716 }
717
718 int Asset::write_index(FileXML *file)
719 {
720         index_state->write_xml(file);
721         return 0;
722 }
723
724
725
726
727 const char* Asset::construct_param(const char *param, 
728         const char *prefix, 
729         char *return_value)
730 {
731         if(prefix)
732                 sprintf(return_value, "%s%s", prefix, param);
733         else
734                 strcpy(return_value, param);
735         return return_value;
736 }
737
738 #define UPDATE_DEFAULT(x, y) defaults->update(construct_param(x, prefix, string), y);
739 #define GET_DEFAULT(x, y) defaults->get(construct_param(x, prefix, string), y);
740
741 void Asset::load_defaults(BC_Hash *defaults, 
742         const char *prefix, 
743         int do_format,
744         int do_compression,
745         int do_path,
746         int do_data_types,
747         int do_bits)
748 {
749         char string[BCTEXTLEN];
750
751 // Can't save codec here because it's specific to render, record, and effect.
752 // The codec has to be UNKNOWN for file probing to work.
753
754         if(do_path)
755         {
756                 GET_DEFAULT("PATH", path);
757         }
758
759         if(do_compression)
760         {
761                 GET_DEFAULT("AUDIO_CODEC", acodec);
762                 GET_DEFAULT("VIDEO_CODEC", vcodec);
763         }
764
765         if(do_format)
766         {
767                 format = GET_DEFAULT("FORMAT", format);
768                 use_header = GET_DEFAULT("USE_HEADER", use_header);
769                 GET_DEFAULT("FFORMAT", fformat);
770         }
771
772         if(do_data_types)
773         {
774                 audio_data = GET_DEFAULT("AUDIO", 1);
775                 video_data = GET_DEFAULT("VIDEO", 1);
776         }
777
778         if(do_bits)
779         {
780                 bits = GET_DEFAULT("BITS", 16);
781                 dither = GET_DEFAULT("DITHER", 0);
782                 signed_ = GET_DEFAULT("SIGNED", 1);
783                 byte_order = GET_DEFAULT("BYTE_ORDER", 1);
784
785
786
787 // Used by filefork
788                 channels = GET_DEFAULT("CHANNELS", 2);
789                 if(!sample_rate) sample_rate = GET_DEFAULT("RATE", 44100);
790                 header = GET_DEFAULT("HEADER", 0);
791                 audio_length = GET_DEFAULT("AUDIO_LENGTH", (int64_t)0);
792
793
794
795                 height = GET_DEFAULT("HEIGHT", height);
796                 width = GET_DEFAULT("WIDTH", width);
797                 actual_height = GET_DEFAULT("ACTUAL_HEIGHT", actual_height);
798                 actual_width = GET_DEFAULT("ACTUAL_WIDTH", actual_width);
799                 program = GET_DEFAULT("PROGRAM", program);
800                 layers = GET_DEFAULT("LAYERS", layers);
801                 if(EQUIV(frame_rate, 0)) frame_rate = GET_DEFAULT("FRAMERATE", frame_rate);
802                 video_length = GET_DEFAULT("VIDEO_LENGTH", (int64_t)0);
803         }
804
805         ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
806         ampeg_derivative = GET_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
807
808         vorbis_vbr = GET_DEFAULT("VORBIS_VBR", vorbis_vbr);
809         vorbis_min_bitrate = GET_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
810         vorbis_bitrate = GET_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
811         vorbis_max_bitrate = GET_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
812
813         theora_fix_bitrate = GET_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
814         theora_bitrate = GET_DEFAULT("THEORA_BITRATE", theora_bitrate);
815         theora_quality = GET_DEFAULT("THEORA_QUALITY", theora_quality);
816         theora_sharpness = GET_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
817         theora_keyframe_frequency = GET_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
818         theora_keyframe_force_frequency = GET_DEFAULT("THEORA_FORCE_KEYFRAME_FREQUENCY", theora_keyframe_force_frequency);
819
820         GET_DEFAULT("FF_AUDIO_OPTIONS", ff_audio_options);
821         ff_audio_bitrate = GET_DEFAULT("FF_AUDIO_BITRATE", ff_audio_bitrate);
822         GET_DEFAULT("FF_VIDEO_OPTIONS", ff_video_options);
823         ff_video_bitrate = GET_DEFAULT("FF_VIDEO_BITRATE", ff_video_bitrate);
824         ff_video_quality = GET_DEFAULT("FF_VIDEO_QUALITY", ff_video_quality);
825
826         mp3_bitrate = GET_DEFAULT("MP3_BITRATE", mp3_bitrate);
827         mp4a_bitrate = GET_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
828         mp4a_quantqual = GET_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
829
830         jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
831         aspect_ratio = GET_DEFAULT("ASPECT_RATIO", aspect_ratio);
832
833 // MPEG format information
834         vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
835         vmpeg_pframe_distance = GET_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
836         vmpeg_progressive = GET_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
837         vmpeg_denoise = GET_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
838         vmpeg_bitrate = GET_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
839         vmpeg_derivative = GET_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
840         vmpeg_quantization = GET_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
841         vmpeg_cmodel = GET_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
842         vmpeg_fix_bitrate = GET_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
843         vmpeg_seq_codes = GET_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
844         vmpeg_preset = GET_DEFAULT("VMPEG_PRESET", vmpeg_preset);
845         vmpeg_field_order = GET_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
846
847         h264_bitrate = GET_DEFAULT("H264_BITRATE", h264_bitrate);
848         h264_quantizer = GET_DEFAULT("H264_QUANTIZER", h264_quantizer);
849         h264_fix_bitrate = GET_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
850
851
852         divx_bitrate = GET_DEFAULT("DIVX_BITRATE", divx_bitrate);
853         divx_rc_period = GET_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
854         divx_rc_reaction_ratio = GET_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
855         divx_rc_reaction_period = GET_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
856         divx_max_key_interval = GET_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
857         divx_max_quantizer = GET_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
858         divx_min_quantizer = GET_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
859         divx_quantizer = GET_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
860         divx_quality = GET_DEFAULT("DIVX_QUALITY", divx_quality);
861         divx_fix_bitrate = GET_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
862         divx_use_deblocking = GET_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
863
864         ms_bitrate = GET_DEFAULT("MS_BITRATE", ms_bitrate);
865         ms_bitrate_tolerance = GET_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
866         ms_interlaced = GET_DEFAULT("MS_INTERLACED", ms_interlaced);
867         ms_quantization = GET_DEFAULT("MS_QUANTIZATION", ms_quantization);
868         ms_gop_size = GET_DEFAULT("MS_GOP_SIZE", ms_gop_size);
869         ms_fix_bitrate = GET_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
870
871         ac3_bitrate = GET_DEFAULT("AC3_BITRATE", ac3_bitrate);
872
873         png_use_alpha = GET_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
874         exr_use_alpha = GET_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
875         exr_compression = GET_DEFAULT("EXR_COMPRESSION", exr_compression);
876         tiff_cmodel = GET_DEFAULT("TIFF_CMODEL", tiff_cmodel);
877         tiff_compression = GET_DEFAULT("TIFF_COMPRESSION", tiff_compression);
878
879         boundaries();
880 }
881
882 void Asset::save_defaults(BC_Hash *defaults, 
883         const char *prefix,
884         int do_format,
885         int do_compression,
886         int do_path,
887         int do_data_types,
888         int do_bits)
889 {
890         char string[BCTEXTLEN];
891
892         UPDATE_DEFAULT("PATH", path);
893
894
895
896
897         if(do_format)
898         {
899                 UPDATE_DEFAULT("FORMAT", format);
900                 UPDATE_DEFAULT("USE_HEADER", use_header);
901                 UPDATE_DEFAULT("FFORMAT", fformat);
902         }
903
904         if(do_data_types)
905         {
906                 UPDATE_DEFAULT("AUDIO", audio_data);
907                 UPDATE_DEFAULT("VIDEO", video_data);
908         }
909
910         if(do_compression)
911         {
912                 UPDATE_DEFAULT("AUDIO_CODEC", acodec);
913                 UPDATE_DEFAULT("VIDEO_CODEC", vcodec);
914
915                 UPDATE_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
916                 UPDATE_DEFAULT("AMPEG_DERIVATIVE", ampeg_derivative);
917
918                 UPDATE_DEFAULT("VORBIS_VBR", vorbis_vbr);
919                 UPDATE_DEFAULT("VORBIS_MIN_BITRATE", vorbis_min_bitrate);
920                 UPDATE_DEFAULT("VORBIS_BITRATE", vorbis_bitrate);
921                 UPDATE_DEFAULT("VORBIS_MAX_BITRATE", vorbis_max_bitrate);
922
923                 UPDATE_DEFAULT("FF_AUDIO_OPTIONS", ff_audio_options);
924                 UPDATE_DEFAULT("FF_AUDIO_BITRATE", ff_audio_bitrate);
925                 UPDATE_DEFAULT("FF_VIDEO_OPTIONS", ff_video_options);
926                 UPDATE_DEFAULT("FF_VIDEO_BITRATE", ff_video_bitrate);
927                 UPDATE_DEFAULT("FF_VIDEO_QUALITY", ff_video_quality);
928
929                 UPDATE_DEFAULT("THEORA_FIX_BITRATE", theora_fix_bitrate);
930                 UPDATE_DEFAULT("THEORA_BITRATE", theora_bitrate);
931                 UPDATE_DEFAULT("THEORA_QUALITY", theora_quality);
932                 UPDATE_DEFAULT("THEORA_SHARPNESS", theora_sharpness);
933                 UPDATE_DEFAULT("THEORA_KEYFRAME_FREQUENCY", theora_keyframe_frequency);
934                 UPDATE_DEFAULT("THEORA_FORCE_KEYFRAME_FREQUENCY", theora_keyframe_force_frequency);
935
936
937
938                 UPDATE_DEFAULT("MP3_BITRATE", mp3_bitrate);
939                 UPDATE_DEFAULT("MP4A_BITRATE", mp4a_bitrate);
940                 UPDATE_DEFAULT("MP4A_QUANTQUAL", mp4a_quantqual);
941
942
943
944
945
946                 UPDATE_DEFAULT("JPEG_QUALITY", jpeg_quality);
947                 UPDATE_DEFAULT("ASPECT_RATIO", aspect_ratio);
948
949 // MPEG format information
950                 UPDATE_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
951                 UPDATE_DEFAULT("VMPEG_PFRAME_DISTANCE", vmpeg_pframe_distance);
952                 UPDATE_DEFAULT("VMPEG_PROGRESSIVE", vmpeg_progressive);
953                 UPDATE_DEFAULT("VMPEG_DENOISE", vmpeg_denoise);
954                 UPDATE_DEFAULT("VMPEG_BITRATE", vmpeg_bitrate);
955                 UPDATE_DEFAULT("VMPEG_DERIVATIVE", vmpeg_derivative);
956                 UPDATE_DEFAULT("VMPEG_QUANTIZATION", vmpeg_quantization);
957                 UPDATE_DEFAULT("VMPEG_CMODEL", vmpeg_cmodel);
958                 UPDATE_DEFAULT("VMPEG_FIX_BITRATE", vmpeg_fix_bitrate);
959                 UPDATE_DEFAULT("VMPEG_SEQ_CODES", vmpeg_seq_codes);
960                 UPDATE_DEFAULT("VMPEG_PRESET", vmpeg_preset);
961                 UPDATE_DEFAULT("VMPEG_FIELD_ORDER", vmpeg_field_order);
962
963                 UPDATE_DEFAULT("H264_BITRATE", h264_bitrate);
964                 UPDATE_DEFAULT("H264_QUANTIZER", h264_quantizer);
965                 UPDATE_DEFAULT("H264_FIX_BITRATE", h264_fix_bitrate);
966
967                 UPDATE_DEFAULT("DIVX_BITRATE", divx_bitrate);
968                 UPDATE_DEFAULT("DIVX_RC_PERIOD", divx_rc_period);
969                 UPDATE_DEFAULT("DIVX_RC_REACTION_RATIO", divx_rc_reaction_ratio);
970                 UPDATE_DEFAULT("DIVX_RC_REACTION_PERIOD", divx_rc_reaction_period);
971                 UPDATE_DEFAULT("DIVX_MAX_KEY_INTERVAL", divx_max_key_interval);
972                 UPDATE_DEFAULT("DIVX_MAX_QUANTIZER", divx_max_quantizer);
973                 UPDATE_DEFAULT("DIVX_MIN_QUANTIZER", divx_min_quantizer);
974                 UPDATE_DEFAULT("DIVX_QUANTIZER", divx_quantizer);
975                 UPDATE_DEFAULT("DIVX_QUALITY", divx_quality);
976                 UPDATE_DEFAULT("DIVX_FIX_BITRATE", divx_fix_bitrate);
977                 UPDATE_DEFAULT("DIVX_USE_DEBLOCKING", divx_use_deblocking);
978
979
980                 UPDATE_DEFAULT("MS_BITRATE", ms_bitrate);
981                 UPDATE_DEFAULT("MS_BITRATE_TOLERANCE", ms_bitrate_tolerance);
982                 UPDATE_DEFAULT("MS_INTERLACED", ms_interlaced);
983                 UPDATE_DEFAULT("MS_QUANTIZATION", ms_quantization);
984                 UPDATE_DEFAULT("MS_GOP_SIZE", ms_gop_size);
985                 UPDATE_DEFAULT("MS_FIX_BITRATE", ms_fix_bitrate);
986
987                 UPDATE_DEFAULT("AC3_BITRATE", ac3_bitrate);
988
989
990                 UPDATE_DEFAULT("PNG_USE_ALPHA", png_use_alpha);
991                 UPDATE_DEFAULT("EXR_USE_ALPHA", exr_use_alpha);
992                 UPDATE_DEFAULT("EXR_COMPRESSION", exr_compression);
993                 UPDATE_DEFAULT("TIFF_CMODEL", tiff_cmodel);
994                 UPDATE_DEFAULT("TIFF_COMPRESSION", tiff_compression);
995         }
996
997         if(do_bits)
998         {
999                 UPDATE_DEFAULT("BITS", bits);
1000                 UPDATE_DEFAULT("DITHER", dither);
1001                 UPDATE_DEFAULT("SIGNED", signed_);
1002                 UPDATE_DEFAULT("BYTE_ORDER", byte_order);
1003
1004
1005
1006
1007
1008
1009 // Used by filefork
1010                 UPDATE_DEFAULT("CHANNELS", channels);
1011                 UPDATE_DEFAULT("RATE", sample_rate);
1012                 UPDATE_DEFAULT("HEADER", header);
1013                 UPDATE_DEFAULT("AUDIO_LENGTH", audio_length);
1014
1015
1016
1017                 UPDATE_DEFAULT("HEIGHT", height);
1018                 UPDATE_DEFAULT("WIDTH", width);
1019                 UPDATE_DEFAULT("ACTUAL_HEIGHT", actual_height);
1020                 UPDATE_DEFAULT("ACTUAL_WIDTH", actual_width);
1021                 UPDATE_DEFAULT("PROGRAM", program);
1022                 UPDATE_DEFAULT("LAYERS", layers);
1023                 UPDATE_DEFAULT("FRAMERATE", frame_rate);
1024                 UPDATE_DEFAULT("VIDEO_LENGTH", video_length);
1025
1026         }
1027 }
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037 int Asset::update_path(char *new_path)
1038 {
1039         strcpy(path, new_path);
1040         return 0;
1041 }
1042
1043 void Asset::update_index(Asset *asset)
1044 {
1045         index_state->copy_from(asset->index_state);
1046 }
1047
1048
1049 int Asset::dump(FILE *fp)
1050 {
1051         fprintf(fp,"  asset::dump\n");
1052         fprintf(fp,"   this=%p path=%s\n", this, path);
1053         fprintf(fp,"   index_status %d\n", index_state->index_status);
1054         fprintf(fp,"   format %d\n", format);
1055         fprintf(fp,"   fformat=\"%s\"\n", fformat);
1056         fprintf(fp,"   ff_audio_options=\"%s\"\n", ff_audio_options);
1057         fprintf(fp,"   ff_audio_bitrate=%d\n", ff_audio_bitrate);
1058         fprintf(fp,"   ff_video_options=\"%s\"\n", ff_video_options);
1059         fprintf(fp,"   ff_video_bitrate=%d\n", ff_video_bitrate);
1060         fprintf(fp,"   ff_video_quality=%d\n", ff_video_quality);
1061         fprintf(fp,"   audio_data %d channels %d samplerate %d bits %d"
1062                 " byte_order %d signed %d header %d dither %d acodec %c%c%c%c\n",
1063                 audio_data, channels, sample_rate, bits, byte_order, signed_,
1064                 header, dither, acodec[0], acodec[1], acodec[2], acodec[3]);
1065         fprintf(fp,"   audio_length " _LD "\n", audio_length);
1066         fprintf(fp,"   video_data %d program %d layers %d framerate %f width %d"
1067                 " height %d vcodec %c%c%c%c aspect_ratio %f\n",
1068                 video_data, layers, program, frame_rate, width, height,
1069                 vcodec[0], vcodec[1], vcodec[2], vcodec[3], aspect_ratio);
1070         fprintf(fp,"   video_length " _LD " \n", video_length);
1071         fprintf(fp,"   ms_bitrate_tolerance=%d\n", ms_bitrate_tolerance);
1072         fprintf(fp,"   ms_quantization=%d\n", ms_quantization);
1073         fprintf(fp,"   ms_fix_bitrate=%d\n", ms_fix_bitrate);
1074         fprintf(fp,"   ms_interlaced=%d\n", ms_interlaced);
1075         fprintf(fp,"   h264_bitrate=%d\n", h264_bitrate);
1076         fprintf(fp,"   h264_quantizer=%d\n", h264_quantizer);
1077         fprintf(fp,"   h264_fix_bitrate=%d\n", h264_fix_bitrate);
1078         return 0;
1079 }
1080
1081
1082 // For Indexable
1083 int Asset::get_audio_channels()
1084 {
1085         return channels;
1086 }
1087
1088 int Asset::get_sample_rate()
1089 {
1090         return sample_rate;
1091 }
1092
1093 int64_t Asset::get_audio_samples()
1094 {
1095         return audio_length;
1096 }
1097
1098 int Asset::have_audio()
1099 {
1100         return audio_data;
1101 }
1102
1103 int Asset::have_video()
1104 {
1105         return video_data;
1106 }
1107
1108 int Asset::get_w()
1109 {
1110         return width;
1111 }
1112
1113 int Asset::get_h()
1114 {
1115         return height;
1116 }
1117
1118 double Asset::get_frame_rate()
1119 {
1120         return frame_rate;
1121 }
1122
1123
1124 int Asset::get_video_layers()
1125 {
1126         return layers;
1127 }
1128
1129 int Asset::get_program()
1130 {
1131         return program;
1132 }
1133
1134 int64_t Asset::get_video_frames()
1135 {
1136         return video_length;
1137 }