Any suggestions for an open source video encoder?

⌘-R in Chief
Posts: 1,247
Joined: 2002.05
Post: #16
*notes he said major advantage* Rolleyes
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #17
FreakSoftware Wrote:*notes he said major advantage* Rolleyes

Right, sorry about that. No *major* advantage to 64-bits by itself. You are correct.

Still, I like to develop new software using as much up-to-date APIs as I can nowadays. If I keep developing for 32-bit only, then at some point in the semi-near future, less and less of that code will be easy to port to newer APIs. That's just from my own experience though, so YMMV. This development thing is like constantly trying to hit a moving target.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #18
Yeah, Chipmunk gets some pretty nice speed improvements when running as 64bit as well. I seem to recall it was somewhere in the 20-30% range. Nothing to get too excited about, but a nice free boost for sure.

On the other hand, I've never released anything as 64bit and probably won't for a while until it's a good time to say goodbye to PPC Universal binaries.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 27
Joined: 2010.01
Post: #19
Hi I found this forum by accident, I was looking for a way to get at the applications context from within an sdl program and I found this forum , which gave me some very useful information about getting at the applications context.

I recently helped Yonas at the ffmpeg4iphone site fix and improve the iphone port of the ffmpeg based ffplay media player.

we get very impressive results,here's some info from our blog and test results with an xvid movie.
http://sol3.typepad.com/tagalong_develop...plete.html

test results here
http://web.me.com/cannonwc/Site/Photos_5.html#3

There are of course 3 problems with an sdl iphone application
the first 2 you just have to live with the 3rd you have to find some workaround.

the first issue is the lgpl license . You will have to publish your mods and natural objects, the second is "What is the status of sdl apps with apple reviewers"?.

the third, is the way sdl is structured makes it difficult to add anykind of decent gui to them.

One workaround that we are developing is to publish the app in kind of a suite with the sdl app dependent on an iphone client app. We use a custom url scheme to navigate between the apps and shared keychain to pass the movie url's to the sdl app for playing. Its a bit of a kludge but should work rather well.
we use a modification of the applicationdelegate c class mentioned on this site for both functions.

We are also independent of the ffmpeg4iphone project developing a purely open gl videoplayer based partly on the mythtv streamer app.

but we are running into issues, if anyone would like to help use, please pm me.

I posted some code snippets but will share all the code with any opengl person willing to help. this code will always remain open source.

specifically we are having trouble with two pieces of functionality. We can't seem to get sound playback to work, and although framerate is consistant there is considerable stuttering. This does not seem to happen in the sdl ffplay port, however one has to realize ffplay is very mature code and most of the bugs have been worked out, the issues I fixed where iphone specific related to armv6,7 optimizations and memory alignment. And two many hands over a period of a year or more in the code. version control is not the best, and the code is sloppy but it works.

Anyway my problems.

I think it has to do with my audioquue callback which is defined this way.

Code:
#define VIDEO_BUFFER_QUANTITY 10
#define VIDEO_QUEUE_SIZE_MAX 5 * 25 * 1024
#define AUDIO_QUEUE_SIZE_MAX 5 * 16 * 1024

#define AUDIO_BUFFER_SECONDS 1



void audioQueueOutputCallback(void *info, AudioQueueRef AudioQueue, AudioQueueBufferRef buffer);
int avReadPacket(void *opaque, uint8_t *buf, int buf_size);
int64_t avSeek(void *opaque, int64_t offset, int whence);



void audioQueueOutputCallback(void *info, AudioQueueRef unused, AudioQueueBufferRef buffer) {
    [(Player *)info fillAudioBuffer:buffer];
}

and the buffer fill method here.

