Base64解码Python和PHP之间的不完整文件

时间:2018-02-12 23:35:05

标签: php python laravel video base64

我在python上发送用base64编码的视频文件,但是当我重新播放视频并打开它时,只有该文件的图像。所以我的猜测可能是在PHP上没有正确解码。这是我用于解码和保存视频的PHP代码。

import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Java3D {

    private class MyDirectionalLight extends DirectionalLight {

        public MyDirectionalLight() {
            final Color3f color = new Color3f(1.8f, 0.8f, 0.1f);
            setColor(color);
            final Vector3f direction = new Vector3f(4.0f, -7.0f, -12.0f);
            setDirection(direction);
            setInfluencingBounds(new BoundingSphere(new Point3d(), 100.0));
        }

    }

    private class MySphere extends Sphere {
        public MySphere() {
            super(0.5f);
        }
    }

    public static void main(String[] args) {
        System.setProperty("sun.awt.noerasebackground", "true");
        new Java3D();
    }

    public Java3D() {
        final SimpleUniverse universe = new SimpleUniverse();
        final BranchGroup group = new BranchGroup();

        final MySphere mySphere = new MySphere();
        group.addChild(mySphere);

        final MyDirectionalLight myDirectionalLight = new MyDirectionalLight();
        group.addChild(myDirectionalLight);

        universe.getViewingPlatform().setNominalViewingTransform();
        universe.addBranchGraph(group);

    }

}

你可以看到我在laravel上工作。这是我编写和发送文件的python代码。

$video_encode_string = request('video');
        $video_decode = base64_decode($video_encode_string);
        $path = public_path().'/video/'.$device->id.'/';

        $date = new \DateTime('now');

        $file = fopen($path.date_format($date, 'Y-m-d H:i:s').'.mp4','wb');
        fwrite($file,$video_decode);
        fclose($file);

我正在使用Raspberry Pi并录制来自流媒体视频的视频然后发送它,当我使用omxplayer播放视频时,它可以完美地适用于任何类型的视频格式。我实际上想知道它是否必须以块的形式解码它

1 个答案:

答案 0 :(得分:0)

尝试使用:locale.setlocale(locale.LC_ALL, 'en_US')