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

Cant create thumbnails from the trimmed videos #107

Open
slyvelikov opened this issue Jun 12, 2024 · 8 comments
Open

Cant create thumbnails from the trimmed videos #107

slyvelikov opened this issue Jun 12, 2024 · 8 comments

Comments

@slyvelikov
Copy link

Hi ya ! As you can see from the title Im trying to create a thumbnail using MediaMetadataRetriever and the method .setDataSource(), but Im getting this error in my logcat and no thumbnail visually - getFrameAtTime: videoFrame is a NULL pointer. If I dont trim the video everything works fine. Also Im stitching 2 videos and Im trimming either of them. But if the videos arent trimmed it can make a thumbnail.

@slyvelikov slyvelikov changed the title Cnat get create thumbnails from the trimmed videos Cant create thumbnails from the trimmed videos Jun 12, 2024
@a914-gowtham
Copy link
Owner

Hi @slyvelikov , It is not reproducing. I tried to reproduce using below snippet. i take the first frame of the video.

public static Bitmap getFrameAt(Activity context, Uri videoUri) {
        try {
            MediaMetadataRetriever retriever = new MediaMetadataRetriever();
            retriever.setDataSource(context, videoUri);
            Bitmap res= retriever.getFrameAtTime(0);
            retriever.release();
            return res;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

and i pass Uri.parse(TrimVideo.getTrimmedVideoPath(result.getData())); to videoUri param.

try above snippet.

@slyvelikov
Copy link
Author

Hi @a914-gowtham and thank you for your quick response ! Im able to load videos with your library and trimming them, the issue comes after I stitch the 2 videos. So I have an app that allows the customers to "stitch" 2 videos. This is done when you record a video with a pause then Im making small chunks of videos out of these pauses. And after I trim one of the these chunks and then stitch it together with the other video parts and I cant get the thumbnail. Ive tried your snippet but it didnt work. Could this be because of a codec issues between your library and my stitching function ?

@a914-gowtham
Copy link
Owner

@slyvelikov are you using ffmpeg for stitching. if yes, you could check if both trimmer library and stitch functuon uses same version of ffmpeg.

@slyvelikov
Copy link
Author

Unfortunately, no, Im using file appending to "stick" them together.

@a914-gowtham
Copy link
Owner

could you share the sample code to append videos. @slyvelikov

@slyvelikov
Copy link
Author

public void appendFile(File fileToAppend) throws VideoFileException {
    if (null == fileToAppend) throw new IllegalArgumentException();
    if (null == mBaseFile) {
        // If first pass, set fileToAppend as the base file
        mBaseFile = fileToAppend;
        return;
    }
    if (null != mOutputFile) {
        // If nth pass, set previous output file as the base file
        mBaseFile = mOutputFile.getFile();
    }

    if (!fileToAppend.getAbsolutePath().equals(mBaseFile.getAbsolutePath())) {
        mOutputFile = new VideoFile();

// Log.d(TAG, "Invoking service to append " + fileToAppend.getName() + " to " + mBaseFile.getName());
// Log.d(TAG, "Service to write composite file fileToAppend: " + fileToAppend.getAbsolutePath());
// Log.d(TAG, "Service to write composite file mBaseFile: " + mBaseFile.getAbsolutePath());
// Log.d(TAG, "Service to write composite file to: " + mOutputFile.getFile().getAbsolutePath());
//
// Log.d(TAG, "Service mCtx: " + String.valueOf(mCtx));
Intent i = new Intent(mCtx, VideoStitchingService.class);
i.putExtra(VideoStitchingService.INTENT_EXTRA_BASE_FILE, mBaseFile);
i.putExtra(VideoStitchingService.INTENT_EXTRA_FILE_TO_APPEND, fileToAppend);
i.putExtra(VideoStitchingService.INTENT_EXTRA_OUTPUT_FILE, mOutputFile.getFile());
mCtx.startService(i);
}
}

@slyvelikov
Copy link
Author

I think the trimmed videos have been corrupted or MediaMetadataRetriever is perceiving them as corrupted.

@a914-gowtham
Copy link
Owner

I'm not sure if we can join two videos by file appending. but, merging two videos using ffmpeg will defenitely work.

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