- (void)fillAudioBuffer:(AudioQueueBufferRef)buffer {
    AudioTimeStamp bufferStartTime;
    
    buffer->mAudioDataByteSize = 0;
    buffer->mPacketDescriptionCount = 0;
    
    if (audioPacketQueue.count <= 0) {
        NSLog(@"Warning: No audio packets in queue");
        emptyAudioBuffer = buffer;
        return;
    }
    
    emptyAudioBuffer = nil;
    
    while (audioPacketQueue.count && buffer->mPacketDescriptionCount < buffer->mPacketDescriptionCapacity) {
        NSMutableData *packetData = [audioPacketQueue objectAtIndex:0];
        AVPacket *packet = [packetData mutableBytes];
        
        if (buffer->mAudioDataBytesCapacity - buffer->mAudioDataByteSize >= packet->size) {
            if (buffer->mPacketDescriptionCount == 0) {
                bufferStartTime.mSampleTime = packet->dts * avfContext->streams[audio_index]->codec->frame_size;
                bufferStartTime.mFlags = kAudioTimeStampSampleTimeValid;
            }
            
            memcpy((uint8_t *)buffer->mAudioData + buffer->mAudioDataByteSize, packet->data, packet->size);
            buffer->mPacketDescriptions[buffer->mPacketDescriptionCount].mStartOffset = buffer->mAudioDataByteSize;
            buffer->mPacketDescriptions[buffer->mPacketDescriptionCount].mDataByteSize = packet->size;
            buffer->mPacketDescriptions[buffer->mPacketDescriptionCount].mVariableFramesInPacket = avfContext->streams[audio_index]->codec->frame_size;
            
            buffer->mAudioDataByteSize += packet->size;
            buffer->mPacketDescriptionCount++;
            
            [audioPacketQueueLock lock];
            audioPacketQueueSize -= packet->size;
            [audioPacketQueue removeObjectAtIndex:0];
            [audioPacketQueueLock unlock];

            av_free_packet(packet);
        }
        else {
            break;
        }
    }

The video problem I think may be related to this

Code:
    video_index = -1;
    audio_index = -1;
    
    int i;
//    for(i = 0; i < avfContext->nb_streams; i++) {
     for (i = 0; i < avfContext->nb_streams && (video_index < 0 || audio_index < 0); i++) {
        enc = avfContext->streams[i]->codec;
        //avfContext->streams[i]->discard = AVDISCARD_ALL;
        switch(enc->codec_type) {
            case CODEC_TYPE_VIDEO:
                video_index = i;
            avfContext->streams[i]->discard = AVDISCARD_NONE;
                break;
            case CODEC_TYPE_AUDIO:
                audio_index = i;
               avfContext->streams[i]->discard = AVDISCARD_NONE;
            default:
            avfContext->streams[i]->discard = AVDISCARD_ALL;
                break;
        }
    }
    
    if (video_index >= 0) {
        avfContext->streams[video_index]->discard = AVDISCARD_DEFAULT;
    }
    
    if (audio_index >= 0) {
        avfContext->streams[audio_index]->discard = AVDISCARD_DEFAULT;
    }
    
    float aspectRatio = av_q2d(avfContext->streams[video_index]->codec->sample_aspect_ratio);
    if (!aspectRatio) {
        aspectRatio = av_q2d(avfContext->streams[video_index]->sample_aspect_ratio);
    }
    if (!aspectRatio) {
        aspectRatio = 4.0 / 3;
    }
    
    if ((float)self.bounds.size.height / self.bounds.size.width > aspectRatio) {
        GLfloat blank = (self.bounds.size.height - self.bounds.size.width * aspectRatio) / 2;
        points[0] = self.bounds.size.width;
        points[1] = self.bounds.size.height - blank;
        points[2] = 0;
        points[3] = self.bounds.size.height - blank;
        points[4] = self.bounds.size.width;
        points[5] = blank;
        points[6] = 0;
        points[7] = blank;
    }
    else {
        GLfloat blank = (self.bounds.size.width - (float)self.bounds.size.height / aspectRatio) / 2;
        points[0] = self.bounds.size.width - blank;
        points[1] = self.bounds.size.height;
        points[2] = blank;
        points[3] = self.bounds.size.height;
        points[4] = self.bounds.size.width - blank;
        points[5] = 0;
        points[6] = blank;
        points[7] = 0;
    }
    
    texturePoints[0] = 0;
    texturePoints[1] = 0;
    texturePoints[2] = 0;
    texturePoints[3] = 1;
    texturePoints[4] = 1;
    texturePoints[5] = 0;
    texturePoints[6] = 1;
    texturePoints[7] = 1;
    
    enc = avfContext->streams[video_index]->codec;
    AVCodec *codec = avcodec_find_decoder(enc->codec_id);
    if (!codec) {
        NSLog(@"Error: no encoder for this codec %d", enc->codec_id);
        av_close_input_file(avfContext);
        return;
    }
    
    ret = avcodec_open(enc, codec);
    if (ret < 0) {
        NSLog(@"Error: Could not open video decoder: %d", ret);
        av_close_input_file(avfContext);
        return;
    }
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #20
Hi michelleC, glad you stumbled upon iDevGames!

Unfortunately, PM's are off for non-moderators here. The forum owner felt it was better to leave them off for some spam reason.

I don't know anything about the video, but on the stuttering, relating to audio, unless you're decoding in hardware, which I assume you're not since you're attempting to use ffmpeg, AudioQueues is probably a problem. I would instead use RemoteIO. It's hard to figure out because of the lack of documentation (although that may have changed since I haven't looked lately) but it might be more consistent in terms of performance.
Quote this message in a reply
Member
Posts: 27
Joined: 2010.01
Post: #21
AnotherJake Wrote:Hi michelleC, glad you stumbled upon iDevGames!

Unfortunately, PM's are off for non-moderators here. The forum owner felt it was better to leave them off for some spam reason.

I don't know anything about the video, but on the stuttering, relating to audio, unless you're decoding in hardware, which I assume you're not since you're attempting to use ffmpeg, AudioQueues is probably a problem. I would instead use RemoteIO. It's hard to figure out because of the lack of documentation (although that may have changed since I haven't looked lately) but it might be more consistent in terms of performance.

I don't have any apps in the iphone app store just yet thats going to change very very soon. I'm holding up my two submissions to possibly include some of the new ffmpeg stuff I learned.

