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

安卓手机拍摄的MP4后缀视频,转码后方向发生变化 #20

Open
tomato-cc opened this issue Apr 1, 2020 · 0 comments
Open

Comments

@tomato-cc
Copy link

    我们的需求是对手机拍摄后的视频进行转码压缩,测试的时候发现,安卓手机拍摄的视频,在转码后会发生旋转(顺时针旋转90度),请问有什么解决方案吗

// 压缩前文件路径
    File source = new File("D:/video/000.mp4");
     // 压缩后的文件路径
    File target = new File("D:/video/test000.mp4");

    try {
        long start = System.currentTimeMillis();
        System.out.println("begin");

        // 音频编码属性配置
        AudioAttributes audio= new AudioAttributes();
        audio.setCodec("libmp3lame");
        // 比特率越高,清晰度/音质越好
        audio.setBitRate(new Integer(56000));//设置音频比特率,单位:b (比特率越高,清晰度/音质越好,当然文件也就越大 56000 = 56kb)
        audio.setChannels(new Integer(1));// 设置重新编码的音频流中使用的声道数(1 =单声道,2 = 双声道(立体声))。如果未设置任何声道值,则编码器将选择默认值 0。
        // 采样率越高声音的还原度越好,文件越大
        audio.setSamplingRate(new Integer(44100));//设置音频采样率,单位:赫兹 hz
        // 设置编码时候的音量值,未设置为0,如果256,则音量值不会改变
       //  audio.setVolume();

        // 视频编码属性配置
        VideoAttributes video=new VideoAttributes();
        video.setCodec("mpeg4");
        // 比特率越高,清晰度/音质越好
       video.setBitRate(new Integer(56000));//设置音频比特率,单位:b (比特率越高,清晰度/音质越好,当然文件也就越大 5600000 = 5600kb)
       // 视频帧率:15 f / s  帧率越低,效果越差
        video.setFrameRate(new Integer(15));// 设置视频帧率(帧率越低,视频会出现断层,越高让人感觉越连续),视频帧率(Frame rate)是用于测量显示帧数的量度。所谓的测量单位为每秒显示帧数(Frames per Second,简:FPS)或“赫兹”(Hz)。

        // 编码设置
        EncodingAttributes attr=new EncodingAttributes();
        attr.setFormat("mp4");
        attr.setAudioAttributes(audio);
        attr.setVideoAttributes(video);

        // 设置值编码
        Encoder encoder = new Encoder();
        encoder.encode(source, target, attr);


        System.out.println("end");
        long end = System.currentTimeMillis();

        System.out.println("压缩前大小: "+source.length() + " 压缩后大小:" + target.length());
        System.out.println("压缩耗时: " + (end -start));
    } catch (Exception e) {
        e.printStackTrace();
    }
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

1 participant