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

Why the video file can't play on my android phone? #62

Open
ghost opened this issue Nov 12, 2014 · 19 comments
Open

Why the video file can't play on my android phone? #62

ghost opened this issue Nov 12, 2014 · 19 comments

Comments

@ghost
Copy link

ghost commented Nov 12, 2014

I had created a Mp4 file by using SequenceEncoder.java, but it can't play on my android phone .It just can play on my computer.

@sokishan4u
Copy link

i can only see the black screen in the video plz help thankx

@svitvitskiy
Copy link
Collaborator

Could you post the device name/sw version?

@coralinejones1985
Copy link

I ran into the same problem: I can view video on PC only. Emulator shows only one rotated image of all sequence and closes video.

@svitvitskiy
Copy link
Collaborator

Could you please attach a sample code, your input file and the output file? This would help me a lot to reproduce and fix the problem. Thanks in advance.

@coralinejones1985
Copy link

SequenceEncoder sequenceEncoder = new SequenceEncoder(SDPathToFile("", "out2.mp4"));
for (int i = 0; i < imagePathList.size(); i++) {
String path = getPath(context, Uri.parse(imagePathList.get(i)));
sequenceEncoder.encodeImage(BitmapFactory.decodeFile(path, null));
}
sequenceEncoder.finish();

I use images from external directory as input files.

@coralinejones1985
Copy link

out2.mp4.zip

here's my out put

@coralinejones1985
Copy link

I also use this code and it gives the same result:

try {
int timescale = 25;
SeekableByteChannel channel = NIOUtils.writableFileChannel(SDPathToFile("", "out2.mp4"));
MP4Muxer muxer = new MP4Muxer(channel, Brand.MP4);
FramesMP4MuxerTrack outTrack = muxer.addTrack(TrackType.VIDEO, timescale);
H264Encoder encoder = new H264Encoder();
ByteBuffer outBuffer = ByteBuffer.allocate(640 * 480 * 6);

        ArrayList<ByteBuffer> spsList = new ArrayList<>();
        ArrayList<ByteBuffer> ppsList = new ArrayList<>();

        for (int i = 0; i < imagePathList.size(); i++) {
            String path = getPath(context, Uri.parse(imagePathList.get(i)));
            Bitmap bitmap = BitmapFactory.decodeFile(path, null);

            Picture rgbPicture = BitmapUtil.fromBitmap(bitmap);
            Picture yuvPicture = Picture.create(rgbPicture.getWidth(),
                    rgbPicture.getHeight(), encoder.getSupportedColorSpaces()[0]);

            Transform transform = ColorUtil.getTransform(
                    ColorSpace.RGB, encoder.getSupportedColorSpaces()[0]);
            transform.transform(rgbPicture, yuvPicture);

            ByteBuffer result = encoder.encodeFrame(yuvPicture, outBuffer);
            outBuffer.clear();

            spsList.clear();
            ppsList.clear();
            H264Utils.wipePS(result, spsList, ppsList);
            H264Utils.encodeMOVPacket(result);

            outTrack.addFrame(new MP4Packet(result, i * 2, timescale, 1, i, true, null, i * 2, 0));
            Log.d(TAG, "Processed " + (i + 1) + " images");
        }

        outTrack.addSampleEntry(H264Utils.createMOVSampleEntry(spsList, ppsList, 4));
        muxer.writeHeader();
        NIOUtils.closeQuietly(channel);
    } catch (Exception e) {
        e.printStackTrace();
    }

@coralinejones1985
Copy link

Can you help me figure out what went wrong?..

@svitvitskiy
Copy link
Collaborator

Sure, just couldn't get around to doing it earlier.

Stan

On Tuesday, January 19, 2016, Кристина notifications@github.com wrote:

Can you help me figure out what went wrong?..


Reply to this email directly or view it on GitHub
#62 (comment).

@svitvitskiy
Copy link
Collaborator

I can see VLC is not playing the file even after the remuxing so I suspect
it doesn't understand a particular "flavor" of h.264 that I am using right
now (CAVLC baseline profile).

I'll try to see if CABAC would fix this problem.

On Tue, Jan 19, 2016 at 12:55 PM, Stanislav Vitvitskiy <
stanislav.vitvitskiy@gmail.com> wrote:

Sure, just couldn't get around to doing it earlier.

Stan

On Tuesday, January 19, 2016, Кристина notifications@github.com wrote:

Can you help me figure out what went wrong?..


Reply to this email directly or view it on GitHub
#62 (comment).

@coralinejones1985
Copy link

This library is great and easy. So I'm looking forward to see solution :)

@coralinejones1985
Copy link

@svitvitskiy I'm sorry for bothering you, but I really need to know when you're planning to do this fix?

@svitvitskiy
Copy link
Collaborator

Hi,

Thank you so much for your patience.

I will be looking at the problem next week.

I'll let you know.

Stan

On Thu, Feb 25, 2016 at 9:28 PM, Кристина notifications@github.com wrote:

@svitvitskiy https://github.com/svitvitskiy I'm sorry for bothering
you, but I really need to know when you're planning to do this fix?


Reply to this email directly or view it on GitHub
#62 (comment).

@svitvitskiy
Copy link
Collaborator

Your video has only 3 frames, so at 25fps this really does seem like it shows the first frame and then the player just closes. I conclude that this is the intended behavior.

However I am guessing you might have a slideshow video in mind. In that case you would want your frames to stay on screen longer. If this is what you want, here's how you can make a slideshow video:

AndroidSequenceEncoder8Bit encoder = new AndroidSequenceEncoder8Bit(out, Rational.R(1, 4));
...

Here you are saying the duration of each frame will be 4 seconds or in other words fps would be 1/4 frames per second.

To use this you'd have to use the latest jcodec from HEAD.

@coralinejones1985
Copy link

Thank you, I'll try it and give you feedback :) I guess, I should fork your project?

@svitvitskiy
Copy link
Collaborator

Well, you just clone it and build locally since the version 0.2.0 has not
been released yet.

On Tue, Mar 8, 2016 at 5:47 AM, Кристина notifications@github.com wrote:

Thank you, I'll try it and give you feedback :) I guess, I should fork
your project?


Reply to this email directly or view it on GitHub
#62 (comment).

@coralinejones1985
Copy link

The same.. Maybe I do something wrong? I want one image to be shown per half a second, but there's only one image shows up and video closes.
SeekableByteChannel channel = NIOUtils.writableChannel(SDPathToFile("", APP_NAME + "." + FORMAT));
AndroidSequenceEncoder8Bit encoder8Bit = new AndroidSequenceEncoder8Bit(channel, Rational.R(1, 5));
for (int i = 0; i < imageUriList.size(); i++) {
String path = getPath(context, Uri.parse(imageUriList.get(i)));
encoder8Bit.encodeImage(BitmapFactory.decodeFile(path, null));
if (i == imageUriList.size() - 1) {
encoder8Bit.encodeImage(BitmapFactory.decodeFile(path, null));
}
Log.d(TAG, "Processed " + (i + 1) + " images");
}
encoder8Bit.finish();

@coralinejones1985
Copy link

I noticed that it works only on Murshmallow..that is wierd. I mean, video makes on every version, plays only on Murshmallow, but not on another versions.

@coralinejones1985
Copy link

Also videoPlays on 5.1.1 version, but not below..

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

3 participants