INDExOS / media-for-mobile

Media for Mobile
Other
456 stars 177 forks source link

Never ends scaling trnaformation #50

Open Gelassen opened 7 years ago

Gelassen commented 7 years ago

Hello,

I have applied M4M solution for scaling video in my app and on reasonable amount of videos (6-20 items) it mostly each time ended with issue. The issue is the transformation can not be stopped. App is processing video almost till 99% and after that I noticed constant call of garbage collector.

It is float bug which means it can not be reproduce with guarantee each time, but for reasonable amount of video it is almost happens every time. Please see my module below. I run it on Android 4.4. Xiaomi Note from the Service.

Do you have any idea why this issue happens?

08-25 13:04:36.509 29887-10194/com.example D/TAG: VideoProcessor:onProgress: 0.99767864 08-25 13:04:36.509 29887-10194/com.example D/TAG: VideoProcessor:onProgress: 0.9989656 08-25 13:04:37.839 29887-10194/com.example D/dalvikvm: GC_FOR_ALLOC freed 11342K, 34% free 52789K/79940K, paused 52ms, total 52ms 08-25 13:04:41.449 29887-10194/com.example D/dalvikvm: GC_FOR_ALLOC freed 11316K, 34% free 52771K/79940K, paused 47ms, total 47ms

public class MediaForMobile {

private static final String DEFAULT_VIDEO_MIME_TYPE = "video/avc";
private static final int DEFAULT_BITRATE = 2500;
private static final int DEFAULT_FRAME_RATE = 30;
private static final int DEFAULT_VIDEO_FRAME_INTERVAL = 1;

private static final String DEFAULT_AUDIO_MIME_TYPE = "audio/mp4a-latm";
private static final int DEFAULT_AUDIO_PROFILE = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
private static final int DEFAULT_AUDIO_BITRATE = 96 * 1024;
private static final int DEFAULT_AUDIO_SAMPLE_RATE = 44100;
private static final int DEFAULT_AUDIO_CHANNEL_COUNT = 2;

private AudioFormat originAudioFormat;
private MediaComposer mediaComposer;
private AndroidMediaObjectFactory factory;
private Uri mediaUri;

public void init(Context context, org.m4m.IProgressListener listener, CopyFileParams params) {
    try {
        factory = new AndroidMediaObjectFactory(context);
        mediaComposer = new org.m4m.MediaComposer(factory, listener);

        mediaUri = new Uri(params.getFrom().getFile().getAbsolutePath());
        Log.d(App.TAG_MEDIA, "TAG_MEDIA: " + mediaUri);
        MediaFileInfo mediaFileInfo = new org.m4m.MediaFileInfo(new AndroidMediaObjectFactory(context));
        mediaFileInfo.setUri(mediaUri);
        originAudioFormat = (org.m4m.AudioFormat) mediaFileInfo.getAudioFormat();
        Log.d(App.TAG, "Video format: " + mediaFileInfo.getVideoFormat().getMimeType());
    } catch (IOException e) {
        Log.e(App.TAG, "Failed to obtain the path", e);
    }
}

public void configureVideoEncoder(Pair<Integer, Integer> videoParams) {
    VideoFormatAndroid videoFormat = new VideoFormatAndroid(
            DEFAULT_VIDEO_MIME_TYPE,
            videoParams.first,
            videoParams.second
    );
    videoFormat.setVideoBitRateInKBytes(DEFAULT_BITRATE);
    videoFormat.setVideoFrameRate(DEFAULT_FRAME_RATE);
    videoFormat.setVideoIFrameInterval(DEFAULT_VIDEO_FRAME_INTERVAL);
    videoFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);
    mediaComposer.setTargetVideoFormat(videoFormat);
}

public void configureAudioEncoder() {
    AudioFormatAndroid audioFormat = new AudioFormatAndroid(
            DEFAULT_AUDIO_MIME_TYPE,
            originAudioFormat.getAudioSampleRateInHz(),
            originAudioFormat.getAudioChannelCount()
    );
    audioFormat.setAudioBitrateInBytes(DEFAULT_AUDIO_BITRATE);
    audioFormat.setAudioProfile(DEFAULT_AUDIO_PROFILE);
    mediaComposer.setTargetAudioFormat(audioFormat);
}

public void transcodeVideo(CopyFileParams params) {
    try {
        mediaComposer.addSourceFile(mediaUri);
        mediaComposer.setTargetFile(params.getTo().getFile().getAbsolutePath());
        mediaComposer.start();
    } catch (IOException e) {
        Log.e(App.TAG, "Failed to obtain file paths", e);
    }
}

public void release() {
    mediaComposer = null;
}

}

AshurQiang commented 7 years ago

I got the same issue, could you please tell me how you resolve it?

Gelassen commented 7 years ago

Hello, It looks like an issue inside the Lib somewhere on native level. My the best assumption is some of sync mechanism like cycle barrier doesn't get a signal from one of the threads. That's why it is always stick on 99% of progress.

I had limited time and implement the hack which listen the result (you can get in from on progress callback) and check if this result is the same for some period of time, e.g 5 sec, and start process since the beginning On 18 Nov 2016 5:05 p.m., "yunpeijiao" notifications@github.com wrote:

I got the same issue, could you please tell me how you resolve it?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/INDExOS/media-for-mobile/issues/50#issuecomment-261482153, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaBjicRlVl1189wcXshJCRuIeCyoYi9ks5q_WphgaJpZM4Jssp- .