Closed
Description
This will probably need:
- fairly new FFmpeg (probably 4.x)
- somewhat different implementation (what we use is internal API, MediaCodec is standalone)
The implementation will need a separate branch for 4.x FFmpeg.
While switching to FFmpeg 4.x we may simplify the PixelFormat hacks that we use, there is infrastructure
for that in FFmpeg 4.x. This is already in comments in relevant places of hvd.c
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
bmegli commentedon Feb 22, 2019
Wrong - MediaCodec is supported since FFmpeg 3.1
bmegli commentedon Feb 24, 2019
Got working proof of concept with:
FFmpeg was build by changing
configure
filewith:
with script:
NHVD was compiled with hand written Android.mk and Application.mk and
ndk-build
Implementation changes include:
bmegli commentedon Feb 25, 2019
hmm, it seems this went through software path, not hardware (not through mediacodec)
bmegli commentedon Mar 2, 2019
The scripts, Android.mk, Application.mk and HVD software decoding path were added in:
NHVD android branch
bmegli commentedon Mar 3, 2019
Ok, got one step further with successfully initializing hardware with MediaCodec
For any lost souls following this path the catches are following:
JNI OnLoad
In your shared library export
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* aReserved)
Attach your thread to VM if needed
Set Java VM for ffmpeg
Without that you will get errors along the line "VM not set", I don't remember exactly.
Find
h264_mediacodec
decoder and alloc contexte.g.
Before opening the context you HAVE to supply additional information
Without that you are going to get "Operation not permitted" in
avcodec_open2
If you are decoding from file you can get it from avformat
Above is one more catch - you can override your
"h264_mediacodec"
decoder in av_find_best_stream to"h264"
if you use the same variable for decoder.Now the important part
So some of the fields set in avcodec_parameters_to_context are mandatory for MediaCodec (probably extradata)
You may finally open the context
correctly initialize hardware through MediaCodec
bmegli commentedon Mar 3, 2019
Ok, successfully decoded in hardware (from file) and rendered it.
Some funny warnings present in logcat.
Data returned in NV12, needs some new shader implementation.
bmegli commentedon Mar 3, 2019
I still need a method of init from raw stream instead of file (and avformat).
bmegli commentedon Mar 4, 2019
Confirmed with test - removing extradata lead to failure in openning context
This is also confirmed by MediaCodec documentation - SPS and PPS needed as setup data
bmegli commentedon Mar 4, 2019
FWIW - the minimal codec context parameters to make it work are:
This however states only about this case (this device, this MediaCodec backend, software versions, etc.)
bmegli commentedon Mar 5, 2019
A rough idea how to extract extradata with bitstream filters was implemented in:
extract_extradata branch in 2b9bf0f
(may not be entirely correct but works)
All put together:
May be used to test if the idea will work.
bmegli commentedon Mar 5, 2019
Implemented rough idea and confirmed that it is possible to make it work.
When streaming to Unity (MediaCodec -> NV12 -> pointer to unity -> textures update -> shader)
there doesn't seem to be improvement over software decoding.
There is occasional "hiccup" in the video, short but noticeable.
Other approaches need to be tested (e.g. decoding directly to Android surface and displaying this in Unity).
experimental mediacodec with extradata extraction
bmegli commentedon May 15, 2019
See also
Aman Gupta - An FFmpeg maintainer's deep dive: iOS VideoToolbox and Android MediaCodec integration - Demuxed 2018
11 remaining items