Permalink
Browse files

Adapted to some changes in FFmpeg libraries.

  • Loading branch information...
1 parent 96687cb commit 417998a80dbc1f327457f6d7c9ad9349fe41a7af @wedesoft committed May 19, 2012
Showing with 17 additions and 16 deletions.
  1. +10 −8 ext/avinput.cc
  2. +7 −8 ext/avoutput.cc
View
@@ -42,9 +42,9 @@ AVInput::AVInput( const string &mrl, bool audio ) throw (Error):
ERRORMACRO( err >= 0, Error, , "Error finding stream info for file \""
<< mrl << "\": " << strerror( errno ) );
for ( unsigned int i=0; i<m_ic->nb_streams; i++ ) {
- if ( m_ic->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
+ if ( m_ic->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO )
m_videoStream = i;
- if ( audio && m_ic->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO )
+ if ( audio && m_ic->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO )
m_audioStream = i;
};
#ifndef NDEBUG
@@ -136,8 +136,8 @@ void AVInput::readAV(void) throw (Error)
while ( av_read_frame( m_ic, &packet ) >= 0 ) {
if ( packet.stream_index == m_videoStream ) {
int frameFinished;
- int err = avcodec_decode_video( m_videoDec, m_avFrame, &frameFinished,
- packet.data, packet.size );
+ int err = avcodec_decode_video2( m_videoDec, m_avFrame, &frameFinished,
+ &packet );
ERRORMACRO( err >= 0, Error, ,
"Error decoding video frame of video \"" << m_mrl << "\"" );
if ( firstPacketPts == AV_NOPTS_VALUE ) firstPacketPts = packet.pts;
@@ -173,22 +173,22 @@ void AVInput::readAV(void) throw (Error)
m_audioFrame.reset();
unsigned char *data = packet.data;
int size = packet.size;
- while ( size > 0 ) {
+ while ( packet.size > 0 ) {
short int *buffer;
ERRORMACRO(posix_memalign((void **)&buffer, 16,
AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 2) == 0, Error, ,
"Error allocating aligned memory");
buffer[ AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 4 - 1 ] = '\000';
int bufSize = AVCODEC_MAX_AUDIO_FRAME_SIZE * 3 / 2;
- int len = avcodec_decode_audio2( m_audioDec, buffer, &bufSize, data, size );
+ int len = avcodec_decode_audio3( m_audioDec, buffer, &bufSize, &packet );
if ( len < 0 ) {
free( buffer );
m_audioFrame.reset();
ERRORMACRO( false, Error, , "Error decoding audio frame of video \""
<< m_mrl << "\"" );
};
- data += len;
- size -= len;
+ packet.data += len;
+ packet.size -= len;
if ( bufSize > 0 ) {
if ( m_audioFrame.get() ) {
SequencePtr extended( new Sequence( m_audioFrame->size() + bufSize ) );
@@ -202,6 +202,8 @@ void AVInput::readAV(void) throw (Error)
};
free( buffer );
};
+ packet.data = data;
+ packet.size = size;
av_free_packet( &packet );
if ( m_audioFrame.get() ) break;
} else
View
@@ -17,6 +17,7 @@
#ifndef NDEBUG
#include <iostream>
#endif
+#include <libavutil/mathematics.h>
#include "avoutput.hh"
#if !defined(INT64_C)
@@ -42,8 +43,8 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
{
try {
AVOutputFormat *format;
- format = guess_format( NULL, mrl.c_str(), NULL );
- if ( format == NULL ) format = guess_format( "mpeg", NULL, NULL );
+ format = av_guess_format( NULL, mrl.c_str(), NULL );
+ if ( format == NULL ) format = av_guess_format( "mpeg", NULL, NULL );
ERRORMACRO( format != NULL, Error, ,
"Could not find suitable output format for \"" << mrl << "\"" );
#ifdef HAVE_LIBAVFORMAT_ALLOC_CONTEXT
@@ -62,7 +63,7 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
m_videoStream->sample_aspect_ratio.den = aspectRatioDen;
AVCodecContext *c = m_videoStream->codec;
c->codec_id = videoCodec != CODEC_ID_NONE ? videoCodec : format->video_codec;
- c->codec_type = CODEC_TYPE_VIDEO;
+ c->codec_type = AVMEDIA_TYPE_VIDEO;
c->bit_rate = videoBitRate;
c->width = width;
c->height = height;
@@ -79,7 +80,7 @@ AVOutput::AVOutput( const string &mrl, int videoBitRate, int width, int height,
ERRORMACRO( m_audioStream != NULL, Error, , "Could not allocate audio stream" );
AVCodecContext *c = m_audioStream->codec;
c->codec_id = audioCodec != CODEC_ID_NONE ? audioCodec : format->audio_codec;
- c->codec_type = CODEC_TYPE_AUDIO;
+ c->codec_type = AVMEDIA_TYPE_AUDIO;
c->bit_rate = audioBitRate;
c->sample_rate = sampleRate;
c->channels = channels;
@@ -273,7 +274,7 @@ void AVOutput::writeVideo( FramePtr frame ) throw (Error)
packet.pts = av_rescale_q( c->coded_frame->pts, c->time_base,
m_videoStream->time_base );
if ( c->coded_frame->key_frame )
- packet.flags |= PKT_FLAG_KEY;
+ packet.flags |= AV_PKT_FLAG_KEY;
packet.stream_index = m_videoStream->index;
packet.data = (uint8_t *)m_videoBuf;
packet.size = packetSize;
@@ -303,7 +304,7 @@ void AVOutput::writeAudio( SequencePtr frame ) throw (Error)
if ( c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE )
packet.pts = av_rescale_q( c->coded_frame->pts, c->time_base,
m_audioStream->time_base );
- packet.flags |= PKT_FLAG_KEY;
+ packet.flags |= AV_PKT_FLAG_KEY;
packet.stream_index = m_audioStream->index;
packet.data = (uint8_t *)m_audioBuf;
packet.size = packetSize;
@@ -444,8 +445,6 @@ VALUE AVOutput::registerRubyClass( VALUE rbModule )
INT2FIX( CODEC_ID_VIXL ) );
rb_define_const( cRubyClass, "CODEC_ID_QPEG",
INT2FIX( CODEC_ID_QPEG ) );
- rb_define_const( cRubyClass, "CODEC_ID_XVID",
- INT2FIX( CODEC_ID_XVID ) );
rb_define_const( cRubyClass, "CODEC_ID_PNG",
INT2FIX( CODEC_ID_PNG ) );
rb_define_const( cRubyClass, "CODEC_ID_PPM",

0 comments on commit 417998a

Please sign in to comment.