by the way you can email me at michelle@mooncatventures.com

Also

check out the site, I think you might be impressed

I could almost agree with you on audioques except for two things

The sdl version of ffplay uses the audioQueue.

And

I get absolutely no sound.

Again if any one would like to look at what I have an see if they see the issue I';; send them the code.

As for ffplay.

I would of thought that the extra layer of having sdl would slow down performance but I see no stuttering or skipping problems whatsoever.

Again if anyone would like to help build some simple vcr style controls that would be nice.

I am always open to sharing, and I like the tone of this forum very very much.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #22
michelleC Wrote:I could almost agree with you on audioques except for two things

The sdl version of ffplay uses the audioQueue.

And

I get absolutely no sound.

Ah yes, the no sound thing certainly puts a crimp in my hypothesis. Wink

It's entirely possible that Audio Queues might work just fine. Personally, I don't like working with Audio Queues very much. Apparently, most others don't either. I wrote GBMusicTrack a year and a half ago, which uses Audio Queues, and I *still* get emails about it from time to time. I don't use it myself anymore, except for testing if I need it. I had a recent problem with iPhone OS 3.x where I was getting stuttering of my OpenGL graphics from time to time and I used GBMusicTrack to localize the issue down to the way Audio Queues schedules buffer refills. Since there's no way to fully control that, I instead switched to using RemoteIO or OpenAL for any audio I generate or decode myself (e.g. Ogg/Vorbis), and things are much more predictable. For audio which has a compatible format with the hardware decoder, I use AVAudioPlayer, but of course, you can't schedule the playback timing, so indeed, for things like ffmpeg you'd probably have to stick to Audio Queues or RemoteIO, although you could also use OpenAL. Check out the iPhone version of Wolfenstein for an example of how that's done (sorry I don't have a link handy ATM but it should show up on a quick Google). They're using Tremor for audio decoding, but the technique of buffering through OpenAL is pretty clear.
Quote this message in a reply
Member
Posts: 27
Joined: 2010.01
Post: #23
The stuttering was mostly on the xvids, and I managed to reduce that to almost nothing.

basically if we can get the sound working on this WE we get a fairly decent movie player .

Still the sdl app outperforms this , I don't understand because sdl is an abstraction above opengl as such opengl by itself should be faster.

Again that ffplay code has been around for a while and is pretty optimized.
Quote this message in a reply
Member
Posts: 27
Joined: 2010.01
Post: #24
The video quality is actually better than that of the sdl app.
http://web.me.com/cannonwc/Site/Photos_6.html#0

Just have to spend more time trying to get the audio working.

It took me 5 days to figure out the issues with ffplay, so I think I will get this with time.

I passed the code along to a few other iphone developers, maybe they will have a solution.

I found a great book on Iphone inside info, I was kind of ignoring it because I thought it was only about toolchain driven iphone code for jailbroken iphones. but you can translate some of the techniques to the sdk. Especially if you are into the cutting edge stuff that me and the developers I hang with are into.

Iphone open aplications development is the name of the book.


Another book I just purchased is

Iphone game projects from apress books. I ran some of the examples, and there are some interesting techniques.

Even after almost 2 years I am still getting used to not being able to use private api's, in other dev environments and languages I am always taking code apart and looking for the loopholes and shortcuts. Oh well
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #25
michelleC Wrote:Still the sdl app outperforms this , I don't understand because sdl is an abstraction above opengl as such opengl by itself should be faster.

I haven't actually looked at SDL for iPhone, and I haven't seen the SDL app you're talking about, but I'd wager they're just using SDL to set up the GL context and using OpenGL directly anyway.
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #26
michelleC Wrote:Another book I just purchased is

Iphone game projects from apress books. I ran some of the examples, and there are some interesting techniques.

OT: I think Zwilnik, one of our moderators here, wrote the chapter on writing a GL ES game for that book.
Quote this message in a reply
Member
Posts: 27
Joined: 2010.01
Post: #27
AnotherJake Wrote:OT: I think Zwilnik, one of our moderators here, wrote the chapter on writing a GL ES game for that book.

Well I at least know what the problem is, I'm not building the audioqueue correctly and it throws an error.

Shouldn't be to hard to fix, I just have to find out what I am missing from the structure.

Still processes the video, but spends a bit of time erroring out when it tries to fill the queue, hence the stuttering, since its on the same thread.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [split] CocoaBASIC released as open source Carlos Camacho 0 3,831 Jan 28, 2011 04:13 PM
Last Post: Carlos Camacho
  Open source Fallout engine coming to Mac (with your help) mvBarracuda 75 53,402 Jan 22, 2009 08:52 AM
Last Post: mvBarracuda
  Port of an open source game engine iarwain 4 4,475 Aug 28, 2008 02:16 PM
Last Post: iarwain
  Spiderweb's Blades of Exile is now open source JeroMiya 3 4,765 Jun 12, 2007 02:35 PM
Last Post: stevejohnson
  Open source alternatives ootoovak 9 5,315 Dec 15, 2006 07:56 AM
Last Post: bronxbomber92