MP4TrackId *MpegCreator (MP4FileHandle mp4file, const char *fname, bool doEncrypt) { mpeg2ps_t *file; int video_streams, audio_streams; int ix; MP4TrackId *pTrackId; file = mpeg2ps_init(fname); video_streams = mpeg2ps_get_video_stream_count(file); audio_streams = mpeg2ps_get_audio_stream_count(file); pTrackId = (MP4TrackId *)malloc(sizeof(MP4TrackId) * (audio_streams + video_streams + 1)); for (ix = 0; ix < video_streams + audio_streams + 1; ix++) { pTrackId[ix] = MP4_INVALID_TRACK_ID; } for (ix = 0; ix < video_streams; ix++) { pTrackId[ix] = VideoCreate(mp4file, file, ix, doEncrypt); } for (ix = 0; ix < audio_streams; ix++) { pTrackId[ix + video_streams] = AudioCreate(mp4file, file, ix, doEncrypt); } return pTrackId; }
bool MediaEngine::openContext() { #ifdef USE_FFMPEG InitFFmpeg(); if (m_pFormatCtx || !m_pdata) return false; m_mpegheaderReadPos = 0; m_decodingsize = 0; u8* tempbuf = (u8*)av_malloc(m_bufSize); m_pFormatCtx = avformat_alloc_context(); m_pIOContext = avio_alloc_context(tempbuf, m_bufSize, 0, (void*)this, _MpegReadbuffer, NULL, 0); m_pFormatCtx->pb = m_pIOContext; // Open video file if (avformat_open_input((AVFormatContext**)&m_pFormatCtx, NULL, NULL, NULL) != 0) return false; if (avformat_find_stream_info(m_pFormatCtx, NULL) < 0) { closeContext(); return false; } if (m_videoStream >= (int)m_pFormatCtx->nb_streams) { WARN_LOG_REPORT(ME, "Bad video stream %d", m_videoStream); m_videoStream = -1; } if (m_videoStream == -1) { // Find the first video stream for(int i = 0; i < (int)m_pFormatCtx->nb_streams; i++) { if(m_pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { m_videoStream = i; break; } } if(m_videoStream == -1) return false; } if (!setVideoStream(m_videoStream, true)) return false; setVideoDim(); m_audioContext = AudioCreate(m_audioType); m_isVideoEnd = false; m_noAudioData = false; m_mpegheaderReadPos++; av_seek_frame(m_pFormatCtx, m_videoStream, 0, 0); #endif // USE_FFMPEG return true; }
HSOUND AudioCreateMusic(LPSTR waveFile) { return AudioCreate(waveFile, TRUE); }
HSOUND AudioCreateSFX(LPSTR waveFile) { return AudioCreate(waveFile, FALSE); }