Beispiel #1
0
gavl_time_t lqt_gavl_duration(quicktime_t * file)
  {
  gavl_time_t ret = 0, time;
  int i, imax;
  int timescale;
  int64_t time_scaled;
  
  imax = quicktime_audio_tracks(file);
  for(i = 0; i < imax; i++)
    {
    timescale = quicktime_sample_rate(file, i);
    time_scaled = quicktime_audio_length(file, i);

    time = gavl_time_unscale(timescale, time_scaled);
    if(ret < time)
      ret = time;
    }

  imax = quicktime_video_tracks(file);
  for(i = 0; i < imax; i++)
    {
    timescale = lqt_video_time_scale(file, i);
    time_scaled = lqt_video_duration(file, i);
    
    time = gavl_time_unscale(timescale, time_scaled);
    if(ret < time)
      ret = time;
    }
  return ret;
  }
Beispiel #2
0
void decode_mov(decode_t *decode)
{

    quicktime_t *qt_handle=NULL;
    unsigned char **p_raw_buffer;
    char *p_v_codec=NULL,*p_a_codec=NULL,*p_buffer=NULL,*p_tmp=NULL;
    int s_width=0,s_height=0,s_channel=0,s_bits=0,s_buff_size=0,s_audio_size=0,s_video_size=0,s_sample=0;
    int s_cont,s_frames;
    double s_fps=0;
    long s_audio_rate,s_qt_pos;
    uint16_t *p_mask1, *p_mask2;
    char msgbuf[TC_BUF_MIN];


    qt_handle = quicktime_open((char * )decode->name, 1, 0);
    if (qt_handle == NULL) {
        QT_ABORT("can't open quicktime!");
    }
    quicktime_set_preload(qt_handle, 10240000);
    s_fps = quicktime_frame_rate(qt_handle, 0);
    if (decode->format == TC_CODEC_PCM) {
        if (quicktime_audio_tracks(qt_handle) == 0) {
            QT_ABORT("no audio track in quicktime found!");
        }
        s_channel = quicktime_track_channels(qt_handle, 0);
        s_audio_rate = quicktime_sample_rate(qt_handle, 0);
        s_bits = quicktime_audio_bits(qt_handle, 0);
        s_audio_size = quicktime_audio_length(qt_handle,0);
        p_a_codec = quicktime_audio_compressor(qt_handle, 0);

        if (decode->frame_limit[1] < s_audio_size) {
            s_audio_size = decode->frame_limit[1] - decode->frame_limit[0];
        } else {
            s_audio_size -= decode->frame_limit[0];
        }

        if (decode->verbose) {
            tc_log_info(__FILE__, "Audio codec=%s, rate=%ld Hz, bits=%d, channels=%d",
                                  p_a_codec, s_audio_rate, s_bits, s_channel);
        }

        if ((s_bits != 8) && (s_bits != 16)) {
            tc_snprintf(msgbuf, sizeof(msgbuf), "unsupported %d bit rate"
                        " in quicktime!", s_bits);
            QT_ABORT(msgbuf);
        }
        if (s_channel > 2) {
            tc_snprintf(msgbuf, sizeof(msgbuf), "too many audio tracks "
                        "(%d) found in quicktime!", s_channel);
            QT_ABORT(msgbuf);
        }
        if (strlen(p_a_codec) == 0) {
            QT_ABORT("unsupported codec (empty!) in quicktime!");
        }
        if (quicktime_supported_audio(qt_handle, 0) != 0) {
            s_qt_pos = quicktime_audio_position(qt_handle,0);
            s_sample = (1.00 * s_channel * s_bits *s_audio_rate)/(s_fps * 8);
            s_buff_size = s_sample * sizeof(uint16_t);
            p_buffer = tc_malloc(s_buff_size);
            if (s_bits == 16)
                s_sample /= 2;
            if (s_channel == 1) {
                p_mask1=(uint16_t *)p_buffer;
                quicktime_set_audio_position(qt_handle, s_qt_pos + decode->frame_limit[0], 0);
                for (; s_audio_size > 0; s_audio_size -= s_sample) {
                    if (quicktime_decode_audio(qt_handle, p_mask1, NULL, s_sample, 0) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    QT_WRITE(decode->fd_out, p_buffer, s_buff_size);
                }
            } else {
                s_sample /= 2;
                p_mask1 = (uint16_t *)p_buffer;
                p_mask2 = tc_malloc(s_sample * sizeof(uint16_t));
                s_qt_pos += decode->frame_limit[0];
                quicktime_set_audio_position(qt_handle, s_qt_pos, 0);
                for (; s_audio_size > 0; s_audio_size -= s_sample) {
                    if (quicktime_decode_audio(qt_handle, p_mask1, NULL, s_sample, 0) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    quicktime_set_audio_position(qt_handle, s_qt_pos, 0);
                    if (quicktime_decode_audio(qt_handle,p_mask2, NULL,s_sample, 1) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    for (s_cont = s_sample - 1; s_cont >= 0; s_cont--)
                        p_mask1[s_cont<<1] = p_mask1[s_cont];
                    for (s_cont = 0; s_cont < s_sample; s_cont++)
                        p_mask1[1+(s_cont<<1)] = p_mask2[s_cont];
                    s_qt_pos += s_sample;
                    QT_WRITE(decode->fd_out, p_buffer, s_buff_size >> 1);
                }
                free(p_mask2);
            }
            free(p_buffer);
        }
#if !defined(LIBQUICKTIME_000904)
        else if ((strcasecmp(p_a_codec, QUICKTIME_RAW) == 0)
Beispiel #3
0
/*
 * mp4extract
 * required arg1 should be the MP4 input file
 * required arg2 should be the output file for the extracted track
 */
int main(int argc, char** argv)
{
    /* variables controlable from command line */
    bool extractVideo = TRUE;

    /* internal variables */
    char* mp4FileName = NULL;
    char* outFileName = NULL;
    quicktime_t* mp4File = NULL;
    FILE* outFile = NULL;
    int track = 0;
    int frame, numFrames;
    u_int8_t buf[64*1024];  /* big enough? */
    int bufSize;

    /* begin process command line */
    progName = argv[0];
    while (1) {
        int c = -1;
        int option_index = 0;
        static struct option long_options[] = {
            { "audio", 0, 0, 'a' },
            { "video", 0, 0, 'v' },
            { NULL, 0, 0, 0 }
        };

        c = getopt_long(argc, argv, "av",
            long_options, &option_index);

        if (c == -1)
            break;

        switch (c) {
        case 'a': {
            extractVideo = FALSE;
            break;
        }
        case 'v': {
            extractVideo = TRUE;
            break;
        }
        case '?':
            break;
        default:
            fprintf(stderr, "%s: unknown option specified, ignoring: %c\n",
                progName, c);
        }
    }

    /* check that we have at least two non-option arguments */
    if ((argc - optind) < 2) {
        fprintf(stderr,
            "usage: %s <mpeg-file> <mov-file>\n",
            progName);
        exit(1);
    }

    /* point to the specified file names */
    mp4FileName = argv[optind++];
    outFileName = argv[optind++];

    /* warn about extraneous non-option arguments */
    if (optind < argc) {
        fprintf(stderr, "%s: unknown options specified, ignoring: ", progName);
        while (optind < argc) {
            fprintf(stderr, "%s ", argv[optind++]);
        }
        fprintf(stderr, "\n");
    }

    /* end processing of command line */

    /* open the MP4 file */
    mp4File = quicktime_open(mp4FileName, 1, 0, 0);
    if (mp4File == NULL) {
        fprintf(stderr,
            "%s: error %s: %s\n",
            progName, mp4FileName, strerror(errno));
        exit(2);
    }

    /* open output file for writing */
    outFile = fopen(outFileName, "wb");
    if (outFile == NULL) {
        fprintf(stderr,
            "%s: error opening %s: %s\n",
            progName, outFileName, strerror(errno));
        exit(3);
    }

    /* add MPEG-4 video config info at beginning of output file */
    if (extractVideo) {
        if (!strcasecmp(quicktime_video_compressor(mp4File, track), "mp4v")) {
            u_char* pConfig;
            int configSize;

            quicktime_get_mp4_video_decoder_config(mp4File, track,
                &pConfig, &configSize);

            if (fwrite(pConfig, 1, configSize, outFile) != configSize) {
                fprintf(stderr,
                    "%s: write error: %s\n",
                    progName, strerror(errno));
                exit(4);
            }
            free(pConfig);
        }
    }

    if (extractVideo) {
        numFrames = quicktime_video_length(mp4File, track);
    } else {
        numFrames = quicktime_audio_length(mp4File, track);
    }

    for (frame = 0; frame < numFrames; frame++) {
        if (extractVideo) {
            bufSize = quicktime_read_frame(mp4File,
                &buf[0], track);
        } else { // extract audio
            bufSize = quicktime_read_audio_frame(mp4File,
                &buf[0], sizeof(buf), track);
        }
        if (bufSize <= 0) {
            fprintf(stderr,
                "%s: read error: %s\n",
                progName, strerror(errno));
            exit(5);
        }

        if (fwrite(buf, 1, bufSize, outFile) != bufSize) {
            fprintf(stderr,
                "%s: write error: %s\n",
                progName, strerror(errno));
            exit(4);
        }
    }

    /* cleanup */
    quicktime_close(mp4File);
    fclose(outFile);
    exit(0);
}