<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Thanks for the answer.<br>
Is yours based on this player:
<a class="moz-txt-link-freetext" href="https://github.com/scrawl/ogre-ffmpeg-videoplayer/blob/master/VideoPlayer.cpp">https://github.com/scrawl/ogre-ffmpeg-videoplayer/blob/master/VideoPlayer.cpp</a>
?<br>
This is the one I used for reference partly. But it is based on
the dranger tutorials, which makes the code very hard to read and
also uses SDL for audio which makes that part rather useless to
me, too.<br>
<br>
SDL seems to call a callback, requesting a number of bytes/buffers
to be filled. But with OpenAL you need to put the complete audio
stream in there and OpenAL does the skipping itself (otherwise
that whole multi-buffering it does wouldn't make much sense). So
you don't really need to do any audio synching with OpenAL if I
got that correctly.<br>
<br>
Also, I do not see where you use the swr_convert I was pointed to
by Eugen. I am trying to use that (similar to sws_scale for image
frames), but it just keeps crashing (without error messages, of
course, that would be helpful).<br>
<br>
My decoder fills single frames to the player. But the player fills
the data of those frames into OpenGL buffers. That is what <code><span
class="pln">getDecodedAudioFrames</span><span class="pun"></span></code>
does. It is supposed to place all decoded frames it has evenly
into the passed number of buffers. But the result was just as bad
as placing each frame directly. So I decided to just put one frame
into each buffer. Which also didn't work.<br>
<br>
Here is the function, with both ways of doing it (the concatening
way is commented out):<br>
//------------------------------------------------------------------------------<br>
int <br>
FFmpegVideoPlayer::getDecodedAudioFrames(unsigned int
p_numBuffers, <br>
std::vector<uint8_t*>& p_audioBuffers, <br>
std::vector<unsigned int>& p_audioBufferSizes)<br>
{<br>
boost::mutex::scoped_lock lock(*_playerMutex);<br>
<br>
// Get the actual number of buffers to fill<br>
unsigned int numBuffers = <br>
_audioFrames.size() >= p_numBuffers? p_numBuffers :
_audioFrames.size();<br>
<br>
if (numBuffers == 0) return 0;<br>
<br>
AudioFrame* frame;<br>
for (unsigned int i = 0; i < numBuffers; ++i)<br>
{<br>
frame = _audioFrames.front();<br>
_audioFrames.pop_front();<br>
<br>
uint8_t* buffer = new uint8_t[frame->dataSize];<br>
memcpy(buffer, frame->data, frame->dataSize);<br>
_currentAudioStorage -= frame->lifeTime;<br>
<br>
p_audioBuffers.push_back(buffer);<br>
p_audioBufferSizes.push_back(frame->dataSize);<br>
<br>
delete frame;<br>
}<br>
<br>
<br>
// // Calculate the number of audio frames per buffer, and
special for the<br>
// // last buffer as there may be a rest<br>
// int numFramesPerBuffer = _audioFrames.size() / numBuffers;<br>
// int numFramesLastBuffer = _audioFrames.size() % numBuffers;<br>
// <br>
// // Fill each buffer<br>
// double totalLifeTime;<br>
// AudioFrame* frame;<br>
// std::vector<AudioFrame*> frames;<br>
// for (unsigned int i = 0; i < numBuffers; ++i)<br>
// {<br>
// // Get all frames for this buffer to count the lifeTime
and data size<br>
// unsigned int dataSize = 0;<br>
// totalLifeTime = 0.0;<br>
// for (unsigned int j = 0; j < numFramesPerBuffer; ++j)<br>
// {<br>
// frame = _audioFrames.front();<br>
// _audioFrames.pop_front();<br>
// frames.push_back(frame);<br>
// <br>
// totalLifeTime += frame->lifeTime;<br>
// dataSize += frame->dataSize;<br>
// }<br>
// _currentAudioStorage -= totalLifeTime;<br>
// <br>
// // Create the buffer<br>
// uint8_t* buffer = new uint8_t[dataSize];<br>
// <br>
// // Concatenate frames into a single memory target<br>
// uint8_t* destination = buffer;<br>
// for (unsigned int j = 0; j < numFramesPerBuffer; ++j)<br>
// {<br>
// memcpy(destination, frames[j]->data,
frames[j]->dataSize);<br>
// destination += frames[j]->dataSize;<br>
// }<br>
// <br>
// // Delete used frames<br>
// for (unsigned int j = 0; j < numFramesPerBuffer; ++j)<br>
// {<br>
// delete frames[j];<br>
// }<br>
// frames.clear();<br>
// <br>
// // Store buffer and size in return values<br>
// p_audioBuffers.push_back(buffer);<br>
// p_audioBufferSizes.push_back(dataSize);<br>
// }<br>
<br>
// We got at least one new frame, wake up the decoder for more
decoding<br>
_decodingCondVar->notify_all();<br>
<br>
return numBuffers;<br>
}<br>
<br>
Am 28.01.2014 02:56, schrieb Chris Robinson:<br>
</div>
<blockquote cite="mid:52E70E4F.70405@gmail.com" type="cite">On
01/27/2014 11:09 AM, Jan Drabner wrote:
<br>
<blockquote type="cite">Hey,
<br>
<br>
I am decoding an OGG video (theora & vorbis as codecs) and
want to show
<br>
it on the screen (using Ogre 3D) while playing its sound. I can
decode
<br>
the image stream just fine and the video plays perfectly with
the
<br>
correct frame rate, etc.
<br>
<br>
However, I cannot get the sound to play at all with OpenAL.
<br>
<br>
Here is how I decode audio packets (in a background thread, the
<br>
equivalent works just fine for the image stream of the video
file):
<br>
</blockquote>
<br>
The main thing that sticks out to me is that you seem to be
returning one frame per buffer, and you're limited to only 4
buffers. The frame size can be fairly small depending on the
format, so it's likely the queue underruns a lot.
<br>
<br>
Beyond that, it's difficult to say with just the provided code
snippets. Is there more available to view online anywhere? If not,
it may help to make a small test app that still exhibits the
problem (easier said than done, I know :/).
<br>
<br>
FWIW, I do have some code available that plays movies using Ogre,
OpenAL, and FFMPEG (and boost), and even has somewhat proper A/V
synchronization and aspect ratio correction. However the audio
code is heavily abstracted to the point where you don't directly
see OpenAL in the player code, so may not be terribly useful for
someone not familiar with the audio interface.
<br>
<br>
If you're interested anyway, you can see it here as part of the
OpenMW code base:
<br>
<a class="moz-txt-link-rfc2396E" href="https://github.com/zinnschlag/openmw/blob/master/apps/openmw/mwrender/videoplayer.cpp"><https://github.com/zinnschlag/openmw/blob/master/apps/openmw/mwrender/videoplayer.cpp></a>
<br>
<br>
_______________________________________________
<br>
openal mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:openal@openal.org">openal@openal.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://openal.org/mailman/listinfo/openal">http://openal.org/mailman/listinfo/openal</a>
<br>
<br>
</blockquote>
<br>
</body>
</html>