1 /* General codec for all MPEG-4 derived encoding. */
2 /* Uses ffmpeg and encore50. */
3 /* Encore50 still seemed to provide better results than ffmpeg for encoding */
4 /* so it does all the generic MPEG-4 encoding. */
11 #include "colormodels.h"
12 #include "funcprotos.h"
14 #include "quicktime.h"
15 #include "workarounds.h"
16 #include ENCORE_INCLUDE
17 //#include DECORE_INCLUDE
26 #define FRAME_RATE_BASE 10000
34 quicktime_ffmpeg_t
*decoder
;
45 int encode_initialized
[FIELDS
];
46 // Information for picking the right library routines.
47 // ID out of avcodec.h for the codec used.
48 // Invalid if encore50 is used.
50 // True if encore50 is being used.
54 AVCodec
*encoder
[FIELDS
];
55 AVCodecContext
*encoder_context
[FIELDS
];
56 AVFrame picture
[FIELDS
];
60 int encode_handle
[FIELDS
];
61 ENC_PARAM enc_param
[FIELDS
];
62 // Must count pframes in VBR
66 // Encoding parameters
68 // For heroine 60 encoding, we want different streams for each field.
70 long rc_period
; // the intended rate control averaging period
71 long rc_reaction_period
; // the reation period for rate control
72 long rc_reaction_ratio
; // the ratio for down/up rate control
73 long max_key_interval
; // the maximum interval between key frames
74 int bitrate_tolerance
;
77 int max_quantizer
; // the upper limit of the quantizer
78 int min_quantizer
; // the lower limit of the quantizer
79 int quantizer
; // For vbr
80 int quality
; // the forward search range for motion estimation
85 // Temporary storage for color conversions
87 // Storage of compressed data
88 unsigned char *work_buffer
;
89 // Allocation of work_buffer
91 } quicktime_mpeg4_codec_t
;
95 // Decore needs the user to specify handles
96 static int decode_handle
= 1;
97 static int encode_handle
= 0;
107 // Direct copy routines
110 // Determine of the compressed frame is a keyframe for direct copy
111 int quicktime_mpeg4_is_key(unsigned char *data
, long size
, char *codec_id
)
116 if(quicktime_match_32(codec_id
, QUICKTIME_DIVX
) ||
117 quicktime_match_32(codec_id
, QUICKTIME_MP4V
) ||
118 quicktime_match_32(codec_id
, QUICKTIME_HV60
))
120 for(i
= 0; i
< size
- 5; i
++)
122 if( data
[i
] == 0x00 &&
123 data
[i
+ 1] == 0x00 &&
124 data
[i
+ 2] == 0x01 &&
127 if((data
[i
+ 4] & 0xc0) == 0x0)
138 // Test for VOL header in frame
139 int quicktime_mpeg4_has_vol(unsigned char *data
)
141 if( data
[0] == 0x00 &&
157 static void putbits(unsigned char **data
,
164 value
&= 0xffffffffffffffffLL
>> (64 - count
);
166 while(64 - *bit_pos
< count
)
168 *(*data
)++ = (*bit_store
) >> 56;
173 (*bit_store
) |= value
<< (64 - count
- *bit_pos
);
179 static void flushbits(unsigned char **data
,
183 //printf("flushbits %llx\n", (*bit_store));
184 while((*bit_pos
) > 0)
186 *(*data
)++ = (*bit_store
) >> 56;
195 #define VO_START_CODE 0x8
196 #define VO_START_CODE_LENGTH 27
197 #define VOL_START_CODE 0x12 /* 25-MAR-97 JDL : according to WD2 */
198 #define VOL_START_CODE_LENGTH 28
202 int quicktime_mpeg4_write_vol(unsigned char *data_start
,
205 int time_increment_resolution
,
209 int bits
, fixed_vop_time_increment
;
210 unsigned char *data
= data_start
;
217 vol_width
= quicktime_quantize16(vol_width
);
218 vol_height
= quicktime_quantize16(vol_height
);
225 VO_START_CODE_LENGTH
, VO_START_CODE
);
230 5, 0); /* vo_id = 0 */
236 VOL_START_CODE_LENGTH
, VOL_START_CODE
);
244 4, 0); /* vol_id = 0 */
250 1, 0); /* random_accessible_vol = 0 */
255 8, 1); /* video_object_type_indication = 1 video */
260 1, 1); /* is_object_layer_identifier = 1 */
265 4, 2); /* visual_object_layer_ver_id = 2 */
270 3, 1); /* visual_object_layer_priority = 1 */
275 4, 1); /* aspect_ratio_info = 1 */
287 1, 0); /* vol_control_parameter = 0 */
292 2, 0); /* vol_shape = 0 rectangular */
309 16, time_increment_resolution
);
319 1, 1); /* fixed_vop_rate = 1 */
323 while((1 << bits
) < time_increment_resolution
) bits
++;
325 // Log calculation fails for some reason
326 // bits = (int)ceil(log((double)time_increment_resolution) / log(2.0));
327 // if (bits < 1) bits=1;
329 fixed_vop_time_increment
=
330 (int)(time_increment_resolution
/ frame_rate
+ 0.1);
336 bits
, fixed_vop_time_increment
);
369 1, 0); /* interlaced = 0 */
374 1, 1); /* OBMC_disabled = 1 */
379 2, 0); /* vol_sprite_usage = 0 */
384 1, 0); /* not_8_bit = 0 */
390 1, 0); /* vol_quant_type = 0 */
395 1, 0); /* vol_quarter_pixel = 0 */
400 1, 1); /* complexity_estimation_disabled = 1 */
405 1, 1); /* resync_marker_disabled = 1 */
410 1, 0); /* data_partitioning_enabled = 0 */
415 1, 0); /* scalability = 0 */
423 * for(i = 0; i < data - data_start; i++)
424 * for(j = 0x80; j >= 1; j /= 2)
425 * printf("%d", (data_start[i] & j) ? 1 : 0);
431 return data
- data_start
;
436 // Create the header for the esds block which is used in mp4v.
437 // Taken from libavcodec
439 static int write_mp4v_header(unsigned char *data
,
444 unsigned char *start
= data
;
448 * static unsigned char test[] =
451 * 0x00, 0x00, 0x01, 0xb0, 0x01, 0x00, 0x00, 0x01, 0xb5, 0x89, 0x13,
452 * 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 0x00, 0xc4, 0x8d,
453 * 0x8a, 0xee, 0x05, 0x28, 0x04, 0x5a, 0x14, 0x63, 0x00, 0x00, 0x01, 0xb2,
454 * 0x46, 0x46, 0x6d, 0x70, 0x65, 0x67, 0x43, 0x56, 0x53, 0x62, 0x34, 0x37,
458 * memcpy(data, test, sizeof(test));
460 * return sizeof(test);
464 // Advanced simple level 1
465 // int profile_level = 0xf3;
467 int profile_level
= 0x1;
468 // int vo_version_id = 5;
469 int vo_version_id
= 1;
480 *data
++ = profile_level
;
482 // Visual object startcode
487 *data
++ = ((unsigned char)0x1 << 7) |
488 ((unsigned char)vo_version_id
<< 3) |
491 // visual object type video
492 *data
++ = (0x1 << 4) |
503 int vol_size
= quicktime_mpeg4_write_vol(data
,
521 static int reads_colormodel(quicktime_t
*file
,
525 quicktime_video_map_t
*vtrack
= &(file
->vtracks
[track
]);
526 quicktime_codec_t
*codec
= (quicktime_codec_t
*)vtrack
->codec
;
527 return (colormodel
== BC_YUV420P
&&
528 !quicktime_match_32(QUICKTIME_SVQ1
, codec
->fourcc
));
531 static int writes_colormodel(quicktime_t
*file
,
535 return colormodel
== BC_YUV420P
;
540 static int decode(quicktime_t
*file
, unsigned char **row_pointers
, int track
)
542 quicktime_video_map_t
*vtrack
= &(file
->vtracks
[track
]);
543 quicktime_trak_t
*trak
= vtrack
->track
;
544 quicktime_mpeg4_codec_t
*codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
545 quicktime_stsd_table_t
*stsd_table
= &trak
->mdia
.minf
.stbl
.stsd
.table
[0];
546 int width
= trak
->tkhd
.track_width
;
547 int height
= trak
->tkhd
.track_height
;
551 if(!codec
->decoder
) codec
->decoder
= quicktime_new_ffmpeg(
559 if(codec
->decoder
) result
= quicktime_ffmpeg_decode(
570 static int encode(quicktime_t
*file
, unsigned char **row_pointers
, int track
)
572 int64_t offset
= quicktime_position(file
);
573 quicktime_video_map_t
*vtrack
= &(file
->vtracks
[track
]);
574 quicktime_mpeg4_codec_t
*codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
575 quicktime_trak_t
*trak
= vtrack
->track
;
576 int width
= trak
->tkhd
.track_width
;
577 int height
= trak
->tkhd
.track_height
;
578 int width_i
= quicktime_quantize16(width
);
579 int height_i
= quicktime_quantize16(height
);
584 int current_field
= vtrack
->current_position
% codec
->total_fields
;
585 quicktime_atom_t chunk_atom
;
591 pthread_mutex_lock(&ffmpeg_lock
);
595 if(!codec
->encode_initialized
[current_field
])
598 if(codec
->ffmpeg_id
== CODEC_ID_MPEG4
&& codec
->use_encore
)
600 codec
->encode_initialized
[current_field
] = 1;
601 codec
->encode_handle
[current_field
] = encode_handle
++;
602 codec
->enc_param
[current_field
].x_dim
= width_i
;
603 codec
->enc_param
[current_field
].y_dim
= height_i
;
604 codec
->enc_param
[current_field
].framerate
=
605 quicktime_frame_rate(file
, track
) / codec
->total_fields
;
606 codec
->enc_param
[current_field
].bitrate
=
607 codec
->bitrate
/ codec
->total_fields
;
608 codec
->enc_param
[current_field
].rc_period
= codec
->rc_period
;
609 codec
->enc_param
[current_field
].rc_reaction_period
= codec
->rc_reaction_period
;
610 codec
->enc_param
[current_field
].rc_reaction_ratio
= codec
->rc_reaction_ratio
;
611 codec
->enc_param
[current_field
].max_quantizer
= codec
->max_quantizer
;
612 codec
->enc_param
[current_field
].min_quantizer
= codec
->min_quantizer
;
613 codec
->enc_param
[current_field
].max_key_interval
= codec
->max_key_interval
;
615 codec
->enc_param
[current_field
].search_range
= codec
->quality
* 3;
616 if(codec
->enc_param
[current_field
].search_range
> 15)
617 codec
->enc_param
[current_field
].search_range
= 15;
619 encore(codec
->encode_handle
[current_field
],
621 &codec
->enc_param
[current_field
], NULL
);
627 static char *video_rc_eq
="tex^qComp";
628 codec
->encode_initialized
[current_field
] = 1;
629 if(!ffmpeg_initialized
)
631 ffmpeg_initialized
= 1;
633 avcodec_register_all();
636 codec
->encoder
[current_field
] = avcodec_find_encoder(codec
->ffmpeg_id
);
637 if(!codec
->encoder
[current_field
])
639 printf("encode: avcodec_find_encoder returned NULL.\n");
640 pthread_mutex_unlock(&ffmpeg_lock
);
644 codec
->encoder_context
[current_field
] = avcodec_alloc_context();
645 AVCodecContext
*context
= codec
->encoder_context
[current_field
];
647 context
->width
= width_i
;
648 context
->height
= height_i
;
649 context
->gop_size
= codec
->gop_size
;
650 context
->pix_fmt
= PIX_FMT_YUV420P
;
651 context
->bit_rate
= codec
->bitrate
/ codec
->total_fields
;
652 context
->bit_rate_tolerance
= codec
->bitrate_tolerance
;
653 context
->rc_eq
= video_rc_eq
;
654 context
->rc_max_rate
= 0;
655 context
->rc_min_rate
= 0;
656 context
->rc_buffer_size
= 0;
658 (!codec
->fix_bitrate
? codec
->quantizer
: 2);
660 (!codec
->fix_bitrate
? codec
->quantizer
: 31);
661 context
->lmin
= 2 * FF_QP2LAMBDA
;
662 context
->lmax
= 31 * FF_QP2LAMBDA
;
663 context
->mb_lmin
= 2 * FF_QP2LAMBDA
;
664 context
->mb_lmax
= 31 * FF_QP2LAMBDA
;
665 context
->max_qdiff
= 3;
666 context
->qblur
= 0.5;
667 context
->qcompress
= 0.5;
668 // It needs the time per frame, not the frame rate.
669 context
->time_base
.den
= quicktime_frame_rate_n(file
, track
);
670 context
->time_base
.num
= quicktime_frame_rate_d(file
, track
);
672 context
->b_quant_factor
= 1.25;
673 context
->b_quant_offset
= 1.25;
674 context
->error_resilience
= FF_ER_CAREFULL
;
675 context
->error_concealment
= 3;
676 context
->frame_skip_cmp
= FF_CMP_DCTMAX
;
677 context
->ildct_cmp
= FF_CMP_VSAD
;
678 context
->intra_dc_precision
= 0;
679 context
->intra_quant_bias
= FF_DEFAULT_QUANT_BIAS
;
680 context
->inter_quant_bias
= FF_DEFAULT_QUANT_BIAS
;
681 context
->i_quant_factor
= -0.8;
682 context
->i_quant_offset
= 0.0;
683 context
->mb_decision
= FF_MB_DECISION_SIMPLE
;
684 context
->mb_cmp
= FF_CMP_SAD
;
685 context
->me_sub_cmp
= FF_CMP_SAD
;
686 context
->me_cmp
= FF_CMP_SAD
;
687 context
->me_pre_cmp
= FF_CMP_SAD
;
688 context
->me_method
= ME_EPZS
;
689 context
->me_subpel_quality
= 8;
690 context
->me_penalty_compensation
= 256;
691 context
->me_range
= 0;
692 context
->me_threshold
= 0;
693 context
->mb_threshold
= 0;
694 context
->nsse_weight
= 8;
695 context
->profile
= FF_PROFILE_UNKNOWN
;
696 context
->rc_buffer_aggressivity
= 1.0;
697 context
->level
= FF_LEVEL_UNKNOWN
;
698 context
->flags
|= CODEC_FLAG_H263P_UMV
;
699 context
->flags
|= CODEC_FLAG_AC_PRED
;
700 context
->flags
|= CODEC_FLAG_4MV
;
701 // Not compatible with Win
702 // context->flags |= CODEC_FLAG_QPEL;
706 avcodec_thread_init(context
, file
->cpus
);
707 context
->thread_count
= file
->cpus
;
710 if(!codec
->fix_bitrate
)
711 context
->flags
|= CODEC_FLAG_QSCALE
;
713 if(codec
->interlaced
)
715 context
->flags
|= CODEC_FLAG_INTERLACED_DCT
;
716 context
->flags
|= CODEC_FLAG_INTERLACED_ME
;
721 * printf("encode gop_size=%d fix_bitrate=%d quantizer=%d\n",
723 * codec->fix_bitrate,
726 avcodec_open(context
, codec
->encoder
[current_field
]);
728 avcodec_get_frame_defaults(&codec
->picture
[current_field
]);
734 if(!codec
->work_buffer
)
736 codec
->buffer_size
= width_i
* height_i
;
737 codec
->work_buffer
= malloc(codec
->buffer_size
);
743 if(codec
->use_encore
)
746 ENC_FRAME encore_input
;
747 ENC_RESULT encore_result
;
750 // Assume planes are contiguous.
751 // Encode directly from function arguments
752 if(file
->color_model
== BC_YUV420P
&&
756 encore_input
.image
= row_pointers
[0];
758 // Convert to YUV420P
759 // Encode from temporary.
762 if(!codec
->temp_frame
)
764 codec
->temp_frame
= malloc(width_i
* height_i
* 3 / 2);
767 cmodel_transfer(0, /* Leave NULL if non existent */
769 codec
->temp_frame
, /* Leave NULL if non existent */
770 codec
->temp_frame
+ width_i
* height_i
,
771 codec
->temp_frame
+ width_i
* height_i
+ width_i
* height_i
/ 4,
772 row_pointers
[0], /* Leave NULL if non existent */
775 0, /* Dimensions to capture from input frame */
779 0, /* Dimensions to project on output frame */
785 0, /* When transfering BC_RGBA8888 to non-alpha this is the background color in 0xRRGGBB hex */
786 width
, /* For planar use the luma rowspan */
790 encore_input
.image
= codec
->temp_frame
;
795 bzero(codec
->work_buffer
, codec
->buffer_size
);
796 encore_input
.bitstream
= codec
->work_buffer
;
797 encore_input
.length
= 0;
798 encore_input
.quant
= !codec
->fix_bitrate
? codec
->quantizer
: 0;
800 if(codec
->p_count
== 0)
802 codec
->p_count
[current_field
]++;
806 codec
->p_count
[current_field
]++;
807 if(codec
->p_count
[current_field
] >= codec
->max_key_interval
)
808 codec
->p_count
[current_field
] = 0;
812 encore(codec
->encode_handle
[current_field
],
817 bytes
= encore_input
.length
;
818 is_keyframe
= encore_result
.isKeyFrame
;
823 AVCodecContext
*context
= codec
->encoder_context
[current_field
];
824 AVFrame
*picture
= &codec
->picture
[current_field
];
826 if(width_i
== width
&&
827 height_i
== height
&&
828 file
->color_model
== BC_YUV420P
)
830 picture
->data
[0] = row_pointers
[0];
831 picture
->data
[1] = row_pointers
[1];
832 picture
->data
[2] = row_pointers
[2];
833 picture
->linesize
[0] = width_i
;
834 picture
->linesize
[1] = width_i
/ 2;
835 picture
->linesize
[2] = width_i
/ 2;
839 if(!codec
->temp_frame
)
841 codec
->temp_frame
= malloc(width_i
* height_i
* 3 / 2);
844 cmodel_transfer(0, /* Leave NULL if non existent */
846 codec
->temp_frame
, /* Leave NULL if non existent */
847 codec
->temp_frame
+ width_i
* height_i
,
848 codec
->temp_frame
+ width_i
* height_i
+ width_i
* height_i
/ 4,
849 row_pointers
[0], /* Leave NULL if non existent */
852 0, /* Dimensions to capture from input frame */
856 0, /* Dimensions to project on output frame */
862 0, /* When transfering BC_RGBA8888 to non-alpha this is the background color in 0xRRGGBB hex */
863 width
, /* For planar use the luma rowspan */
866 picture
->data
[0] = codec
->temp_frame
;
867 picture
->data
[1] = codec
->temp_frame
+ width_i
* height_i
;
868 picture
->data
[2] = codec
->temp_frame
+ width_i
* height_i
+ width_i
* height_i
/ 4;
869 picture
->linesize
[0] = width_i
;
870 picture
->linesize
[1] = width_i
/ 2;
871 picture
->linesize
[2] = width_i
/ 2;
875 picture
->pict_type
= 0;
876 picture
->quality
= 0;
877 picture
->pts
= vtrack
->current_position
* quicktime_frame_rate_d(file
, track
);
878 picture
->key_frame
= 0;
879 bytes
= avcodec_encode_video(context
,
883 is_keyframe
= context
->coded_frame
&& context
->coded_frame
->key_frame
;
885 * printf("encode current_position=%d is_keyframe=%d\n",
886 * vtrack->current_position,
890 if(!trak
->mdia
.minf
.stbl
.stsd
.table
[0].esds
.mpeg4_header_size
&&
891 !strcmp(((quicktime_codec_t
*)vtrack
->codec
)->fourcc
, QUICKTIME_MP4V
))
893 unsigned char temp
[1024];
894 unsigned char *ptr
= temp
;
895 for(i
= 0; i
< bytes
- 4; i
++)
897 if(!(codec
->work_buffer
[i
] == 0x00 &&
898 codec
->work_buffer
[i
+ 1] == 0x00 &&
899 codec
->work_buffer
[i
+ 2] == 0x01 &&
900 codec
->work_buffer
[i
+ 3] == 0xb3))
902 *ptr
++ = codec
->work_buffer
[i
];
907 quicktime_set_mpeg4_header(&trak
->mdia
.minf
.stbl
.stsd
.table
[0],
910 trak
->mdia
.minf
.stbl
.stsd
.table
[0].version
= 0;
919 pthread_mutex_unlock(&ffmpeg_lock
);
920 quicktime_write_chunk_header(file
, trak
, &chunk_atom
);
921 result
= !quicktime_write_data(file
,
924 quicktime_write_chunk_footer(file
,
926 vtrack
->current_chunk
,
929 if(is_keyframe
|| vtrack
->current_position
== 0)
930 quicktime_insert_keyframe(file
,
931 vtrack
->current_position
,
934 vtrack
->current_chunk
++;
943 static void flush(quicktime_t
*file
, int track
)
945 quicktime_video_map_t
*track_map
= &(file
->vtracks
[track
]);
946 quicktime_trak_t
*trak
= track_map
->track
;
947 quicktime_mpeg4_codec_t
*codec
= ((quicktime_codec_t
*)track_map
->codec
)->priv
;
950 if(!trak
->mdia
.minf
.stbl
.stsd
.table
[0].esds
.mpeg4_header_size
&&
951 !strcmp(((quicktime_codec_t
*)track_map
->codec
)->fourcc
, QUICKTIME_MP4V
))
953 int width
= trak
->tkhd
.track_width
;
954 int height
= trak
->tkhd
.track_height
;
955 int width_i
= quicktime_quantize16(width
);
956 int height_i
= quicktime_quantize16(height
);
958 unsigned char temp
[1024];
959 int size
= write_mp4v_header(temp
,
962 quicktime_frame_rate(file
, track
));
963 quicktime_set_mpeg4_header(&trak
->mdia
.minf
.stbl
.stsd
.table
[0],
969 file
->moov
.udta
.require
= strdup("QuickTime 6.0 or greater");
970 file
->moov
.udta
.require_len
= strlen(file
->moov
.udta
.require
);
980 static int set_parameter(quicktime_t
*file
,
985 quicktime_video_map_t
*vtrack
= &(file
->vtracks
[track
]);
986 char *compressor
= vtrack
->track
->mdia
.minf
.stbl
.stsd
.table
[0].format
;
988 if(quicktime_match_32(compressor
, QUICKTIME_DIVX
) ||
989 quicktime_match_32(compressor
, QUICKTIME_MP42
) ||
990 quicktime_match_32(compressor
, QUICKTIME_MPG4
) ||
991 quicktime_match_32(compressor
, QUICKTIME_DX50
) ||
992 quicktime_match_32(compressor
, QUICKTIME_HV60
))
994 quicktime_mpeg4_codec_t
*codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
996 if(!strcasecmp(key
, "divx_bitrate"))
997 codec
->bitrate
= *(int*)value
;
999 if(!strcasecmp(key
, "divx_rc_period"))
1000 codec
->rc_period
= *(int*)value
;
1002 if(!strcasecmp(key
, "divx_rc_reaction_ratio"))
1003 codec
->rc_reaction_ratio
= *(int*)value
;
1005 if(!strcasecmp(key
, "divx_rc_reaction_period"))
1006 codec
->rc_reaction_period
= *(int*)value
;
1008 if(!strcasecmp(key
, "divx_max_key_interval"))
1009 codec
->max_key_interval
= *(int*)value
;
1011 if(!strcasecmp(key
, "divx_max_quantizer"))
1012 codec
->max_quantizer
= *(int*)value
;
1014 if(!strcasecmp(key
, "divx_min_quantizer"))
1015 codec
->min_quantizer
= *(int*)value
;
1017 if(!strcasecmp(key
, "divx_quantizer"))
1018 codec
->quantizer
= *(int*)value
;
1020 if(!strcasecmp(key
, "divx_quality"))
1021 codec
->quality
= *(int*)value
;
1023 if(!strcasecmp(key
, "divx_fix_bitrate"))
1024 codec
->fix_bitrate
= *(int*)value
;
1026 if(!strcasecmp(key
, "divx_use_deblocking"))
1027 codec
->use_deblocking
= *(int*)value
;
1030 if(quicktime_match_32(compressor
, QUICKTIME_DIV3
) ||
1031 quicktime_match_32(compressor
, QUICKTIME_MP4V
))
1033 quicktime_mpeg4_codec_t
*codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
1034 if(!strcasecmp(key
, "ffmpeg_bitrate"))
1035 codec
->bitrate
= *(int*)value
;
1037 if(!strcasecmp(key
, "ffmpeg_bitrate_tolerance"))
1038 codec
->bitrate_tolerance
= *(int*)value
;
1040 if(!strcasecmp(key
, "ffmpeg_interlaced"))
1041 codec
->interlaced
= *(int*)value
;
1043 if(!strcasecmp(key
, "ffmpeg_gop_size"))
1044 codec
->gop_size
= *(int*)value
;
1046 if(!strcasecmp(key
, "ffmpeg_quantizer"))
1047 codec
->quantizer
= *(int*)value
;
1049 if(!strcasecmp(key
, "ffmpeg_fix_bitrate"))
1050 codec
->fix_bitrate
= *(int*)value
;
1057 static int delete_codec(quicktime_video_map_t
*vtrack
)
1059 quicktime_mpeg4_codec_t
*codec
;
1063 codec
= ((quicktime_codec_t
*)vtrack
->codec
)->priv
;
1064 for(i
= 0; i
< codec
->total_fields
; i
++)
1066 if(codec
->encode_initialized
[i
])
1068 pthread_mutex_lock(&ffmpeg_lock
);
1069 if(codec
->use_encore
)
1071 encore(codec
->encode_handle
[i
],
1078 avcodec_close(codec
->encoder_context
[i
]);
1079 free(codec
->encoder_context
[i
]);
1081 pthread_mutex_unlock(&ffmpeg_lock
);
1086 if(codec
->temp_frame
) free(codec
->temp_frame
);
1087 if(codec
->work_buffer
) free(codec
->work_buffer
);
1088 if(codec
->decoder
) quicktime_delete_ffmpeg(codec
->decoder
);
1097 static quicktime_mpeg4_codec_t
* init_common(quicktime_video_map_t
*vtrack
,
1102 quicktime_codec_t
*codec_base
= (quicktime_codec_t
*)vtrack
->codec
;
1103 quicktime_mpeg4_codec_t
*codec
;
1105 codec_base
->priv
= calloc(1, sizeof(quicktime_mpeg4_codec_t
));
1106 codec_base
->delete_vcodec
= delete_codec
;
1107 codec_base
->decode_video
= decode
;
1108 codec_base
->encode_video
= encode
;
1109 codec_base
->flush
= flush
;
1110 codec_base
->reads_colormodel
= reads_colormodel
;
1111 codec_base
->writes_colormodel
= writes_colormodel
;
1112 codec_base
->set_parameter
= set_parameter
;
1113 codec_base
->fourcc
= compressor
;
1114 codec_base
->title
= title
;
1115 codec_base
->desc
= description
;
1117 codec
= (quicktime_mpeg4_codec_t
*)codec_base
->priv
;
1122 codec
->bitrate
= 1000000;
1123 codec
->rc_period
= 50;
1124 codec
->rc_reaction_ratio
= 45;
1125 codec
->rc_reaction_period
= 10;
1126 codec
->max_key_interval
= 45;
1127 codec
->max_quantizer
= 31;
1128 codec
->min_quantizer
= 1;
1129 codec
->quantizer
= 10;
1131 codec
->fix_bitrate
= 1;
1132 codec
->total_fields
= 1;
1142 // Mike Rowe Soft MPEG-4
1143 void quicktime_init_codec_div3(quicktime_video_map_t
*vtrack
)
1145 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1148 "Mike Row Soft MPEG4 Version 3");
1149 result
->ffmpeg_id
= CODEC_ID_MSMPEG4V3
;
1152 void quicktime_init_codec_div5(quicktime_video_map_t
*vtrack
)
1154 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1157 "Mike Row Soft MPEG4 Version 5");
1158 result
->ffmpeg_id
= CODEC_ID_MPEG4
;
1161 // Mike Rowe Soft MPEG-4
1162 void quicktime_init_codec_div3lower(quicktime_video_map_t
*vtrack
)
1164 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1165 QUICKTIME_DIV3_LOWER
,
1167 "Mike Row Soft MPEG4 Version 3");
1168 result
->ffmpeg_id
= CODEC_ID_MSMPEG4V3
;
1171 void quicktime_init_codec_div3v2(quicktime_video_map_t
*vtrack
)
1173 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1176 "Mike Row Soft MPEG4 Version 2");
1177 result
->ffmpeg_id
= CODEC_ID_MSMPEG4V2
;
1181 void quicktime_init_codec_divx(quicktime_video_map_t
*vtrack
)
1183 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1186 "Generic MPEG Four");
1187 result
->ffmpeg_id
= CODEC_ID_MPEG4
;
1188 result
->use_encore
= 1;
1191 void quicktime_init_codec_mpg4(quicktime_video_map_t
*vtrack
)
1193 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1196 "FFMPEG (msmpeg4)");
1197 result
->ffmpeg_id
= CODEC_ID_MSMPEG4V1
;
1200 void quicktime_init_codec_dx50(quicktime_video_map_t
*vtrack
)
1202 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1206 result
->ffmpeg_id
= CODEC_ID_MPEG4
;
1210 void quicktime_init_codec_mp4v(quicktime_video_map_t
*vtrack
)
1212 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1215 "Generic MPEG Four");
1216 result
->ffmpeg_id
= CODEC_ID_MPEG4
;
1217 // result->use_encore = 1;
1222 void quicktime_init_codec_svq1(quicktime_video_map_t
*vtrack
)
1224 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1226 "Sorenson Version 1",
1227 "From the chearch of codecs of yesterday's sights");
1228 result
->ffmpeg_id
= CODEC_ID_SVQ1
;
1231 void quicktime_init_codec_svq3(quicktime_video_map_t
*vtrack
)
1233 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1235 "Sorenson Version 3",
1236 "From the chearch of codecs of yesterday's sights");
1237 result
->ffmpeg_id
= CODEC_ID_SVQ3
;
1240 void quicktime_init_codec_h263(quicktime_video_map_t
*vtrack
)
1242 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1246 result
->ffmpeg_id
= CODEC_ID_H263
;
1249 void quicktime_init_codec_xvid(quicktime_video_map_t
*vtrack
)
1251 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1255 result
->ffmpeg_id
= CODEC_ID_MPEG4
;
1258 // field based MPEG-4
1259 void quicktime_init_codec_hv60(quicktime_video_map_t
*vtrack
)
1261 quicktime_mpeg4_codec_t
*result
= init_common(vtrack
,
1264 "MPEG 4 with alternating streams every other frame. (Not standardized)");
1265 result
->total_fields
= 2;
1266 result
->ffmpeg_id
= CODEC_ID_MPEG4
;