Ticket #40464: libquicktime-cvs.diff

File libquicktime-cvs.diff, 71.5 KB (added by mojca (Mojca Miklavec), 11 years ago)

full patch against CVS

  • configure.ac

     
    99
    1010USER_CFLAGS=$CFLAGS
    1111
    12 AM_CONFIG_HEADER(config.h)
     12dnl AM_CONFIG_HEADER(config.h)
     13AC_CONFIG_HEADERS(config.h)
    1314
    1415AC_CANONICAL_HOST
    1516AM_MAINTAINER_MODE
     
    3940dnl Libquicktime codec API version
    4041dnl
    4142
    42 LQT_CODEC_API_VERSION="12"
     43LQT_CODEC_API_VERSION="13"
    4344
    4445AH_TEMPLATE([HAVE_GPL], [Enable GPL code])
    4546AH_TEMPLATE([LQT_CODEC_API_VERSION],
  • include/colorspace_macros.h

     
    372372/* YUV (10 bit) -> 8 */
    373373
    374374#define YUV_10_TO_RGB_24(y,u,v,r,g,b) \
    375   i_tmp=(yj_16_to_rgb * (y-0x40) + vj_16_to_r * (v-0x200))>>18;        \
    376   r = RECLIP_8(i_tmp);\
    377   i_tmp=(yj_16_to_rgb * (y-0x40) + uj_16_to_g * (u-0x200)+ vj_16_to_g * (v-0x200))>>18; \
    378   g = RECLIP_8(i_tmp);\
    379   i_tmp=(yj_16_to_rgb * (y-0x40) + uj_16_to_b * (u-0x200))>>18; \
    380   b = RECLIP_8(i_tmp);
     375   i_tmp=(y_16_to_rgb * (y-0x40) + v_16_to_r * (v-0x200))>>18;        \
     376   r = RECLIP_8(i_tmp);\
     377   i_tmp=(y_16_to_rgb * (y-0x40) + u_16_to_g * (u-0x200)+ v_16_to_g * (v-0x200))>>18; \
     378   g = RECLIP_8(i_tmp);\
     379   i_tmp=(y_16_to_rgb * (y-0x40) + u_16_to_b * (u-0x200))>>18; \
     380   b = RECLIP_8(i_tmp);
    381381
    382382#define YUVJ_10_TO_RGB_24(y,u,v,r,g,b) \
    383383  i_tmp=(yj_16_to_rgb * y + vj_16_to_r * (v-0x200))>>18;        \
  • include/lqt_funcprotos.h

     
    10151015void quicktime_read_stss(quicktime_t *file, quicktime_stss_t *stss);
    10161016void quicktime_write_stss(quicktime_t *file, quicktime_stss_t *stss);
    10171017
     1018/* stps.c */
     1019
     1020void quicktime_stps_init(quicktime_stps_t *stps);
     1021void quicktime_stps_delete(quicktime_stps_t *stps);
     1022void quicktime_stps_dump(quicktime_stps_t *stps);
     1023void quicktime_read_stps(quicktime_t *file, quicktime_stps_t *stps);
     1024void quicktime_write_stps(quicktime_t *file, quicktime_stps_t *stps);
     1025
    10181026/* stsz.c */
    10191027
    10201028void quicktime_stsz_init(quicktime_stsz_t *stsz);
     
    10331041                           long sample_size);
    10341042void quicktime_stsz_init_timecode(quicktime_stsz_t *stsz);
    10351043
     1044/* sdtp.c */
     1045
     1046void quicktime_sdtp_init(quicktime_sdtp_t *sdtp);
     1047void quicktime_sdtp_delete(quicktime_sdtp_t *sdtp);
     1048void quicktime_sdtp_dump(quicktime_sdtp_t *sdtp);
     1049void quicktime_read_sdtp(quicktime_t *file, quicktime_sdtp_t *sdtp, long num_entries);
     1050void quicktime_write_sdtp(quicktime_t *file, quicktime_sdtp_t *sdtp);
     1051
    10361052/* stts.c */
    10371053
    10381054void quicktime_stts_init(quicktime_stts_t *stts);
     
    14621478int quicktime_codecs_flush(quicktime_t *file);
    14631479
    14641480LQT_EXTERN void lqt_write_frame_header(quicktime_t * file, int track,
    1465                                        int pic_num1, int64_t pic_pts, int keyframe);
     1481                                       int pic_num1, int64_t pic_pts,
     1482                                       enum LqtKeyFrame keyframe);
    14661483
    14671484LQT_EXTERN void lqt_write_frame_footer(quicktime_t * file, int track);
    14681485
     
    14801497/* workarounds.c */
    14811498
    14821499int64_t quicktime_add3(int64_t a, int64_t b, int64_t c);
     1500
     1501
     1502/* bframe_detector.c */
     1503
     1504LQT_EXTERN void quicktime_init_bframe_detector(quicktime_bframe_detector* ctx, quicktime_video_map_t* vtrack);
     1505LQT_EXTERN int quicktime_is_bframe(quicktime_bframe_detector* ctx, int64_t frame);
  • include/quicktime/lqt.h

     
    10561056 *  \param file A quicktime handle
    10571057 *  \param row_pointers Frame (see \ref lqt_rows_alloc)
    10581058 *  \param track Track index (starting with 0)
     1059 *  \returns 0 on success and a non-zero value on failure.
    10591060 *
    10601061 * Decode one video frame and increment the interal frame pointer.
    10611062 * To get the presentation timestamp for this frame, call
  • include/quicktime/qtprivate.h

     
    592592  quicktime_stss_table_t *table;
    593593  } quicktime_stss_t;
    594594
     595/* partial sync sample */
     596typedef struct
     597  {
     598  long sample;
     599  } quicktime_stps_table_t;
     600
     601typedef struct
     602  {
     603  int version;
     604  long flags;
     605  long total_entries;
     606  long entries_allocated;
     607  quicktime_stps_table_t *table;
     608  } quicktime_stps_t;
    595609
    596610/* sample to chunk */
    597611typedef struct
     
    629643  quicktime_stsz_table_t *table;
    630644  } quicktime_stsz_t;
    631645
     646/* sample dependency table */
     647typedef struct
     648  {
     649  int version;
     650  long flags;
     651  long total_entries;
     652  long entries_allocated;
     653  uint8_t *table;
     654  } quicktime_sdtp_t;
    632655
    633656/* chunk offset */
    634657typedef struct
     
    656679  quicktime_stsd_t stsd;
    657680  quicktime_stts_t stts;
    658681  quicktime_stss_t stss;
     682  quicktime_stps_t stps;
    659683  quicktime_stsc_t stsc;
    660684  quicktime_stsz_t stsz;
     685  quicktime_sdtp_t sdtp;
    661686  quicktime_stco_t stco;
    662687  quicktime_ctts_t ctts;
    663688  int has_ctts;
     
    13571382 
    13581383  } quicktime_audio_map_t;
    13591384
     1385
     1386enum LqtKeyFrame {
     1387    LQT_NO_KEY_FRAME      = 0,
     1388    LQT_FULL_KEY_FRAME    = 1,
     1389    LQT_PARTIAL_KEY_FRAME = 2 /* Corresponds to an I-frame in an open GOP. */
     1390};
     1391
     1392
    13601393typedef struct
    13611394  {
    13621395  quicktime_trak_t *track;
     
    14211454
    14221455  /* For encoding */
    14231456  quicktime_atom_t chunk_atom;
    1424   int keyframe;
     1457  enum LqtKeyFrame keyframe;
    14251458
    14261459  lqt_compression_info_t ci;
     1460
     1461  /* 1 if encoding, 0 if decoding. */
     1462  int do_encode;
    14271463 
    14281464  } quicktime_video_map_t;
    14291465
     
    16801716
    16811717  };
    16821718
     1719
     1720typedef struct
     1721  {
     1722  int64_t frame;
     1723  long ctts_entry_idx;
     1724  long sample_within_entry;
     1725  quicktime_ctts_t *ctts;
     1726  } quicktime_bframe_detector;
     1727
    16831728#endif
  • include/quicktime/quicktime.h

     
    10981098
    10991099/* One keyframe table for each track */
    11001100long quicktime_get_keyframe_before(quicktime_t *file, long frame, int track);
     1101long quicktime_get_partial_keyframe_before(quicktime_t *file, long frame, int track);
    11011102void quicktime_insert_keyframe(quicktime_t *file, long frame, int track);
     1103void quicktime_insert_partial_keyframe(quicktime_t *file, long frame, int track);
    11021104/* Track has keyframes */
    11031105int quicktime_has_keyframes(quicktime_t *file, int track);
    11041106
     1107/* Sample dependencies for long-GOP formats. */
     1108void quicktime_insert_sdtp_entry(quicktime_t *file, long frame, int track, uint8_t flags);
     1109
    11051110/* ===================== Access to built in codecs follows. */
    11061111
    11071112/* If the codec for this track is supported in the library return 1. */
  • plugins/audiocodec/pcm.c

     
    10531053    {
    10541054    case 8:
    10551055      atrack->block_align = atrack->channels;
    1056       atrack->sample_format = LQT_SAMPLE_UINT8;
     1056      atrack->sample_format = LQT_SAMPLE_INT8;
    10571057      codec->encode = encode_8;
    10581058      codec->decode = decode_8;
    10591059      break;
  • plugins/faac/faac.c

     
    5252  int bitrate;
    5353  int quality;
    5454  int object_type;
     55  int priming_delay; 
    5556  } quicktime_faac_codec_t;
    5657
    5758
     
    8081
    8182  imax = codec->sample_buffer_size * track_map->channels;
    8283 
    83   if(!num_samples && (codec->encoder_delay < 0))
     84  if(!num_samples && (codec->encoder_delay < -FAAC_PRIMING_DELAY))
    8485    return 0;
    8586 
    8687  for(i = 0; i < imax; i++)
     
    116117  lqt_start_audio_vbr_frame(file, track);
    117118  result = !quicktime_write_data(file, codec->chunk_buffer,
    118119                                 bytes_encoded);
    119   if(codec->encoder_delay < 0)
     120  if(codec->encoder_delay < -FAAC_PRIMING_DELAY)
    120121    {
    121122    lqt_finish_audio_vbr_frame(file, track, codec->samples_per_frame +
    122                                codec->encoder_delay);
     123                               codec->encoder_delay + FAAC_PRIMING_DELAY);
    123124    }
    124125  else
    125126    lqt_finish_audio_vbr_frame(file, track, codec->samples_per_frame);
     
    205206  {
    206207  int samples_read;
    207208  int samples_to_copy;
     209  int priming_delay = 0;
    208210 
    209211  faacEncConfigurationPtr enc_config;
    210212  unsigned long input_samples;
     
    255257#endif
    256258    codec->chunk_buffer_size = output_bytes;
    257259    codec->chunk_buffer = malloc(codec->chunk_buffer_size);
     260
     261    if(codec->priming_delay > FAAC_PRIMING_DELAY)
     262      priming_delay = codec->priming_delay - FAAC_PRIMING_DELAY;
    258263   
    259264    codec->initialized = 1;
    260265
     
    276281 
    277282  while(samples_read < samples)
    278283    {
     284    /* Add priming delay */
     285    if(priming_delay >= codec->samples_per_frame)
     286      {
     287        memset(codec->sample_buffer, 0,
     288               codec->samples_per_frame * track_map->channels * sizeof(float));
     289        codec->sample_buffer_size = codec->samples_per_frame;
     290        priming_delay -= codec->samples_per_frame;
     291      }
     292    else if(priming_delay > 0)
     293      {
     294        memset(codec->sample_buffer, 0,
     295               priming_delay * track_map->channels * sizeof(float));
     296        codec->sample_buffer_size = priming_delay;
     297        priming_delay = 0;
     298      }
    279299    /* Put samples into sample buffer */
    280300   
    281301    samples_to_copy = codec->samples_per_frame - codec->sample_buffer_size;
    282302    if(samples_read + samples_to_copy > samples)
    283303      samples_to_copy = samples - samples_read;
    284304
    285     memcpy(codec->sample_buffer +
    286            track_map->channels * codec->sample_buffer_size,
    287            input + samples_read * track_map->channels,
    288            samples_to_copy * track_map->channels * sizeof(float));
    289    
    290     codec->sample_buffer_size += samples_to_copy;
    291     samples_read += samples_to_copy;
     305    if(samples_to_copy > 0)
     306      {
     307        memcpy(codec->sample_buffer +
     308               track_map->channels * codec->sample_buffer_size,
     309               input + samples_read * track_map->channels,
     310               samples_to_copy * track_map->channels * sizeof(float));
     311       
     312        codec->sample_buffer_size += samples_to_copy;
     313        samples_read += samples_to_copy;
     314      }
    292315   
    293316    /* Encode one frame, possibly starting a new audio chunk */
    294317    if(codec->sample_buffer_size == codec->samples_per_frame)
     
    312335  {
    313336  quicktime_audio_map_t *track_map = &file->atracks[track];
    314337  quicktime_faac_codec_t *codec = track_map->codec->priv;
    315    
     338
    316339  if(!strcasecmp(key, "faac_bitrate"))
    317340    codec->bitrate = *(int*)value;
    318341  else if(!strcasecmp(key, "faac_quality"))
     
    328351    else if(!strcmp((char*)value, "LTP"))
    329352      codec->object_type = LTP;
    330353    }
     354  else if(!strcasecmp(key, "faac_priming_delay"))
     355    codec->priming_delay = *(int*)value;
    331356  return 0;
    332357  }
    333358
     
    404429 
    405430  codec->bitrate = 0;
    406431  codec->quality = 100;
     432  codec->priming_delay = 2112;
    407433
    408434  if(!atrack)
    409435    return;
  • plugins/faac/lqt_faac.c

     
    3939      .val_default = { .val_int = 0 }
    4040    },
    4141    {
    42       .name =        "quality",
     42      .name =        "faac_quality",
    4343      .real_name =   TRS("VBR Quality"),
    4444      .type =        LQT_PARAMETER_INT,
    4545      .val_min =     { .val_int = 10 },
     
    4747      .val_default = { .val_int = 100 },
    4848    },
    4949    {
    50       .name        = "object_type",
     50      .name        = "faac_object_type",
    5151      .real_name   = TRS("Object type"),
    5252      .type        = LQT_PARAMETER_STRINGLIST,
    5353      .val_default = { .val_string = "Low" },
     
    5757                                       TRS("LTP"),
    5858                                       (char*)0 },
    5959    },
     60    {
     61      .name =        "faac_priming_delay",
     62      .real_name =   TRS("Priming delay (samples)"),
     63      .type =        LQT_PARAMETER_INT,
     64      .val_min =     { .val_int = FAAC_PRIMING_DELAY },
     65      .val_default = { .val_int = 2112 },
     66    },
    6067    { /* End of parameters */ }
    6168  };
    6269
  • plugins/faac/qtfaac.h

     
    2222 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    2323*******************************************************************************/
    2424
     25#define FAAC_PRIMING_DELAY 1024
     26
    2527void quicktime_init_codec_faac(quicktime_codec_t * codec,
    2628                               quicktime_audio_map_t *atrack,
    2729                               quicktime_video_map_t *vtrack);
  • plugins/ffmpeg/audio.c

     
    4545#define ENCODE_AUDIO 1
    4646#endif
    4747
     48#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
     49/* from libavcodec/avcodec.h dated Dec 23 2012 */
     50#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
     51#endif
     52
    4853/* The following code was ported from gmerlin_avdecoder (http://gmerlin.sourceforge.net) */
    4954
    5055/* MPEG Audio header parsing code */
  • plugins/ffmpeg/lqt_ffmpeg.c

     
    5353#define CODEC_TYPE_NB         AVMEDIA_TYPE_NB
    5454#endif
    5555
     56#if LIBAVCODEC_VERSION_INT > ((53<<16)|(17<<8)|0)
     57#define HAVE_PRORES_SUPPORT
     58#endif
     59
    5660 
    5761#define ENCODE_PARAM_AUDIO \
    5862  { \
     
    198202    .val_default = { .val_int = 1 }  \
    199203  }
    200204
     205#define ENCODE_PARAM_PRORES                                             \
     206  {                                                                     \
     207    .name = "prores_profile",                                           \
     208    .real_name = TRS("ProRes profile"),                                 \
     209    .type = LQT_PARAMETER_STRINGLIST,                                   \
     210    .val_default = { .val_string =  "Standard" },                       \
     211    .stringlist_options = (char *[]){ "HQ", "Standard",  "LT", "Proxy", \
     212                                      (char *)0 }                       \
     213  }
     214
    201215#define DECODE_PARAM_AUDIO
    202216
    203217#define DECODE_PARAM_VIDEO \
    204   PARAM_FLAG_GRAY
     218  PARAM_FLAG_GRAY,         \
     219  PARAM_THREAD_COUNT
     220
    205221
    206222static lqt_parameter_info_static_t encode_parameters_mpeg4[] = {
    207223  ENCODE_PARAM_VIDEO_FRAMETYPES_IPB,
     
    292308};
    293309
    294310static lqt_parameter_info_static_t encode_parameters_imx[] = {
     311  PARAM_THREAD_COUNT,
    295312  ENCODE_PARAM_IMX,
    296313  { /* End of parameters */ }
    297314};
    298315
     316static lqt_parameter_info_static_t encode_parameters_dnxhd[] = {
     317  PARAM_THREAD_COUNT,
     318  { /* End of parameters */ }
     319};
     320
     321static lqt_parameter_info_static_t encode_parameters_xdcam_hd422[] = {
     322  PARAM_THREAD_COUNT,
     323  { /* End of parameters */ }
     324};
     325
     326static lqt_parameter_info_static_t encode_parameters_prores[] = {
     327  PARAM_THREAD_COUNT,
     328  ENCODE_PARAM_PRORES,
     329  { /* End of parameters */ }
     330};
     331
    299332
    300333static lqt_parameter_info_static_t encode_parameters_audio[] = {
    301334  ENCODE_PARAM_AUDIO,
     
    684717      .index = -1,
    685718      .encoder = NULL,
    686719      .decoder = NULL,
     720      .decode_parameters = decode_parameters_video,
    687721      .short_name = "rle",
    688722      .name = TRS("FFMPEG RLE"),
    689723      .fourccs = { "rle ", (char *)0 },
     
    697731      .index = -1,
    698732      .encoder = NULL,
    699733      .decoder = NULL,
     734      .decode_parameters = decode_parameters_video,
    700735      .short_name = "wrle",
    701736      .name = TRS("FFMPEG Microsoft RLE"),
    702737      .fourccs = { "WRLE", (char *)0 },
     
    806841      .encoder = NULL,
    807842      .decoder = NULL,
    808843      .decode_parameters = decode_parameters_video,
     844      .encode_parameters = encode_parameters_dnxhd,
    809845      .image_sizes = image_sizes_dnxhd,
    810846      .short_name = "dnxhd",
    811847      .name = TRS("FFMPEG dnxhd"),
     
    826862      .image_sizes = image_sizes_imx,
    827863      .short_name = "imx",
    828864      .name = TRS("FFMPEG IMX"),
    829       .fourccs = { "mx3p", "mx3n", "mx4p", "mx4n", "mx5p", "mx5n", (char *)0 },
     865      .fourccs = { "mx3p", "mx3n", "mx4p", "mx4n", "mx5p", "mx5n", "AVmp", (char *)0 },
    830866      .wav_ids = { LQT_WAV_ID_NONE },
    831867      .compatibility_flags = LQT_FILE_QT_OLD | LQT_FILE_QT,
    832868      .do_encode = 1,
    833869      .compression_id = LQT_COMPRESSION_D10
    834870    },
     871    {
     872      .id = CODEC_ID_MPEG2VIDEO,
     873      .index = -1,
     874      .encoder = NULL,
     875      .decoder = NULL,
     876      .decode_parameters = decode_parameters_video,
     877      .short_name = "xdcam_hd",
     878      .name = TRS("FFMPEG XDCAM HD"),
     879      .fourccs = {
     880        "xdv1", "xdv2", "xdv3", "xdv4", "xdv5", "xdv6", "xdv7", "xdv8",
     881        "xdv9", "xdva", (char *)0 },
     882      .wav_ids = { LQT_WAV_ID_NONE },
     883      .compatibility_flags = LQT_FILE_QT
     884    },
     885    {
     886      .id = CODEC_ID_MPEG2VIDEO,
     887      .index = -1,
     888      .encoder = NULL,
     889      .decoder = NULL,
     890      .decode_parameters = decode_parameters_video,
     891      .short_name = "xdcam_ex",
     892      .name = TRS("FFMPEG XDCAM EX"),
     893      .fourccs = { "xdvb", "xdvc", "xdvd", "xdve", "xdvf", (char *)0 },
     894      .wav_ids = { LQT_WAV_ID_NONE },
     895      .compatibility_flags = LQT_FILE_QT
     896    },
     897    {
     898      .id = CODEC_ID_MPEG2VIDEO,
     899      .index = -1,
     900      .encoder = NULL,
     901      .decoder = NULL,
     902      .decode_parameters = decode_parameters_video,
     903      .encode_parameters = encode_parameters_xdcam_hd422,
     904      .short_name = "xdcam_hd422",
     905      .name = TRS("FFMPEG XDCAM HD422"),
     906      .fourccs = {
     907        "xd54", "xd55", "xd59", "xd5a", "xd5b", "xd5c", "xd5d", "xd5e", "xd5f",
     908        (char *)0 },
     909      .wav_ids = { LQT_WAV_ID_NONE },
     910      .compatibility_flags = LQT_FILE_QT,
     911      .do_encode = 1,
     912      .encoding_colormodels = (int[]){ BC_YUV422P, LQT_COLORMODEL_NONE }
     913    },
     914#ifdef HAVE_PRORES_SUPPORT
     915    {
     916      .id = CODEC_ID_PRORES,
     917      .index = -1,
     918      .encoder = NULL,
     919      .decoder = NULL,
     920      .decode_parameters = decode_parameters_video,
     921      .encode_parameters = encode_parameters_prores,
     922      .short_name = "prores",
     923      .name = TRS("FFMPEG ProRes"),
     924      .fourccs = { "apch", "apcn", "apcs", "apco", (char *)0 },
     925      .wav_ids = { LQT_WAV_ID_NONE },
     926      .compatibility_flags = LQT_FILE_QT,
     927      .do_encode = 1,
     928      .encoding_colormodels = (int[]){ BC_YUV422P10, LQT_COLORMODEL_NONE }
     929    },
     930#endif
    835931};
    836932
    837933/* Audio */
     
    9551051  for(i = 0; i < NUMMAPS_V; i++)
    9561052    {
    9571053    if(codecidmap_v[i].do_encode)
    958       codecidmap_v[i].encoder = avcodec_find_encoder(codecidmap_v[i].id);
     1054      {
     1055#ifdef HAVE_PRORES_SUPPORT
     1056      // FFMpeg has 2 different ProRes encoders, so try the better one first.
     1057      if(codecidmap_v[i].id == CODEC_ID_PRORES)
     1058        {
     1059        // In newer versions it's called prores_ks. It used to be called prores_kostya
     1060        codecidmap_v[i].encoder = avcodec_find_encoder_by_name("prores_ks");
     1061        if(!codecidmap_v[i].encoder)
     1062          codecidmap_v[i].encoder = avcodec_find_encoder_by_name("prores_kostya");
     1063        }
     1064
     1065      if(!codecidmap_v[i].encoder)
     1066#endif
     1067        codecidmap_v[i].encoder = avcodec_find_encoder(codecidmap_v[i].id);
     1068      }
    9591069    codecidmap_v[i].decoder = avcodec_find_decoder(codecidmap_v[i].id);
    9601070
    9611071    if(codecidmap_v[i].encoder || codecidmap_v[i].decoder)
  • plugins/ffmpeg/params.c

     
    101101    }                                           \
    102102  }
    103103
     104#define PARAM_DICT_INT(name, dict_name)             \
     105  {                                                 \
     106  if(!strcasecmp(name, key))                        \
     107    {                                               \
     108    char buf[128];                                  \
     109    snprintf(buf, sizeof(buf), "%d", *(int*)value); \
     110    av_dict_set(options, dict_name, buf, 0);        \
     111    found = 1;                                      \
     112    }                                               \
     113  }
     114
    104115#define PARAM_DICT_FLAG(name, dict_name)        \
    105116  {                                             \
    106117  if(!strcasecmp(name, key))                    \
     
    202213  PARAM_INT("ff_max_b_frames",max_b_frames);
    203214  PARAM_FLOAT("ff_b_quant_factor",b_quant_factor);
    204215  PARAM_INT("ff_b_frame_strategy",b_frame_strategy);
     216
     217#if LIBAVCODEC_VERSION_MAJOR >= 55
     218  PARAM_DICT_INT("ff_luma_elim_threshold","luma_elim_threshold");
     219  PARAM_DICT_INT("ff_chroma_elim_threshold","chroma_elim_threshold");
     220#else
    205221  PARAM_INT("ff_luma_elim_threshold",luma_elim_threshold);
    206222  PARAM_INT("ff_chroma_elim_threshold",chroma_elim_threshold);
     223#endif
     224
    207225  PARAM_INT("ff_strict_std_compliance",strict_std_compliance);
    208226  PARAM_QP2LAMBDA("ff_b_quant_offset",b_quant_offset);
    209227  PARAM_INT("ff_rc_min_rate",rc_min_rate);
     
    241259  PARAM_QP2LAMBDA("ff_lmax", lmax);
    242260  PARAM_INT("ff_noise_reduction",noise_reduction);
    243261  PARAM_INT_SCALE("ff_rc_initial_buffer_occupancy",rc_initial_buffer_occupancy,1000);
     262
     263#if LIBAVCODEC_VERSION_MAJOR >= 55
     264  PARAM_DICT_INT("ff_inter_threshold","inter_threshold");
     265  PARAM_DICT_INT("ff_quantizer_noise_shaping","quantizer_noise_shaping");
     266#else
    244267  PARAM_INT("ff_inter_threshold",inter_threshold);
    245268  PARAM_INT("ff_quantizer_noise_shaping",quantizer_noise_shaping);
     269#endif
     270
    246271  PARAM_INT("ff_thread_count",thread_count);
    247272  PARAM_INT("ff_me_threshold",me_threshold);
    248273  PARAM_INT("ff_mb_threshold",mb_threshold);
     
    272297  PARAM_FLAG("ff_flag_bitexact",CODEC_FLAG_BITEXACT);
    273298  PARAM_FLAG("ff_flag_ac_pred",CODEC_FLAG_AC_PRED);
    274299  //  PARAM_FLAG("ff_flag_h263p_umv",CODEC_FLAG_H263P_UMV); // Unused
     300
     301#if LIBAVCODEC_VERSION_MAJOR >= 55
     302  PARAM_DICT_FLAG("ff_flag_cbp_rd","cbp_rd");
     303  PARAM_DICT_FLAG("ff_flag_qp_rd","qp_rd");
     304  PARAM_DICT_FLAG("ff_flag2_strict_gop","strict_gop");
     305#else
    275306  PARAM_FLAG("ff_flag_cbp_rd",CODEC_FLAG_CBP_RD);
    276307  PARAM_FLAG("ff_flag_qp_rd",CODEC_FLAG_QP_RD);
     308  PARAM_FLAG2("ff_flag2_strict_gop",CODEC_FLAG2_STRICT_GOP);
     309#endif
    277310
    278311#if LIBAVCODEC_VERSION_MAJOR >= 54
    279312  PARAM_DICT_FLAG("ff_flag_h263p_aiv", "aiv");
     
    288321  PARAM_FLAG("ff_flag_loop_filter",CODEC_FLAG_LOOP_FILTER);
    289322  PARAM_FLAG("ff_flag_closed_gop",CODEC_FLAG_CLOSED_GOP);
    290323  PARAM_FLAG2("ff_flag2_fast",CODEC_FLAG2_FAST);
    291   PARAM_FLAG2("ff_flag2_strict_gop",CODEC_FLAG2_STRICT_GOP);
    292324  PARAM_ENUM("ff_coder_type",coder_type,coder_type);
    293325 
    294326  }
  • plugins/ffmpeg/video.c

     
    4343#define PIX_FMT_YUV422P10_OR_DUMMY -1234
    4444#endif
    4545
     46#if LIBAVCODEC_VERSION_INT > ((53<<16)|(17<<8)|0)
     47#define HAVE_PRORES_SUPPORT
     48#endif
     49
    4650#if LIBAVCODEC_VERSION_INT >= ((54<<16)|(1<<8)|0)
    4751#define ENCODE_VIDEO2 1
    4852#else
    4953#define ENCODE_VIDEO 1
    5054#endif
    5155
     56static const struct
     57{
     58    const char* fourcc;
     59
     60    /* There are two different ProRes encoders in FFMpeg. One of them
     61       only accepts numeric profile values, while the other one also
     62       accepts profile names. Fortunately, they do agree on numeric values. */
     63    const char* ffmpeg_profile;
     64
     65    const char* lqt_name;
     66} lqt_prores_profiles[] = {
     67    { "apco", "0", "Proxy" },
     68    { "apcs", "1", "LT" },
     69    { "apcn", "2", "Standard" },
     70    { "apch", "3", "HQ" }
     71};
     72
    5273/* We keep the numeric values the same as in the ACLR atom.
    5374   The interpretation of values is based on trial and error. */
    5475enum AvidYuvRange
     
    95116  enum PixelFormat reinterpret_pix_fmt;
    96117 
    97118  int is_imx;
     119  int is_xdcam_hd422;
    98120  int y_offset;
     121  int prores_profile; // Index into lqt_prores_profiles, for encoding only.
    99122
    100123#if LIBAVCODEC_VERSION_MAJOR < 54
    101124  AVPaletteControl palette;
     
    129152
    130153  /* Stuff for compressed H.264 reading */
    131154  int nal_size_length;
     155
     156  quicktime_bframe_detector bframe_detector;
     157
     158  /* lqt_pts = ffmpeg_pts * pts_factor */
     159  int encoding_pts_factor;
     160
    132161  } quicktime_ffmpeg_video_codec_t;
    133162
    134163/* ffmpeg <-> libquicktime colormodels */
     
    291320  *p += 4;
    292321  }
    293322
     323static uint8_t generate_sdtp_flags_mpeg2(long frame, const AVCodecContext* avctx)
     324  {
     325  unsigned flags = 0;
     326
     327  switch(avctx->coded_frame->pict_type)
     328    {
     329    case AV_PICTURE_TYPE_I:
     330      flags |= 0x20; // doesnt_depend_on_other_samples
     331      if(avctx->gop_size > 1)
     332        flags |= 0x04; // other_samples_depend_on_this_one
     333      if(avctx->max_b_frames > 0)
     334        flags |= 0x40; // earlier_dps_allowed
     335      break;
     336    case AV_PICTURE_TYPE_P:
     337      flags |= 0x10; // sample_depends_on_others
     338      if(avctx->max_b_frames > 0)
     339        flags |= 0x40|0x04; // earlier_dps_allowed|other_samples_depend_on_this_one
     340      break;
     341    case AV_PICTURE_TYPE_B:
     342      flags |= 0x10|0x08; // sample_depends_on_others|no_other_samples_depend_on_this_one
     343      break;
     344    default:;
     345    }
     346
     347  return (uint8_t)flags;
     348  }
     349
     350static void maybe_add_sdtp_entry(quicktime_t* file, long sample, int track)
     351  {
     352  quicktime_video_map_t *vtrack = &file->vtracks[track];
     353  quicktime_ffmpeg_video_codec_t *codec = vtrack->codec->priv;
     354
     355  if (codec->encoder->id == CODEC_ID_MPEG2VIDEO && codec->avctx->gop_size > 1)
     356    {
     357    uint8_t flags = generate_sdtp_flags_mpeg2(sample, codec->avctx);
     358    quicktime_insert_sdtp_entry(file, sample, track, flags);
     359    }
     360  }
     361
     362
    294363#ifndef HAVE_LIBSWSCALE
    295364static void fill_avpicture(AVPicture * ret, unsigned char ** rows,
    296365                           int lqt_colormodel,
     
    400469  codec->reinterpret_pix_fmt = codec->avctx->pix_fmt;
    401470
    402471  /* First we try codec-specific colormodel matching. */
    403   if(codec->decoder->id == CODEC_ID_DNXHD)
     472  if(codec->is_imx && quicktime_match_32(vtrack->track->mdia.minf.stbl.stsd.table[0].format, "AVmp"))
     473    {
     474     if (lqt_ffmpeg_get_avid_yuv_range(vtrack->track) == AVID_FULL_YUV_RANGE)
     475       {
     476       vtrack->stream_cmodel = BC_YUVJ422P;
     477       codec->reinterpret_pix_fmt = PIX_FMT_YUVJ422P;
     478       *exact = 1;
     479       return;
     480       }
     481    }
     482  else if(codec->decoder->id == CODEC_ID_DNXHD)
    404483    {
    405484    /* FFMpeg supports PIX_FMT_YUV422P and PIX_FMT_YUV422P10 for DNxHD, which
    406485       we sometimes interpret as PIX_FMT_YUVJ422P and PIX_FMT_YUVJ422P10. */
     
    662741        codec->y_offset = codec->avctx->height - trak->tkhd.track_height;
    663742        vtrack->height_extension = 0;
    664743    } else {
     744        int stsd_height = trak->mdia.minf.stbl.stsd.table[0].height;
    665745        codec->y_offset = 0;
    666         if (vtrack->height_extension == codec->avctx->height - trak->tkhd.track_height) {
     746        if (vtrack->height_extension == codec->avctx->height - stsd_height) {
    667747            return;
    668748        }
    669749
    670         vtrack->height_extension = codec->avctx->height - trak->tkhd.track_height;
     750        vtrack->height_extension = codec->avctx->height - stsd_height;
    671751
    672752        /* Now we need a larger temp_frame */
    673753        if (vtrack->temp_frame) {
     
    883963                               &got_pic,
    884964                               &codec->pkt) < 0)
    885965        {
    886         lqt_log(file, LQT_LOG_ERROR, LOG_DOMAIN, "Skipping corrupted frame");
    887         continue;
     966        lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "Broken frame encountered");
     967        codec->decoding_delay--;
     968        return 1;
    888969        }
    889970
    890971#if LIBAVCODEC_VERSION_MAJOR >= 54
     
    907988                              codec->buffer,
    908989                              buffer_size) < 0)
    909990        {
    910         lqt_log(file, LQT_LOG_ERROR, LOG_DOMAIN, "Skipping corrupted frame");
    911         continue;
     991        lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "Broken frame encountered");
     992        codec->decoding_delay--;
     993        return 1;
    912994        }
    913995#endif     
    914996      if(got_pic)
    915997        codec->decoding_delay--;
    916998     
    917999      if((buffer_size <= 0) && !got_pic)
    918         return 0;
     1000        return 1;
    9191001      }
    9201002    }
    9211003 
     
    9721054
    9731055      vtrack->chroma_placement = LQT_CHROMA_PLACEMENT_MPEG2;
    9741056      vtrack->ci.id = LQT_COMPRESSION_D10;
    975       vtrack->ci.bitrate =
    976         (trak->mdia.minf.stbl.stsd.table[0].format[2] - '0') *
    977         10000000;
     1057      if (quicktime_match_32(trak->mdia.minf.stbl.stsd.table[0].format, "AVmp"))
     1058        vtrack->ci.bitrate = 50000000;
     1059      else
     1060        vtrack->ci.bitrate =
     1061          (trak->mdia.minf.stbl.stsd.table[0].format[2] - '0') * 10000000;
    9781062      }
    9791063   
    9801064    if(codec->avctx->sample_aspect_ratio.num)
     
    10301114  return result;
    10311115  }
    10321116
     1117static int64_t bitstream_i_frame_to_display_frame(int64_t bitstream_i_frame, quicktime_bframe_detector* bframe_detector)
     1118  {
     1119  if (!bframe_detector)
     1120    return bitstream_i_frame; // Assuming closed GOP.
     1121  else
     1122    { // This branch can also handle P-frames, though we aren't relying on that.
     1123    int num_following_b_frames = 0;
     1124    while (quicktime_is_bframe(bframe_detector, bitstream_i_frame + num_following_b_frames + 1) == 1)
     1125      {
     1126      num_following_b_frames++;
     1127      }
     1128    return bitstream_i_frame + num_following_b_frames;
     1129    }
     1130  }
     1131
     1132static int64_t bitstream_b_frame_to_display_frame(int64_t bitstream_b_frame)
     1133  {
     1134  return bitstream_b_frame - 1;
     1135  }
     1136
     1137static int64_t get_bitstream_sync_frame(quicktime_t* file, int64_t display_frame, int track, quicktime_bframe_detector* bframe_detector)
     1138  {
     1139  int64_t full_sync_kf = quicktime_get_keyframe_before(file, display_frame, track);
     1140  int64_t partial_sync_kf = quicktime_get_partial_keyframe_before(file, display_frame, track);
     1141
     1142  while (partial_sync_kf > full_sync_kf && partial_sync_kf > 0)
     1143    {
     1144    if (bitstream_i_frame_to_display_frame(partial_sync_kf, bframe_detector) <= display_frame)
     1145      return partial_sync_kf;
     1146
     1147    partial_sync_kf = quicktime_get_partial_keyframe_before(file, partial_sync_kf - 1, track);
     1148    }
     1149
     1150  return full_sync_kf;
     1151  }
     1152
    10331153static void resync_ffmpeg(quicktime_t *file, int track)
    10341154  {
    1035   int64_t keyframe, frame;
    1036   int buffer_size, got_pic;
    10371155  quicktime_video_map_t *vtrack = &file->vtracks[track];
    10381156  quicktime_ffmpeg_video_codec_t *codec = vtrack->codec->priv;
    1039  
     1157
     1158  const int64_t target_display_frame = vtrack->current_position; // Frame we are told to seek to.
     1159  int64_t bitstream_frame; // Current working frame in bitstream order.
     1160  int64_t buffer_size;
     1161  const int64_t total_frames = quicktime_video_length(file, track);
     1162  int decoded_frames_to_discard = 0;
     1163  int seen_non_b_frames = 0;
     1164  const int detect_bframes = vtrack->track->mdia.minf.stbl.has_ctts;
     1165  quicktime_bframe_detector* bframe_detector = detect_bframes ? &codec->bframe_detector : NULL;
     1166
    10401167  /* Forget about previously decoded frame */
    10411168  codec->have_frame = 0;
    10421169  codec->decoding_delay = 0;
    1043  
     1170
    10441171  /* Reset lavc */
    10451172  avcodec_flush_buffers(codec->avctx);
    10461173
    1047  
    1048   if(quicktime_has_keyframes(file, track))
     1174  if(target_display_frame <= 0)
     1175    return;
     1176
     1177  if(!quicktime_has_keyframes(file, track))
     1178    return; // Assuming I-frame only stream.
     1179
     1180  bitstream_frame = get_bitstream_sync_frame(file, target_display_frame, track, bframe_detector);
     1181  decoded_frames_to_discard = target_display_frame - bitstream_i_frame_to_display_frame(bitstream_frame, bframe_detector);
     1182
     1183  for (;; bitstream_frame++)
    10491184    {
    1050     keyframe = quicktime_get_keyframe_before(file, vtrack->current_position, track);
     1185    int got_pic = 0;
    10511186
    1052     frame = keyframe;
    1053    
    1054     while(frame < vtrack->current_position)
     1187    if (decoded_frames_to_discard <= 0) // Should not be < 0 unless the stream is broken.
    10551188      {
     1189      // We want vtrack->current_position + codec->decoding_delay == bitstream_frame
     1190      // when the next encoded frame is read.
     1191      codec->decoding_delay = bitstream_frame - vtrack->current_position;
     1192      break;
     1193      }
     1194
     1195    if (bitstream_frame < total_frames)
     1196      {
     1197      if (detect_bframes)
     1198        {
     1199        int is_bframe = quicktime_is_bframe(bframe_detector, bitstream_frame);
     1200        if (!is_bframe)
     1201          seen_non_b_frames++;
     1202
     1203        // Skip initial B-frames.
     1204        if (is_bframe && seen_non_b_frames < 2)
     1205          continue;
     1206
     1207        // Don't do IDCT where we don't have to.
     1208        if (is_bframe && bitstream_b_frame_to_display_frame(bitstream_frame) < target_display_frame)
     1209          codec->avctx->skip_idct = AVDISCARD_NONREF;
     1210        }
     1211
    10561212      buffer_size = lqt_read_video_frame(file, &codec->buffer,
    10571213                                         &codec->buffer_alloc,
    1058                                          frame + codec->decoding_delay,
    1059                                          NULL, track);
    1060       if(buffer_size > 0)
    1061         {
     1214                                         bitstream_frame, NULL, track);
     1215      }
     1216    else // if (bitstream_frame < total_frames)
     1217      {
     1218      // Feed an empty packet to the decoder to indicate end of stream,
     1219      // which will make it return the final decoded frames it still owes us.
     1220      buffer_size = 0;
     1221      }
     1222
    10621223#if LIBAVCODEC_BUILD >= ((52<<16)+(26<<8)+0)
    1063         codec->pkt.data = codec->buffer;
    1064         codec->pkt.size = buffer_size;
    1065         avcodec_decode_video2(codec->avctx,
    1066                               codec->frame,
    1067                               &got_pic,
    1068                               &codec->pkt);
     1224    codec->pkt.data = codec->buffer;
     1225    codec->pkt.size = buffer_size;
     1226    avcodec_decode_video2(codec->avctx, codec->frame, &got_pic, &codec->pkt);
    10691227#else
    1070         avcodec_decode_video(codec->avctx,
    1071                              codec->frame,
    1072                              &got_pic,
    1073                              codec->buffer,
    1074                              buffer_size);
     1228    avcodec_decode_video(codec->avctx, codec->frame, &got_pic, codec->buffer, buffer_size);
    10751229#endif
    1076         if(!got_pic)
    1077           {
    1078           codec->decoding_delay++;
    1079           frame--;
    1080           }
    1081         }
    1082       frame++;
     1230
     1231    // Default value is necessary for normal decoding.
     1232    codec->avctx->skip_idct = AVDISCARD_DEFAULT;
     1233
     1234    if(got_pic)
     1235      decoded_frames_to_discard--;
     1236    else if (bitstream_frame >= total_frames)
     1237      {
     1238      // We've already fed an empty packet to the decoder, indicating
     1239      // no more data will follow, yet it didn't return any additional
     1240      // frames. At this point we give up and declare decoding failure.
     1241      break;
    10831242      }
    1084     }
     1243    } // for (;; bitstream_frame++)
    10851244  }
    10861245
    10871246static int set_pass_ffmpeg(quicktime_t *file,
     
    11281287 
    11291288  }
    11301289
     1290static const char* get_xdcam_hd422_fourcc(quicktime_t *file, int track, int height)
     1291  {
     1292  quicktime_video_map_t *vtrack = &file->vtracks[track];
     1293  int time_scale = lqt_video_time_scale(file, track);
     1294  int frame_duration = lqt_frame_duration(file, track, NULL);
     1295  int interlaced = vtrack->interlace_mode != LQT_INTERLACE_NONE;
     1296  int frame_rate_100; // Frame rate with 2 decimal places preserved, multiplied by 100.
     1297
     1298  if(frame_duration <= 0 || time_scale <= 0)
     1299    return NULL; // Sanity check.
     1300
     1301  frame_rate_100 = time_scale * 100 / frame_duration;
     1302
     1303  if(height == 720 && !interlaced) // Only progressive modes are supported for 720 lines.
     1304    {
     1305    if(interlaced)
     1306      {
     1307      lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "XDCAM HD422 supports 720p but not 720i");
     1308      return NULL;
     1309      }
     1310    else
     1311      {
     1312      switch(frame_rate_100)
     1313        {
     1314        case 2397:
     1315          return "xd54";
     1316        case 2500:
     1317          return "xd55";
     1318        case 6000:
     1319          return "xd59";
     1320        case 5000:
     1321          return "xd5a";
     1322        }
     1323      }
     1324    }
     1325  else if(height == 1080)
     1326    {
     1327    if(interlaced)
     1328      {
     1329      switch(frame_rate_100)
     1330        {
     1331        case 2500:
     1332          return "xd5c";
     1333        case 2997:
     1334          return "xd5b";
     1335        }
     1336      }
     1337    else // if(interlaced)
     1338      {
     1339      switch(frame_rate_100)
     1340        {
     1341        case 2397:
     1342          return "xd5d";
     1343        case 2500:
     1344          return "xd5e";
     1345        case 2997:
     1346          return "xd5f";
     1347        }
     1348      }
     1349    }
     1350  else if(height == 540)
     1351    {
     1352    lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "XDCAM HD422 540p is not supported");
     1353    return NULL;
     1354    }
     1355  else
     1356    {
     1357    lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "Frame height of %d is not supported by XDCAM HD422", height);
     1358    return NULL;
     1359    }
     1360
     1361  lqt_log(file, LQT_LOG_WARNING, LOG_DOMAIN, "Frame rate %d.%02d is not supported by XDCAM HD422, at least not for %d%c",
     1362          frame_rate_100 / 100, frame_rate_100 % 100, height, interlaced ? 'i' : 'p');
     1363  return NULL;
     1364  }
     1365
    11311366static int init_imx_encoder(quicktime_t *file, int track)
    11321367  {
    11331368  quicktime_video_map_t *vtrack = &file->vtracks[track];
     
    11381373  codec->avctx->gop_size = 0;
    11391374  codec->avctx->intra_dc_precision = 2;
    11401375  codec->avctx->qmin = 1;
    1141   codec->avctx->qmax = 3;
     1376  codec->avctx->qmax = codec->imx_bitrate == 30 ? 8 : 3;
    11421377  codec->avctx->rtp_payload_size = 1; // ??
    11431378  codec->avctx->rc_buffer_aggressivity = 0.25;
    11441379  codec->avctx->flags |= CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_LOW_DELAY;
     
    11851420  return 0;
    11861421  }
    11871422
     1423static int init_xdcam_hd422_encoder(quicktime_t *file, int track)
     1424  {
     1425  quicktime_video_map_t *vtrack = &file->vtracks[track];
     1426  quicktime_ffmpeg_video_codec_t *codec = vtrack->codec->priv;
     1427  quicktime_trak_t *trak = vtrack->track;
     1428  int height = trak->tkhd.track_height;
     1429  int time_scale = lqt_video_time_scale(file, track);
     1430  int frame_duration = lqt_frame_duration(file, track, NULL);
     1431  const char* fourcc;
     1432
     1433  codec->avctx->pix_fmt = PIX_FMT_YUV422P;
     1434  codec->avctx->gop_size = time_scale > 25 * frame_duration ? 15 : 12;
     1435  codec->avctx->max_b_frames = 2;
     1436  codec->avctx->intra_dc_precision = 2;
     1437  codec->avctx->qmin = 1;
     1438  codec->avctx->qmax = 12; // The maximum value compatible with non_linear_quant option.
     1439  codec->avctx->lmin = FF_QP2LAMBDA;
     1440
     1441  // XDCAM is meant to use open GOPs. From time to time we might want to insert closed GOPs
     1442  // like some other encoders do, but libavcodec only checks this flag once.
     1443  codec->avctx->flags &= ~CODEC_FLAG_CLOSED_GOP;
     1444
     1445  if(vtrack->interlace_mode != LQT_INTERLACE_NONE)
     1446    codec->avctx->flags |= CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME;
     1447
     1448#if (LIBAVCODEC_VERSION_MAJOR < 54)
     1449  codec->avctx->flags2 |= CODEC_FLAG2_INTRA_VLC|CODEC_FLAG2_NON_LINEAR_QUANT;
     1450#else
     1451  av_dict_set(&codec->options, "non_linear_quant", "1", 0);
     1452  av_dict_set(&codec->options, "intra_vlc", "1", 0);
     1453#endif
     1454
     1455  codec->avctx->bit_rate = 50*1000*1000;
     1456  codec->avctx->rc_max_rate = codec->avctx->bit_rate;
     1457  codec->avctx->rc_min_rate = codec->avctx->bit_rate;
     1458  codec->avctx->rc_buffer_size = 17825792;
     1459  codec->avctx->rc_initial_buffer_occupancy = codec->avctx->rc_buffer_size;
     1460  codec->avctx->scenechange_threshold = 1000*1000*1000;
     1461
     1462  fourcc = get_xdcam_hd422_fourcc(file, track, height);
     1463  if (fourcc)
     1464    {
     1465    memcpy(trak->mdia.minf.stbl.stsd.table[0].format, fourcc, 4);
     1466    return 0;
     1467    }
     1468
     1469  return -1;
     1470  }
     1471
     1472#ifdef HAVE_PRORES_SUPPORT
     1473static int init_prores_encoder(quicktime_t *file, int track)
     1474  {
     1475  quicktime_video_map_t *vtrack = &file->vtracks[track];
     1476  quicktime_trak_t *trak = vtrack->track;
     1477  quicktime_ffmpeg_video_codec_t *codec = vtrack->codec->priv;
     1478  int height = trak->tkhd.track_height;
     1479
     1480  if(vtrack->interlace_mode != LQT_INTERLACE_NONE)
     1481    codec->avctx->flags |= CODEC_FLAG_INTERLACED_DCT;
     1482
     1483  // Color parameters go into ProRes bitstream.
     1484  if (trak->mdia.minf.stbl.stsd.table->has_colr)
     1485    {
     1486    // If COLR atom was provided by the client, use that.
     1487    const quicktime_colr_t* colr = &trak->mdia.minf.stbl.stsd.table->colr;
     1488    codec->avctx->color_primaries = colr->primaries;
     1489    codec->avctx->color_trc = colr->transferFunction;
     1490    codec->avctx->colorspace = colr->matrix;
     1491    }
     1492  else
     1493    {
     1494    // Try to guess the correct parameters.
     1495    if (height >= 720)
     1496      {
     1497      codec->avctx->color_primaries = AVCOL_PRI_BT709;
     1498      codec->avctx->color_trc = AVCOL_TRC_BT709;
     1499      codec->avctx->colorspace = AVCOL_SPC_BT709;
     1500      }
     1501    else if (height >= 576)
     1502      {
     1503      codec->avctx->color_primaries = AVCOL_PRI_BT470BG;
     1504      codec->avctx->color_trc = AVCOL_TRC_BT709;
     1505      codec->avctx->colorspace = AVCOL_SPC_SMPTE170M;
     1506      }
     1507    else
     1508      {
     1509      codec->avctx->color_primaries = AVCOL_PRI_SMPTE170M;
     1510      codec->avctx->color_trc = AVCOL_TRC_BT709;
     1511      codec->avctx->colorspace = AVCOL_SPC_SMPTE170M;
     1512      }
     1513    }
     1514
     1515  av_dict_set(&codec->options, "profile", lqt_prores_profiles[codec->prores_profile].ffmpeg_profile, 0);
     1516  memcpy(trak->mdia.minf.stbl.stsd.table[0].format, lqt_prores_profiles[codec->prores_profile].fourcc, 4);
     1517
     1518  return 0;
     1519  }
     1520#endif
     1521
    11881522static void setup_header_mpeg4(quicktime_t *file, int track,
    11891523                               const uint8_t * header, int header_len,
    11901524                               int advanced)
     
    12941628#endif
    12951629  int64_t pts;
    12961630  int kf;
     1631  uint8_t* encoded_data;
    12971632 
    12981633  if(!row_pointers)
    12991634    {
     
    13231658    /* time_base is 1/framerate for constant framerate */
    13241659         
    13251660    codec->avctx->time_base.den = lqt_video_time_scale(file, track);
    1326     codec->avctx->time_base.num = lqt_frame_duration(file, track, NULL);
     1661    codec->avctx->time_base.num = 1; // If we want variable frame durations, we need 1 here.
     1662    codec->encoding_pts_factor = 1;
    13271663
    1328     //          codec->avctx->time_base.den = 1;
    1329     //          codec->avctx->time_base.num = lqt_video_time_scale(file, track);
     1664    // Codecs for which time_base.num == 1 causes problems.
     1665    switch(codec->encoder->id)
     1666      {
     1667      // Variable duration frames won't work for these.
     1668      case CODEC_ID_MPEG2VIDEO:
     1669      case CODEC_ID_DVVIDEO:
     1670      case CODEC_ID_DNXHD:
     1671          codec->encoding_pts_factor = lqt_frame_duration(file, track, NULL);
     1672          codec->avctx->time_base.num = codec->encoding_pts_factor;
     1673          // time_base may be reduced by a common factor by libavcodec,
     1674          // so we can't just use that.
     1675          break;
     1676      default:;
     1677      }
    13301678
    13311679    if(codec->avctx->flags & CODEC_FLAG_QSCALE)
    13321680      codec->avctx->global_quality = codec->qscale;
     
    13351683    codec->avctx->height = height;
    13361684
    13371685    lqt_ffmpeg_setup_encoding_colormodel(vtrack);
    1338 
     1686#if ENCODE_VIDEO2
     1687    codec->frame->width = width;
     1688    codec->frame->height = height;
     1689    codec->frame->format = codec->avctx->pix_fmt;
     1690#endif
     1691   
    13391692    lqt_get_pixel_aspect(file, track, &pixel_width, &pixel_height);
    13401693    codec->avctx->sample_aspect_ratio.num = pixel_width;
    13411694    codec->avctx->sample_aspect_ratio.den = pixel_height;
     
    14151768      }
    14161769    else if(codec->is_imx)
    14171770      init_imx_encoder(file, track);
     1771    else if(codec->is_xdcam_hd422)
     1772      init_xdcam_hd422_encoder(file, track);
     1773#ifdef HAVE_PRORES_SUPPORT
     1774    else if(codec->encoder->id == CODEC_ID_PRORES)
     1775      init_prores_encoder(file, track);
     1776#endif
    14181777   
    14191778    /* Initialize 2-pass */
    14201779    if(codec->total_passes)
     
    15151874    codec->frame->linesize[2] = vtrack->stream_row_span_uv;
    15161875    }
    15171876 
    1518   codec->frame->pts = vtrack->timestamp;
     1877  codec->frame->pts = vtrack->timestamp / codec->encoding_pts_factor;
    15191878  if(codec->avctx->flags & CODEC_FLAG_QSCALE)
    15201879    codec->frame->quality = codec->qscale;
    1521 #ifdef DO_INTERLACE
     1880#if 1
    15221881  if(vtrack->interlace_mode != LQT_INTERLACE_NONE)
    15231882    {
    15241883    codec->frame->interlaced_frame = 1;
     
    15401899  else
    15411900    bytes_encoded = 0;
    15421901 
    1543   pts = pkt.pts;
     1902  encoded_data = pkt.data; // May be different from codec->buffer!
     1903  pts = pkt.pts * codec->encoding_pts_factor;
    15441904  kf = !!(pkt.flags & AV_PKT_FLAG_KEY);
    15451905   
    15461906#else // Old
     
    15531913  if(bytes_encoded < 0)
    15541914    return -1;
    15551915 
    1556   pts = codec->avctx->coded_frame->pts;
     1916  encoded_data = codec->buffer;
     1917  pts = codec->avctx->coded_frame->pts * encoding_pts_factor;
    15571918  kf = codec->avctx->coded_frame->key_frame;
    15581919 
    15591920#endif
    15601921 
     1922  if(kf && codec->is_xdcam_hd422 && vtrack->cur_chunk)
     1923    kf = LQT_PARTIAL_KEY_FRAME; // For XDCAM, only the first key frame is full key frame.
     1924
    15611925  if(!was_initialized && codec->encoder->id == CODEC_ID_DNXHD)
    15621926    setup_avid_atoms(file, vtrack, codec->buffer, bytes_encoded);
    15631927 
     
    15751939                           kf);
    15761940         
    15771941    result = !quicktime_write_data(file,
    1578                                    codec->buffer,
     1942                                   encoded_data,
    15791943                                   bytes_encoded);
    15801944
     1945#if ENCODE_VIDEO2
     1946    av_free_packet(&pkt);
     1947#endif
     1948
     1949    // Must go before lqt_write_frame_header() which increments vtrack->cur_chunk.
     1950    // cur_chunk is a frame number in storage order.
     1951    maybe_add_sdtp_entry(file, vtrack->cur_chunk, track);
     1952
    15811953    lqt_write_frame_footer(file, track);
    15821954         
    15831955    /* Write stats */
     
    16422014  else
    16432015    return 0;
    16442016 
    1645   pts = pkt.pts;
     2017  pts = pkt.pts * codec->encoding_pts_factor;
    16462018
    16472019  kf = !!(pkt.flags & AV_PKT_FLAG_KEY);
    16482020 
     
    16552027  if(bytes_encoded <= 0)
    16562028    return 0;
    16572029
    1658   pts = codec->avctx->coded_frame->pts;
     2030  pts = codec->avctx->coded_frame->pts * codec->encoding_pts_factor;
    16592031  kf = codec->avctx->coded_frame->key_frame;
    16602032 
    16612033#endif
     2034
     2035  if(kf && codec->is_xdcam_hd422 && vtrack->cur_chunk)
     2036    kf = LQT_PARTIAL_KEY_FRAME; // For XDCAM, only the first key frame is full key frame.
    16622037 
    16632038  if(bytes_encoded)
    16642039    {
     
    16692044                                   codec->buffer,
    16702045                                   bytes_encoded);
    16712046
     2047    // Must go before lqt_write_frame_header() which increments vtrack->cur_chunk.
     2048    // cur_chunk is a frame number in storage order.
     2049    maybe_add_sdtp_entry(file, vtrack->cur_chunk, track);
     2050
    16722051    lqt_write_frame_footer(file, track);
    16732052         
    16742053    if((codec->pass == 1) && codec->avctx->stats_out && codec->stats_file)
     
    16852064                               const char *key,
    16862065                               const void *value)
    16872066  {
     2067  int i;
    16882068  quicktime_video_map_t *vtrack = &file->vtracks[track];
    16892069  quicktime_ffmpeg_video_codec_t *codec = vtrack->codec->priv;
    16902070  if(!strcasecmp(key, "ff_qscale"))
     
    17062086      }
    17072087    return 0;
    17082088    }
     2089  else if(!strcasecmp(key, "prores_profile"))
     2090    {
     2091    for(i = 0; i < sizeof(lqt_prores_profiles)/sizeof(lqt_prores_profiles[0]); i++)
     2092      {
     2093      if(!strcasecmp((const char*)value, lqt_prores_profiles[i].lqt_name))
     2094        {
     2095        codec->prores_profile = i;
     2096        break;
     2097        }
     2098      }
     2099    }
    17092100 
    17102101  lqt_ffmpeg_set_parameter(codec->avctx,
    17112102#if LIBAVCODEC_VERSION_MAJOR >= 54
     
    17962187  return 0;
    17972188  }
    17982189
     2190static int init_compressed_xdcam_hd422(quicktime_t * file, int track)
     2191  {
     2192  quicktime_video_map_t * vtrack = &file->vtracks[track];
     2193
     2194  const char* fourcc = get_xdcam_hd422_fourcc(file, track, vtrack->ci.height);
     2195  if (fourcc)
     2196    {
     2197    memcpy(vtrack->track->mdia.minf.stbl.stsd.table[0].format, fourcc, 4);
     2198    return 0;
     2199    }
     2200  else
     2201    return -1;
     2202  }
     2203
     2204static int writes_compressed_xdcam_hd422(lqt_file_type_t type,
     2205                                         const lqt_compression_info_t * ci)
     2206  {
     2207    /* AVI doesn't support XDCAM family of formats */
     2208    if(type & (LQT_FILE_AVI | LQT_FILE_AVI_ODML))
     2209      return 0;
     2210
     2211    return ci->bitrate == 50000000;
     2212  }
     2213
    17992214
    18002215static void append_data_h264(lqt_packet_t * p, uint8_t * data, int len,
    18012216                             int header_len)
     
    18882303#if LIBAVCODEC_VERSION_INT < ((53<<16)|(8<<8)|0)
    18892304  codec->avctx = avcodec_alloc_context();
    18902305#else
    1891   codec->avctx = avcodec_alloc_context3(NULL);
     2306  codec->avctx = avcodec_alloc_context3((!vtrack || vtrack->do_encode) ? encoder : decoder);
    18922307#endif
    18932308  codec->encoder = encoder;
    18942309  codec->decoder = decoder;
    1895  
     2310
     2311  // vtrack can be NULL if called from lqt_writes_compressed
     2312  if(vtrack)
     2313    quicktime_init_bframe_detector(&codec->bframe_detector, vtrack);
     2314
    18962315  codec_base->priv = codec;
    18972316  codec_base->delete_codec = lqt_ffmpeg_delete_video;
    18982317  codec_base->flush = flush;
     
    19092328      codec_base->init_compressed   = init_compressed_mpeg4;
    19102329      codec_base->write_packet = write_packet_mpeg4;
    19112330      }
    1912     else if(encoder->id == CODEC_ID_MPEG2VIDEO)
    1913       {
    1914       codec_base->writes_compressed = writes_compressed_imx;
    1915       codec_base->init_compressed   = init_compressed_imx;
    1916       }
    19172331    else if(encoder->id == CODEC_ID_DVVIDEO)
    19182332      {
    19192333      codec_base->init_compressed = init_compressed_dv;
     
    19592373          quicktime_match_32(compressor, "mx5p") ||
    19602374          quicktime_match_32(compressor, "mx3n") ||
    19612375          quicktime_match_32(compressor, "mx4n") ||
    1962           quicktime_match_32(compressor, "mx5n"))
     2376          quicktime_match_32(compressor, "mx5n") ||
     2377          quicktime_match_32(compressor, "AVmp"))
    19632378    {
    19642379    vtrack->stream_cmodel = BC_YUV422P;
    19652380    codec->is_imx = 1;
     2381    codec_base->writes_compressed = writes_compressed_imx;
     2382    codec_base->init_compressed   = init_compressed_imx;
     2383    }
     2384  else if(quicktime_match_32(compressor, "xd54") ||
     2385          quicktime_match_32(compressor, "xd55") ||
     2386          quicktime_match_32(compressor, "xd5a") ||
     2387          quicktime_match_32(compressor, "xd5b") ||
     2388          quicktime_match_32(compressor, "xd5c") ||
     2389          quicktime_match_32(compressor, "xd5d") ||
     2390          quicktime_match_32(compressor, "xd5e") ||
     2391          quicktime_match_32(compressor, "xd5f"))
     2392    {
     2393    vtrack->stream_cmodel = BC_YUV422P;
     2394    codec->is_xdcam_hd422 = 1;
     2395    codec_base->writes_compressed = writes_compressed_xdcam_hd422;
     2396    codec_base->init_compressed   = init_compressed_xdcam_hd422;
     2397    }
     2398  else if(quicktime_match_32(compressor, "apch") ||
     2399          quicktime_match_32(compressor, "apcn") ||
     2400          quicktime_match_32(compressor, "apcs") ||
     2401          quicktime_match_32(compressor, "apco"))
     2402    {
     2403    vtrack->stream_cmodel = BC_YUV422P10;
    19662404    }
    19672405  else
    19682406    vtrack->stream_cmodel = BC_YUV420P;
  • plugins/png/qtpng.c

     
    2525#include "lqt_private.h"
    2626#include <quicktime/colormodels.h>
    2727#include <png.h>
     28#include <string.h>
    2829#include <stdlib.h>
    2930#include "qtpng.h"
    3031
  • plugins/schroedinger/extract_settings.c

     
    3939          fprintf(stderr, "    %s\n", s->enum_list[j]);
    4040          j++;
    4141          }
     42        fprintf(stderr, "Default: %s\n", s->enum_list[(int)(s->default_value)]);
    4243        break;
    4344      case SCHRO_ENCODER_SETTING_TYPE_DOUBLE:
    4445        fprintf(stderr, "Double\n");
  • src/Makefile.am

     
    9999stsd.c \
    100100stsdtable.c \
    101101stss.c \
     102stps.c \
     103sdtp.c \
    102104stsz.c \
    103105stts.c \
    104106texttrack.c \
     
    123125lqt_color.c \
    124126lqt_codecinfo.c \
    125127lqt_divx.c \
    126 lqt_qtvr.c
     128lqt_qtvr.c \
     129bframe_detector.c
    127130
    128131INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include
  • src/edts.c

     
    4343{
    4444        quicktime_atom_t leaf_atom;
    4545
    46         do
     46        while (quicktime_position(file) + 8 < edts_atom->end)
    4747        {
    4848                quicktime_atom_read_header(file, &leaf_atom);
    4949                if(quicktime_atom_is(&leaf_atom, "elst"))
    50                 { quicktime_read_elst(file, &edts->elst); }
     50                        quicktime_read_elst(file, &edts->elst);
    5151                else
    5252                        quicktime_atom_skip(file, &leaf_atom);
    53         }while(quicktime_position(file) < edts_atom->end);
     53        }
     54
     55        quicktime_set_position(file, edts_atom->end);
    5456}
    5557
    5658void quicktime_edts_dump(quicktime_edts_t *edts)
  • src/lqt_codecinfo.c

     
    601601  {
    602602  char * pos;
    603603  int ret;
    604   char * filename;
     604  char * filename = NULL;
     605  size_t filename_len = 0, new_size = 0;
    605606  DIR * directory;
    606607  struct dirent * directory_entry;
    607608  struct stat status;
     
    611612  lqt_codec_info_t * video_codecs_end;
    612613  lqt_codec_info_t * audio_codecs_end;
    613614
    614   filename = malloc(PATH_MAX * sizeof(char));
    615  
    616615  /* Set the end pointers so we can quickly add codecs after */
    617616
    618617 
     
    662661   
    663662    /* Now, the file should be a valid plugin, construct the filename */
    664663   
     664    new_size = strlen(plugin_dir) + strlen(directory_entry->d_name) + 2;
     665    if (new_size > filename_len)
     666      {
     667      filename_len = new_size;
     668      filename = realloc(filename, filename_len);
     669      if (!filename)
     670        exit(EXIT_FAILURE);
     671      }
    665672    strcpy(filename, plugin_dir);
    666673    strcat(filename, "/");
    667674    strcat(filename, directory_entry->d_name);
  • src/lqt_codecs.c

     
    540540  }
    541541
    542542void lqt_write_frame_header(quicktime_t * file, int track,
    543                             int pic_num1,
    544                             int64_t pic_pts, int keyframe)
     543                            int pic_num1, int64_t pic_pts,
     544                            enum LqtKeyFrame keyframe)
    545545  {
    546546  quicktime_video_map_t * vtrack = &file->vtracks[track];
    547547  quicktime_trak_t * trak = vtrack->track;
     
    590590  trak->chunk_samples = 1;
    591591  quicktime_write_chunk_footer(file, trak);
    592592 
    593   if(vtrack->keyframe)
     593  if(vtrack->keyframe == LQT_FULL_KEY_FRAME)
    594594    quicktime_insert_keyframe(file, vtrack->cur_chunk, track);
     595  else if(vtrack->keyframe == LQT_PARTIAL_KEY_FRAME)
     596    quicktime_insert_partial_keyframe(file, vtrack->cur_chunk, track);
     597
    595598  vtrack->cur_chunk++;
    596599  }
    597600
     
    749752  if(file->vtracks[track].timecode_track)
    750753    lqt_flush_timecode(file, track, time, 0);
    751754 
    752   file->vtracks[track].current_position++;
     755  vtrack->current_position++;
     756
     757  /* vtrack->current_position now points past the last frame
     758     we were asked to encode. If that frame was the last one
     759     but flushing the codec produces more output, there will be
     760     read access to vtrack->timestamps[vtrack->current_position]
     761     from lqt_write_frame_header(), therefore we need to make sure
     762     it's a valid address pointing to initialized memory. */
     763  if(vtrack->current_position >= vtrack->timestamps_alloc)
     764    {
     765    vtrack->timestamps_alloc += 1024;
     766    vtrack->timestamps = realloc(vtrack->timestamps,
     767                                 vtrack->timestamps_alloc *
     768                                 sizeof(*vtrack->timestamps));
     769    }
     770  vtrack->timestamps[vtrack->current_position] = -1;
    753771  return 0;
    754772  }
    755773
  • src/lqt_qtvr.c

     
    202202        file->moov.udta.ctyp[3] = 'r';
    203203        file->moov.udta.is_qtvr = 1;
    204204
     205        file->moov.mvhd.time_scale = time_scale;
     206
    205207        trak = quicktime_add_track(file);
    206208        quicktime_trak_init_qtvr(file, trak, QTVR_OBJ, width, height, duration, time_scale);
    207209        quicktime_obji_init(&file->qtvr_node[0].obji);
     
    225227        file->moov.udta.ctyp[3] = 'r';
    226228        file->moov.udta.is_qtvr = 1;
    227229
     230        file->moov.mvhd.time_scale = time_scale;
     231
    228232        trak = quicktime_add_track(file);
    229233        quicktime_trak_init_qtvr(file, trak, QTVR_PAN, width, height, duration, time_scale);
    230234        quicktime_pdat_init(&file->qtvr_node[0].pdat);
  • src/lqt_quicktime.c

     
    14401440  return 0;
    14411441  }
    14421442
     1443long quicktime_get_partial_keyframe_before(quicktime_t *file, long frame, int track)
     1444  {
     1445  quicktime_trak_t *trak = file->vtracks[track].track;
     1446  quicktime_stps_t *stps = &trak->mdia.minf.stbl.stps;
     1447  int i;
     1448
     1449  // Offset 1
     1450  frame++;
     1451
     1452  for(i = stps->total_entries - 1; i >= 0; i--)
     1453    {
     1454    if(stps->table[i].sample <= frame) return stps->table[i].sample - 1;
     1455    }
     1456
     1457  return 0;
     1458  }
     1459
    14431460#if 0
    14441461static long quicktime_get_keyframe_after(quicktime_t *file, long frame, int track)
    14451462  {
     
    14861503  stss->total_entries++;
    14871504  }
    14881505
     1506void quicktime_insert_partial_keyframe(quicktime_t *file, long frame, int track)
     1507  {
     1508  quicktime_trak_t *trak = file->vtracks[track].track;
     1509  quicktime_stps_t *stps = &trak->mdia.minf.stbl.stps;
     1510
     1511  if(file->file_type & (LQT_FILE_AVI|LQT_FILE_AVI_ODML))
     1512    {
     1513    // AVI doesn't support partial keyframes.
     1514    return;
     1515    }
     1516
     1517  // Expand table
     1518  if(stps->entries_allocated <= stps->total_entries)
     1519    {
     1520    stps->entries_allocated += 1024;
     1521    stps->table = realloc(stps->table,
     1522                          sizeof(*stps->table) *
     1523                          stps->entries_allocated);
     1524    }
     1525
     1526  stps->table[stps->total_entries].sample = frame+1;
     1527  stps->total_entries++;
     1528  }
     1529
     1530void quicktime_insert_sdtp_entry(quicktime_t *file, long sample, int track, uint8_t flags)
     1531  {
     1532  quicktime_trak_t *trak = file->vtracks[track].track;
     1533  quicktime_sdtp_t *sdtp = &trak->mdia.minf.stbl.sdtp;
     1534
     1535  if(file->file_type & (LQT_FILE_AVI|LQT_FILE_AVI_ODML))
     1536    {
     1537    // AVI doesn't support sdtp atom
     1538    return;
     1539    }
     1540
     1541  // Expand table
     1542  if(sdtp->entries_allocated <= sample)
     1543    {
     1544    sdtp->entries_allocated = sdtp->entries_allocated * 2 + 512;
     1545    sdtp->table = realloc(sdtp->table, sdtp->entries_allocated);
     1546    memset(sdtp->table + sdtp->total_entries, 0, sdtp->entries_allocated - sdtp->total_entries);
     1547    }
     1548
     1549  sdtp->table[sample] = flags;
     1550  if(sdtp->total_entries <= sample)
     1551    sdtp->total_entries = sample + 1;
     1552  }
    14891553
    14901554int quicktime_has_keyframes(quicktime_t *file, int track)
    14911555  {
     
    15211585  vtrack->current_position = 0;
    15221586  vtrack->cur_chunk = 0;
    15231587  vtrack->io_cmodel = BC_RGB888;
     1588  vtrack->do_encode = encode;
    15241589  quicktime_init_vcodec(vtrack, encode, info);
    15251590  return 0;
    15261591  }
     
    16251690      quicktime_init_video_map(&file->vtracks[i],
    16261691                               file->wr,
    16271692                               (lqt_codec_info_t*)0);
     1693#if 0
    16281694      /* Get decoder colormodel */
    16291695      file->vtracks[i].codec->decode_video(file, (uint8_t**)0, i);
    16301696      file->vtracks[i].io_cmodel = file->vtracks[i].stream_cmodel;
     
    16331699                              quicktime_video_width(file, i),
    16341700                              &file->vtracks[i].stream_row_span,
    16351701                              &file->vtracks[i].stream_row_span_uv);
    1636 
     1702#endif
    16371703      /* Get interlace mode */
    16381704      if((file->vtracks[i].interlace_mode == LQT_INTERLACE_NONE) &&
    16391705         (file->vtracks[i].track->mdia.minf.stbl.stsd.table[0].has_fiel))
     
    20542120      free(new_file);
    20552121    new_file = 0;
    20562122    }
    2057        
    2058        
    2059        
     2123       
    20602124  if(rd && new_file)
    20612125    {
    20622126    /* Set default decoding parameters */
     
    20642128      lqt_set_default_audio_parameters(new_file, i);
    20652129
    20662130    for(i = 0; i < new_file->total_vtracks; i++)
     2131      {
    20672132      lqt_set_default_video_parameters(new_file, i);
     2133     
     2134      /*
     2135       *  Get decoder colormodel
     2136       *  This might causing a first frame to be decoded, so we can't call this
     2137       *  before setting the parameters
     2138       */
     2139      new_file->vtracks[i].codec->decode_video(new_file, (uint8_t**)0, i);
     2140      new_file->vtracks[i].io_cmodel = new_file->vtracks[i].stream_cmodel;
     2141      lqt_get_default_rowspan(new_file->vtracks[i].stream_cmodel,
     2142                              quicktime_video_width(new_file, i),
     2143                              &new_file->vtracks[i].stream_row_span,
     2144                              &new_file->vtracks[i].stream_row_span_uv);
     2145      }
    20682146    }
    20692147       
    20702148  return new_file;
  • src/stbl.c

     
    3131  quicktime_stsd_init(&stbl->stsd);
    3232  quicktime_stts_init(&stbl->stts);
    3333  quicktime_stss_init(&stbl->stss);
     34  quicktime_stps_init(&stbl->stps);
    3435  quicktime_stsc_init(&stbl->stsc);
    3536  quicktime_stsz_init(&stbl->stsz);
     37  quicktime_sdtp_init(&stbl->sdtp);
    3638  quicktime_stco_init(&stbl->stco);
    3739  }
    3840
     
    135137  quicktime_stsd_delete(&stbl->stsd);
    136138  quicktime_stts_delete(&stbl->stts);
    137139  quicktime_stss_delete(&stbl->stss);
     140  quicktime_stps_delete(&stbl->stps);
    138141  quicktime_stsc_delete(&stbl->stsc);
    139142  quicktime_stsz_delete(&stbl->stsz);
     143  quicktime_sdtp_delete(&stbl->sdtp);
    140144  quicktime_stco_delete(&stbl->stco);
    141145  }
    142146
     
    147151  quicktime_stts_dump(&stbl->stts);
    148152  if(stbl->stss.total_entries)
    149153    quicktime_stss_dump(&stbl->stss);
     154  if(stbl->stps.total_entries)
     155    quicktime_stps_dump(&stbl->stps);
    150156  quicktime_stsc_dump(&stbl->stsc);
    151157  quicktime_stsz_dump(&stbl->stsz);
     158  if(stbl->sdtp.total_entries)
     159    quicktime_sdtp_dump(&stbl->sdtp);
    152160  quicktime_stco_dump(&stbl->stco);
    153161  if(stbl->has_ctts)
    154162    quicktime_ctts_dump(&stbl->ctts);
     
    187195      quicktime_read_stss(file, &stbl->stss);
    188196      quicktime_atom_skip(file, &leaf_atom);
    189197      }
     198    else if(quicktime_atom_is(&leaf_atom, "stps"))
     199      {
     200      quicktime_read_stps(file, &stbl->stps);
     201      quicktime_atom_skip(file, &leaf_atom);
     202      }
    190203    else if(quicktime_atom_is(&leaf_atom, "stsc"))
    191204      {
    192205      quicktime_read_stsc(file, &stbl->stsc);
     
    197210      quicktime_read_stsz(file, &stbl->stsz);
    198211      quicktime_atom_skip(file, &leaf_atom);
    199212      }
     213    else if(quicktime_atom_is(&leaf_atom, "sdtp"))
     214      {
     215      // This atom doesn't have its own number_of_entries field.
     216      long num_entries = stbl->stsz.total_entries; // That's what Apple docs tell us to use.
     217      if(num_entries <= 0)
     218        num_entries = leaf_atom.size - 12; // Fallback, in case stsz wasn't loaded yet.
     219      quicktime_read_sdtp(file, &stbl->sdtp, num_entries);
     220      quicktime_atom_skip(file, &leaf_atom);
     221      }
    200222    else if(quicktime_atom_is(&leaf_atom, "co64"))
    201223      {
    202224      quicktime_read_stco64(file, &stbl->stco);
     
    222244  quicktime_write_stsd(file, minf, &stbl->stsd);
    223245  quicktime_write_stts(file, &stbl->stts);
    224246  quicktime_write_stss(file, &stbl->stss);
     247  if(stbl->stps.total_entries)
     248    quicktime_write_stps(file, &stbl->stps);
    225249  quicktime_write_stsc(file, &stbl->stsc);
    226250  quicktime_write_stsz(file, &stbl->stsz);
     251
     252  // Must go after stsz, as it doesn't have its own number_of_entries field
     253  // and Apple docs say to use stsz.number_of_entries.
     254  if(stbl->sdtp.total_entries)
     255    quicktime_write_sdtp(file, &stbl->sdtp);
     256
    227257  quicktime_write_stco(file, &stbl->stco);
    228258  if(stbl->has_ctts)
    229259    quicktime_write_ctts(file, &stbl->ctts);
  • src/stsdtable.c

     
    707707
    708708  table->version = 0;
    709709  table->revision = 0;
    710   table->vendor[0] = 'l';
    711   table->vendor[1] = 'q';
    712   table->vendor[2] = 't';
    713   table->vendor[3] = ' ';
     710 
     711  /* We used to write "lqt " here, but some broken
     712     software expects "appl" */
     713  table->vendor[0] = 'a';
     714  table->vendor[1] = 'p';
     715  table->vendor[2] = 'p';
     716  table->vendor[3] = 'l';
    714717
    715718  table->temporal_quality = 100;
    716719  table->spatial_quality = 258;
  • src/trak.c

     
    427427  int64_t result = 0;
    428428
    429429  if(trak->mdia.minf.stbl.stco.total_entries &&
    430      chunk > trak->mdia.minf.stbl.stco.total_entries)
     430     chunk >= trak->mdia.minf.stbl.stco.total_entries)
    431431    result = table[trak->mdia.minf.stbl.stco.total_entries - 1].offset;
    432432  else
    433433    if(trak->mdia.minf.stbl.stco.total_entries)
  • new file src/bframe_detector.c

    - +  
     1/*******************************************************************************
     2 trak.c
     3
     4 libquicktime - A library for reading and writing quicktime/avi/mp4 files.
     5 http://libquicktime.sourceforge.net
     6
     7 Copyright (C) 2002 Heroine Virtual Ltd.
     8 Copyright (C) 2002-2011 Members of the libquicktime project.
     9
     10 This library is free software; you can redistribute it and/or modify it under
     11 the terms of the GNU Lesser General Public License as published by the Free
     12 Software Foundation; either version 2.1 of the License, or (at your option)
     13 any later version.
     14
     15 This library is distributed in the hope that it will be useful, but WITHOUT
     16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     18 details.
     19
     20 You should have received a copy of the GNU Lesser General Public License along
     21 with this library; if not, write to the Free Software Foundation, Inc., 51
     22 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     23*******************************************************************************/
     24
     25#include "lqt_private.h"
     26
     27void quicktime_init_bframe_detector(quicktime_bframe_detector* ctx, quicktime_video_map_t* vtrack)
     28  {
     29  ctx->frame = 0;
     30  ctx->ctts_entry_idx = 0;
     31  ctx->sample_within_entry = 0;
     32  ctx->ctts = &vtrack->track->mdia.minf.stbl.ctts;
     33  }
     34
     35/* Returns 1 for true, 0 for false, or a negative value if impossible to tell. */
     36int quicktime_is_bframe(quicktime_bframe_detector* ctx, int64_t frame)
     37  {
     38
     39  if(ctx->ctts_entry_idx < 0 || ctx->ctts_entry_idx >= ctx->ctts->total_entries)
     40    return -1;
     41
     42  if(frame > ctx->frame)
     43    {
     44    while(frame - ctx->frame >= ctx->ctts->table[ctx->ctts_entry_idx].sample_count - ctx->sample_within_entry)
     45      {
     46      if(ctx->ctts_entry_idx + 1 >= ctx->ctts->total_entries)
     47        return -1;
     48
     49      ctx->frame += ctx->ctts->table[ctx->ctts_entry_idx].sample_count - ctx->sample_within_entry;
     50      ctx->ctts_entry_idx++;
     51      ctx->sample_within_entry = 0;
     52      }
     53    ctx->sample_within_entry += frame - ctx->frame;
     54    ctx->frame = frame;
     55    }
     56  else if(frame < ctx->frame)
     57    {
     58    while(ctx->frame - frame > ctx->sample_within_entry)
     59      {
     60      if(ctx->ctts_entry_idx < 1)
     61        return -1;
     62
     63      ctx->frame -= ctx->sample_within_entry + 1;
     64      ctx->ctts_entry_idx--;
     65      ctx->sample_within_entry = ctx->ctts->table[ctx->ctts_entry_idx].sample_count - 1;
     66      }
     67    ctx->sample_within_entry -= ctx->frame - frame;
     68    ctx->frame = frame;
     69    }
     70
     71    return ctx->ctts->table[ctx->ctts_entry_idx].sample_duration <
     72       ctx->ctts->table[0].sample_duration;;
     73  }
  • new file src/sdtp.c

    - +  
     1/*******************************************************************************
     2 sdtp.c
     3
     4 libquicktime - A library for reading and writing quicktime/avi/mp4 files.
     5 http://libquicktime.sourceforge.net
     6
     7 Copyright (C) 2002-2011 Members of the libquicktime project.
     8
     9 This library is free software; you can redistribute it and/or modify it under
     10 the terms of the GNU Lesser General Public License as published by the Free
     11 Software Foundation; either version 2.1 of the License, or (at your option)
     12 any later version.
     13
     14 This library is distributed in the hope that it will be useful, but WITHOUT
     15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     17 details.
     18
     19 You should have received a copy of the GNU Lesser General Public License along
     20 with this library; if not, write to the Free Software Foundation, Inc., 51
     21 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     22*******************************************************************************/
     23
     24#include "lqt_private.h"
     25#include <stdlib.h>
     26#include <string.h>
     27
     28void quicktime_sdtp_init(quicktime_sdtp_t *sdtp)
     29  {
     30  sdtp->version = 0;
     31  sdtp->flags = 0;
     32  sdtp->total_entries = 0;
     33  sdtp->entries_allocated = 0;
     34  sdtp->table = NULL;
     35  }
     36
     37void quicktime_sdtp_delete(quicktime_sdtp_t *sdtp)
     38  {
     39  if(sdtp->table) free(sdtp->table);
     40  sdtp->total_entries = 0;
     41  sdtp->entries_allocated = 0;
     42  sdtp->table = 0;
     43  }
     44
     45void quicktime_sdtp_dump(quicktime_sdtp_t *sdtp)
     46  {
     47  long i;
     48  lqt_dump("     sample dependencies (sdtp)\n");
     49  lqt_dump("      version %d\n", sdtp->version);
     50  lqt_dump("      flags %ld\n", sdtp->flags);
     51  lqt_dump("      total_entries %ld\n", sdtp->total_entries);
     52  for(i = 0; i < sdtp->total_entries; i++)
     53    {
     54    unsigned flags = sdtp->table[i];
     55    char separator = ':';
     56    lqt_dump("       sample %ld: flags 0x%02x", i, flags);
     57    if(flags & 1)
     58      {
     59      lqt_dump("%c has_redundant_coding", separator);
     60      separator = ',';
     61      }
     62    if(flags & 2)
     63      {
     64      lqt_dump("%c no_redundant_coding", separator);
     65      separator = ',';
     66      }
     67    if(flags & 4)
     68      {
     69      lqt_dump("%c other_samples_depend_on_this_one", separator);
     70      separator = ',';
     71      }
     72    if(flags & 8)
     73      {
     74      lqt_dump("%c no_other_samples_depend_on_this_one", separator);
     75      separator = ',';
     76      }
     77    if(flags & 16)
     78      {
     79      lqt_dump("%c sample_depends_on_others", separator);
     80      separator = ',';
     81      }
     82    if(flags & 32)
     83      {
     84      lqt_dump("%c sample_doesnt_depend_on_others", separator);
     85      separator = ',';
     86      }
     87    if(flags & 64)
     88      {
     89      lqt_dump("%c earlier_display_times_allowed", separator);
     90      separator = ',';
     91      }
     92    if(flags & 128)
     93      {
     94      lqt_dump("%c reserved_bit_7", separator);
     95      separator = ',';
     96      }
     97    lqt_dump("\n");
     98    }
     99  }
     100
     101void quicktime_read_sdtp(quicktime_t *file, quicktime_sdtp_t *sdtp, long num_entries)
     102  {
     103  sdtp->version = quicktime_read_char(file);
     104  sdtp->flags = quicktime_read_int24(file);
     105  sdtp->total_entries = num_entries;
     106
     107  if(sdtp->entries_allocated < sdtp->total_entries)
     108    {
     109    sdtp->entries_allocated = sdtp->total_entries;
     110    sdtp->table = (uint8_t*)realloc(sdtp->table, sdtp->entries_allocated);
     111    }
     112
     113  memset(sdtp->table, 0, sdtp->total_entries);
     114  quicktime_read_data(file, sdtp->table, sdtp->total_entries);
     115  }
     116
     117void quicktime_write_sdtp(quicktime_t *file, quicktime_sdtp_t *sdtp)
     118  {
     119  quicktime_atom_t atom;
     120
     121  if(sdtp->total_entries)
     122    {
     123    quicktime_atom_write_header(file, &atom, "sdtp");
     124
     125    quicktime_write_char(file, sdtp->version);
     126    quicktime_write_int24(file, sdtp->flags);
     127    quicktime_write_data(file, sdtp->table, sdtp->total_entries);
     128    quicktime_atom_write_footer(file, &atom);
     129    }
     130  }
  • new file src/stps.c

    - +  
     1/*******************************************************************************
     2 stps.c
     3
     4 libquicktime - A library for reading and writing quicktime/avi/mp4 files.
     5 http://libquicktime.sourceforge.net
     6
     7 Copyright (C) 2002 Heroine Virtual Ltd.
     8 Copyright (C) 2002-2011 Members of the libquicktime project.
     9
     10 This library is free software; you can redistribute it and/or modify it under
     11 the terms of the GNU Lesser General Public License as published by the Free
     12 Software Foundation; either version 2.1 of the License, or (at your option)
     13 any later version.
     14
     15 This library is distributed in the hope that it will be useful, but WITHOUT
     16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     18 details.
     19
     20 You should have received a copy of the GNU Lesser General Public License along
     21 with this library; if not, write to the Free Software Foundation, Inc., 51
     22 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     23*******************************************************************************/
     24
     25#include "lqt_private.h"
     26#include <stdlib.h>
     27
     28void quicktime_stps_init(quicktime_stps_t *stps)
     29  {
     30  stps->version = 0;
     31  stps->flags = 0;
     32  stps->total_entries = 0;
     33  stps->entries_allocated = 0;
     34  stps->table = NULL;
     35  }
     36
     37void quicktime_stps_delete(quicktime_stps_t *stps)
     38  {
     39  if(stps->table) free(stps->table);
     40  stps->total_entries = 0;
     41  stps->entries_allocated = 0;
     42  stps->table = 0;
     43  }
     44
     45void quicktime_stps_dump(quicktime_stps_t *stps)
     46  {
     47  int i;
     48  lqt_dump("     partial sync sample (stps)\n");
     49  lqt_dump("      version %d\n", stps->version);
     50  lqt_dump("      flags %ld\n", stps->flags);
     51  lqt_dump("      total_entries %ld\n", stps->total_entries);
     52  for(i = 0; i < stps->total_entries; i++)
     53    {
     54    lqt_dump("       sample %lx\n", stps->table[i].sample);
     55    }
     56  }
     57
     58void quicktime_read_stps(quicktime_t *file, quicktime_stps_t *stps)
     59  {
     60  int i;
     61  stps->version = quicktime_read_char(file);
     62  stps->flags = quicktime_read_int24(file);
     63  stps->total_entries = quicktime_read_int32(file);
     64
     65  if(stps->entries_allocated < stps->total_entries)
     66    {
     67    stps->entries_allocated = stps->total_entries;
     68    stps->table = (quicktime_stps_table_t*)realloc(stps->table, sizeof(quicktime_stps_table_t) * stps->entries_allocated);
     69    }
     70
     71  for(i = 0; i < stps->total_entries; i++)
     72    {
     73    stps->table[i].sample = quicktime_read_int32(file);
     74    }
     75  }
     76
     77
     78void quicktime_write_stps(quicktime_t *file, quicktime_stps_t *stps)
     79  {
     80  int i;
     81  quicktime_atom_t atom;
     82
     83  if(stps->total_entries)
     84    {
     85    quicktime_atom_write_header(file, &atom, "stps");
     86
     87    quicktime_write_char(file, stps->version);
     88    quicktime_write_int24(file, stps->flags);
     89    quicktime_write_int32(file, stps->total_entries);
     90    for(i = 0; i < stps->total_entries; i++)
     91      {
     92      quicktime_write_int32(file, stps->table[i].sample);
     93      }
     94
     95    quicktime_atom_write_footer(file, &atom);
     96    }
     97  }