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

Android : How to use https://github.com/ypresto/android-transcoder with this utility? #4

Open
PankajChunchun opened this issue Dec 27, 2017 · 2 comments

Comments

@PankajChunchun
Copy link

PankajChunchun commented Dec 27, 2017

Hi Yuya Tanaka,

I am working on an Android project, where requirement is to transcode a video. So I am using https://github.com/ypresto/android-transcoder, but this utility does not place moov atom at beginning of file.

So I went through this utility and wanted to use it.

I did not find any documentation regarding how can I use it with https://github.com/ypresto/android-transcoder. Can you please add some documentation? Steps would also be fine, later I will add documentation for this utility and will share pull request.

Thank you.

@PankajChunchun
Copy link
Author

I saw your comment in a closed issue #2

So what I understood is

Step1 : Transcode the video
Step2: Use utility to add "moov" in transcoded video

And my implementation looks like

MediaTranscoder.Listener listener = new MediaTranscoder.Listener() {
                        @Override
                        public void onTranscodeProgress(double progress) {
                        }

                        @Override
                        public void onTranscodeCompleted() {
                            Log.d(TAG, "transcoding took " + (SystemClock.uptimeMillis() - startTime) + "ms");
                            onTranscodeFinished(true, "transcoded file placed on " + file, parcelFileDescriptor);

                            Log.d(TAG, "Adding MOOV at beging of this file...");

                            File videoToPlay = null;

                            try {
                                if (QtFastStart.fastStart(file, moovFile)) {
                                    Log.d(TAG, "Added MOOV at beging of this file...");
                                    // Use output file path to play video
                                    videoToPlay = moovFile;
                                } else {
                                    Log.d(TAG, "MOOV present in this FILE");
                                    // Use input file path, as it has moov already so output file will not exists.
                                    videoToPlay = file;
                                }

                            } catch (QtFastStart.MalformedFileException m) {
                                Log.e(TAG, m.toString());
                            } catch (QtFastStart.UnsupportedFileException q) {
                                Log.e(TAG, q.toString());
                            } catch (QtFastStart.QtFastStartException e) { // catches QtFastStartException other than MalformedFileException and UnsupportedFileException
                                Log.e(TAG, e.toString());
                            } catch (IOException e) {
                                Log.e(TAG, e.toString());
                            }


                            Log.d(TAG, "Playing video " + videoToPlay.getAbsolutePath());

                            Uri uri = FileProvider.getUriForFile(MainActivity.this, FILE_PROVIDER_AUTHORITY, videoToPlay);
                            startActivity(new Intent(Intent.ACTION_VIEW)
                                    .setDataAndType(uri, "video/mp4")
                                    .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION));
                        }

                        @Override
                        public void onTranscodeCanceled() {
                            onTranscodeFinished(false, "Transcoder canceled.", parcelFileDescriptor);
                        }

                        @Override
                        public void onTranscodeFailed(Exception exception) {
                            onTranscodeFinished(false, "Transcoder error occurred.", parcelFileDescriptor);
                        }
                    };
                    Log.d(TAG, "transcoding into " + file);
                    mFuture = MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(),
                            MediaFormatStrategyPresets.createAndroid720pStrategy(8000 * 1000, 128 * 1000, 1), listener);

Can you please confirm If I am doing it in correct way?

@masterwok
Copy link

@PankajChunchun does one have to wait for the transcoding to complete? In my use case, I want to start playing the stream immediately. This solution will not work for me.

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

No branches or pull requests

2 participants