bool PhVideoEngine::open(QString fileName) { close(); PHDEBUG << fileName; _clock.setTime(0); _clock.setRate(0); _currentTime = PHTIMEMIN; if(avformat_open_input(&_formatContext, fileName.toStdString().c_str(), NULL, NULL) < 0) return false; PHDEBUG << "Retrieve stream information"; if (avformat_find_stream_info(_formatContext, NULL) < 0) return false; // Couldn't find stream information av_dump_format(_formatContext, 0, fileName.toStdString().c_str(), 0); // Find video stream : for(int i = 0; i < (int)_formatContext->nb_streams; i++) { AVMediaType streamType = _formatContext->streams[i]->codec->codec_type; PHDEBUG << i << ":" << streamType; switch(streamType) { case AVMEDIA_TYPE_VIDEO: _videoStream = _formatContext->streams[i]; PHDEBUG << "\t=> video"; break; case AVMEDIA_TYPE_AUDIO: if(_useAudio && (_audioStream == NULL)) _audioStream = _formatContext->streams[i]; PHDEBUG << "\t=> audio"; break; default: PHDEBUG << "\t=> unknown"; break; } } if(_videoStream == NULL) return false; // Looking for timecode type _tcType = PhTimeCode::computeTimeCodeType(this->framePerSecond()); emit timeCodeTypeChanged(_tcType); // Reading timestamp : AVDictionaryEntry *tag = av_dict_get(_formatContext->metadata, "timecode", NULL, AV_DICT_IGNORE_SUFFIX); if(tag == NULL) tag = av_dict_get(_videoStream->metadata, "timecode", NULL, AV_DICT_IGNORE_SUFFIX); if(tag) { PHDEBUG << "Found timestamp:" << tag->value; _timeIn = PhTimeCode::timeFromString(tag->value, _tcType); } PHDEBUG << "size : " << _videoStream->codec->width << "x" << _videoStream->codec->height; AVCodec * videoCodec = avcodec_find_decoder(_videoStream->codec->codec_id); if(videoCodec == NULL) { PHDEBUG << "Unable to find the codec:" << _videoStream->codec->codec_id; return false; } if (avcodec_open2(_videoStream->codec, videoCodec, NULL) < 0) { PHDEBUG << "Unable to open the codec:" << _videoStream->codec; return false; } _videoFrame = av_frame_alloc(); PHDEBUG << "length:" << this->length(); PHDEBUG << "fps:" << this->framePerSecond(); if(_audioStream) { AVCodec* audioCodec = avcodec_find_decoder(_audioStream->codec->codec_id); if(audioCodec) { if(avcodec_open2(_audioStream->codec, audioCodec, NULL) < 0) { PHDEBUG << "Unable to open audio codec."; _audioStream = NULL; } else { _audioFrame = av_frame_alloc(); PHDEBUG << "Audio OK."; } } else { PHDEBUG << "Unable to find codec for audio."; _audioStream = NULL; } } decodeFrame(0); _fileName = fileName; return true; }
void PhMediaPanel::onTCTypeComboChanged() { emit timeCodeTypeChanged(timeCodeType()); }
void PhMediaPanel::onTCTypeComboChanged() { if(_clock) _clock->setTimeCodeType(timeCodeType()); emit timeCodeTypeChanged(timeCodeType()); }