How can play streaming Video from frame byte array

狂风中的少年 提交于 2020-02-06 07:50:29

问题


Thanks for watching of question and sorry about my english XD

(use Android Studio with JAVA) How can i play streaming video from byte array to VideoView or MediaPlayer, i have received byte array from ZeroMQ socket, and byte array content is Frame(size w: 640 h: 360 base64 encoding)

ZeroMQ protocol thread code

public class ZeromQMessageTask extends AsyncTask<String, Void, String>{
        @Override
        protected String doInBackground(String... strings) {
            DataOutputStream dataOutputStream = null;
            try{
                ZMQ.Context context = ZMQ.context(1);
                ZMQ.Socket socket = context.socket(ZMQ.SUB);
                socket.subscribe(ZMQ.SUBSCRIPTION_ALL);
                socket.connect("tcp://192.168.0.21:8080");
                socket.setReceiveTimeOut(5000);


                int count = 0;
                while (count < 10000){
                    byte[] datas = socket.recv(0);
                    count ++;
                }
                Log.e("socket closed: " , ""+count);

                socket.close();
                context.term();

            }catch (Exception e){
                Log.e("socket error: " , e.getLocalizedMessage());
                Log.e("socket error: " , e.toString());
            }
            return "test";
        }
    }

Server code (for refer) ps.maybe python code?

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.bind('tcp://*:{}'.format(PORT))

while True:
  try:
       for frame in frames:
           encoded, buffer = cv2.imencode('.jpg', frame)
           jpg_astext = base64.b64encode(buffer)
           footage_socket.send(jpg_as_text)

  except Exception as e: ...

来源:https://stackoverflow.com/questions/59710384/how-can-play-streaming-video-from-frame-byte-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!