LAVCFile
Originally committed to SVN as r325.
This commit is contained in:
parent
33ff5515e5
commit
71511a3950
5 changed files with 138 additions and 16 deletions
|
@ -59,6 +59,7 @@ aegisub_SOURCES = about.cpp \
|
||||||
frame_main_events.cpp \
|
frame_main_events.cpp \
|
||||||
hilimod_textctrl.cpp \
|
hilimod_textctrl.cpp \
|
||||||
hotkeys.cpp \
|
hotkeys.cpp \
|
||||||
|
lavc_file.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
md5.c \
|
md5.c \
|
||||||
mkv_wrap.cpp \
|
mkv_wrap.cpp \
|
||||||
|
|
65
core/lavc_file.cpp
Normal file
65
core/lavc_file.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// AEGISUB
|
||||||
|
//
|
||||||
|
// Website: http://aegisub.cellosoft.com
|
||||||
|
// Contact: mailto:zeratul@cellosoft.com
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "lavc_file.h"
|
||||||
|
|
||||||
|
#ifdef USE_LAVC
|
||||||
|
|
||||||
|
LAVCFile::LAVCFile(wxString filename)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
fctx = NULL;
|
||||||
|
|
||||||
|
result = av_open_input_file(&fctx,filename.mb_str(wxConvLocal),NULL,0,NULL);
|
||||||
|
if (result != 0) throw _T("Failed opening file.");
|
||||||
|
|
||||||
|
// Get stream info
|
||||||
|
result = av_find_stream_info(fctx);
|
||||||
|
if (result < 0) {
|
||||||
|
av_close_input_file(fctx);
|
||||||
|
fctx = NULL;
|
||||||
|
throw _T("Unable to read stream info");
|
||||||
|
}
|
||||||
|
refs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LAVCFile::~LAVCFile()
|
||||||
|
{
|
||||||
|
if (fctx)
|
||||||
|
av_close_input_file(fctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
60
core/lavc_file.h
Normal file
60
core/lavc_file.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
||||||
|
// may be used to endorse or promote products derived from this software
|
||||||
|
// without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// AEGISUB
|
||||||
|
//
|
||||||
|
// Website: http://aegisub.cellosoft.com
|
||||||
|
// Contact: mailto:zeratul@cellosoft.com
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef LAVC_FILE_H
|
||||||
|
#define LAVC_FILE_H
|
||||||
|
|
||||||
|
#include <ffmpeg/avcodec.h>
|
||||||
|
#include <ffmpeg/avformat.h>
|
||||||
|
|
||||||
|
class LAVCFile {
|
||||||
|
private:
|
||||||
|
unsigned refs;
|
||||||
|
|
||||||
|
LAVCFile(wxString filename);
|
||||||
|
~LAVCFile();
|
||||||
|
public:
|
||||||
|
AVFormatContext *fctx;
|
||||||
|
|
||||||
|
static LAVCFile *Create(wxString filename) { return new LAVCFile(filename); }
|
||||||
|
LAVCFile *AddRef() { refs++; return this; };
|
||||||
|
void Release() { if (!--refs) delete this; };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* LAVC_FILE_H */
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) {
|
LAVCVideoProvider::LAVCVideoProvider(wxString filename, wxString subfilename) {
|
||||||
// Init variables
|
// Init variables
|
||||||
codecContext = NULL;
|
codecContext = NULL;
|
||||||
formatContext = NULL;
|
lavcfile = NULL;
|
||||||
codec = NULL;
|
codec = NULL;
|
||||||
stream = NULL;
|
stream = NULL;
|
||||||
frame = NULL;
|
frame = NULL;
|
||||||
|
@ -87,24 +87,18 @@ void LAVCVideoProvider::LoadVideo(wxString filename) {
|
||||||
// Close first
|
// Close first
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
|
lavcfile = LAVCFile::Create(filename);
|
||||||
// Load
|
// Load
|
||||||
try {
|
try {
|
||||||
// Open file
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
result = av_open_input_file(&formatContext,filename.mb_str(wxConvLocal),NULL,0,NULL);
|
|
||||||
if (result != 0) throw _T("Failed opening file.");
|
|
||||||
|
|
||||||
// Get stream info
|
|
||||||
result = av_find_stream_info(formatContext);
|
|
||||||
if (result < 0) throw _T("Unable to read stream info");
|
|
||||||
|
|
||||||
// Find video stream
|
// Find video stream
|
||||||
vidStream = -1;
|
vidStream = -1;
|
||||||
codecContext = NULL;
|
codecContext = NULL;
|
||||||
for (int i=0;i<formatContext->nb_streams;i++) {
|
for (int i=0;i<lavcfile->fctx->nb_streams;i++) {
|
||||||
codecContext = formatContext->streams[i]->codec;
|
codecContext = lavcfile->fctx->streams[i]->codec;
|
||||||
if (codecContext->codec_type == CODEC_TYPE_VIDEO) {
|
if (codecContext->codec_type == CODEC_TYPE_VIDEO) {
|
||||||
stream = formatContext->streams[i];
|
stream = lavcfile->fctx->streams[i];
|
||||||
vidStream = i;
|
vidStream = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -179,8 +173,9 @@ void LAVCVideoProvider::Close() {
|
||||||
codec = NULL;
|
codec = NULL;
|
||||||
|
|
||||||
// Close format context
|
// Close format context
|
||||||
if (formatContext) av_close_input_file(formatContext);
|
if (lavcfile)
|
||||||
formatContext = NULL;
|
lavcfile->Release();
|
||||||
|
lavcfile = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,7 +193,7 @@ void LAVCVideoProvider::UpdateDisplaySize() {
|
||||||
bool LAVCVideoProvider::GetNextFrame() {
|
bool LAVCVideoProvider::GetNextFrame() {
|
||||||
// Read packet
|
// Read packet
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
while (av_read_frame(formatContext, &packet)>=0) {
|
while (av_read_frame(lavcfile->fctx, &packet)>=0) {
|
||||||
// Check if packet is part of video stream
|
// Check if packet is part of video stream
|
||||||
if(packet.stream_index == vidStream) {
|
if(packet.stream_index == vidStream) {
|
||||||
// Decode frame
|
// Decode frame
|
||||||
|
@ -359,7 +354,7 @@ wxBitmap LAVCVideoProvider::GetFrame(int n) {
|
||||||
// Constant frame rate
|
// Constant frame rate
|
||||||
else {
|
else {
|
||||||
seekTo = n;
|
seekTo = n;
|
||||||
result = av_seek_frame(formatContext,vidStream,seekTo,AVSEEK_FLAG_BACKWARD);
|
result = av_seek_frame(lavcfile->fctx,vidStream,seekTo,AVSEEK_FLAG_BACKWARD);
|
||||||
|
|
||||||
// Seek to keyframe
|
// Seek to keyframe
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include <ffmpeg/avformat.h>
|
#include <ffmpeg/avformat.h>
|
||||||
#include "video_provider.h"
|
#include "video_provider.h"
|
||||||
#include "mkv_wrap.h"
|
#include "mkv_wrap.h"
|
||||||
|
#include "lavc_file.h"
|
||||||
|
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
@ -61,7 +62,7 @@ class LAVCVideoProvider : public VideoProvider {
|
||||||
private:
|
private:
|
||||||
MatroskaWrapper mkv;
|
MatroskaWrapper mkv;
|
||||||
|
|
||||||
AVFormatContext *formatContext;
|
LAVCFile *lavcfile;
|
||||||
AVCodecContext *codecContext;
|
AVCodecContext *codecContext;
|
||||||
AVStream *stream;
|
AVStream *stream;
|
||||||
AVCodec *codec;
|
AVCodec *codec;
|
||||||
|
|
Loading…
Reference in a new issue