Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support playing movies with libav and fix ffmpeg audio stutter #621

Merged
merged 3 commits into from Feb 4, 2015

Conversation

TheCycoONE
Copy link
Member

Makes libav an optional alternative to ffmpeg, selected in cmake.

The intro movie actually plays better with this libav code, but the frame
rate had to be determined experimentally as time_base for these videos in
libav seems to be giving a value of 0/1.

This addresses the issue of building on Ubuntu (e.g. #594)

The second commit fixes the audio stutter in ffmpeg, making it use the same path for calculating the out samples as libav is using.

The third commit fixes deprecated function warnings while falling back to earlier versions when those functions are not available. Most importantly it uses av_frame_free instead of av_free for frames which is needed to free extended data associated with frames.

@TheCycoONE
Copy link
Member Author

Actually I'd like to look into the framerate issue a little more before this is merged. The value I came up with is perfect for the intro video (17.5fps) but the lose videos have a drastically different intended framerate (8.333fps).

@TheCycoONE
Copy link
Member Author

Actually I was pretty close to the answer. It seems I should be using the time_base from the AVStream not the AVCodecContext. I'll fix this tonight or tomorrow night.

@TheCycoONE
Copy link
Member Author

I've corrected the framerate issue, and now I'm quite happy with the state of playing videos with libav. (So happy that unless I can improve the ffmpeg version I'm going to ship 0.50 with libav)

@TheCycoONE
Copy link
Member Author

Added a second commit to this pull request which fixes the stutter in ffmpeg. Incidentally I had caused it trying to take advantage of newer features. That they weren't available in libav and audio was working fine lead me to the solution.

@TheCycoONE TheCycoONE changed the title Support playing movies with libav Support playing movies with libav and fix ffmpeg audio stutter Jan 26, 2015
@TheCycoONE
Copy link
Member Author

Added explicit include for libavutil/mathematics.h for libav-9.16 as reported by @legluondunet

@TheCycoONE
Copy link
Member Author

Note: I have verified that this works with libav-11.1 for windows and Ubuntu 14.10. This code does not work on the earlier libav-9.16 included in Ubuntu 14.04 LTS. (Of note: avplay in ubuntu 14.04 is also unable to properly play intro.sm4 so it may not be possible to support our movies with that version of libav.)

@Lego3
Copy link
Contributor

Lego3 commented Jan 31, 2015

I didn't manage to create 64-bit binaries for Visual Studio here either... I think I'll scrap Visual Studio soon. :-P On Ubuntu on the other hand everything worked as a charm as usual.

@Lego3
Copy link
Contributor

Lego3 commented Jan 31, 2015

While the sound doesn't stutter anymore I get some image stuttering back and forth when running on a virtual Ubuntu machine (always had this)

@TheCycoONE
Copy link
Member Author

Again you have to run the libav compile instructions from the Visual Studio x64 console. Enhanced edition can't, but community edition and pro have it.

@TheCycoONE
Copy link
Member Author

@Lego3 when you say 'always had this', you mean you had an issue with video stuttering in ffmepg as well and libav just doesn't fix it? Is there anything holding this back from being merged?

@Lego3
Copy link
Contributor

Lego3 commented Feb 1, 2015

I don't think there is anything holding it back, no. I managed to compile once I found the correct command prompt. :-P CMake still asks for postproc, which I couldn't see is a part of libav. But the game works fine without it...

@Lego3
Copy link
Contributor

Lego3 commented Feb 1, 2015

And by the way, has SDL_mixer inclusion always been under the advanced tab in CMake?

@TheCycoONE
Copy link
Member Author

You are right about postproc. I'll fix FindLibAV to match all the right libraries before it's merged. Not sure about sdl2mixer - not a change I made.

@TheCycoONE
Copy link
Member Author

Removed postproc and add libavfilter to FindLibAV.cmake for correctness. Neither are used by CorsixTH.

Makes libav an optional alternative to ffmpeg, selected in cmake.

The intro movie plays perfectly with this libav code.
Attempting to calculate the resampling delay for determining the number
of out samples was actually causing underruns. There is no harm in not
accounting for any resample delay because any samples not taken are
buffered for the next conversion.
Use av_frame_alloc, av_frame_unref, and av_frame_free instead of their
earlier equivalents. In the case of av_frame_free we were not using
the earlier equivalent but av_free.  With these changes avcodec_frame_free
will be used on versions that don't yet support av_frame_free. FFMPEG
versions that do not support avcodec_frame_free are not supported with
this commit.
Lego3 added a commit that referenced this pull request Feb 4, 2015
Support playing movies with libav and fix ffmpeg audio stutter
@Lego3 Lego3 merged commit 19e2ad1 into CorsixTH:master Feb 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants