On Fri, 12 Jun 2009 15:21:38 -0400, Stas Oskin <stas.os...@gmail.com> wrote:

Hi.

I have externally encoded MPEG4 data coming to me from a RTSP source. I'm
basically receiving just arrays of bytes per each frame + some info like
frame type and PTS.

I need to decode this to JPEG - any idea how I do it with FFMPEG?

Thanks in advance!


If you're using C++, you might find the following helpful. I wrote it so that I can just make subclasses of a CustomIOContext class, and then get a string from an instance of it to pass to av_open_input_file. (yess, I'm passing a pointer as a string of hex in the filename, hehe)

  class TCustomIOContext {
  protected:
    virtual int url_open(URLContext *h, int flags) { return -1; }
virtual int url_read(URLContext *h, unsigned char *buf, int size) { return -1; } virtual int url_write(URLContext *h, unsigned char *buf, int size) { return -1; } virtual int64_t url_seek(URLContext *h, int64_t pos, int whence) { return -1; }
    virtual int url_close(URLContext *h) { return -1; }
    virtual int url_read_pause(URLContext *h, int pause) { return -1; }
virtual int64_t url_read_seek(URLContext *h, int stream_index, int64_t timestamp, int flags) { return -1; }
    virtual int url_get_file_handle(URLContext *h) { return -1; }
    friend struct TCustIoCaller;
  public:
    TCustomIOContext() {}
    virtual ~TCustomIOContext() {}
    std::string getLibavUrl();
  };

  struct TCustIoCaller {
    static int open(URLContext *c, const char *filename, int flags);
    static int read(URLContext *c, unsigned char *buf, int size) {
      return ((TCustomIOContext*)c->priv_data)->url_read(c, buf, size);
    }
    static int write(URLContext *c, unsigned char *buf, int size) {
      return ((TCustomIOContext*)c->priv_data)->url_write(c, buf, size);
    }
    static int64_t seek(URLContext *c, int64_t pos, int whence) {
      return ((TCustomIOContext*)c->priv_data)->url_seek(c, pos, whence);
    }
    static int close(URLContext *c) {
      return ((TCustomIOContext*)c->priv_data)->url_close(c);
    }
    static int read_pause(URLContext *c, int pause) {
      return ((TCustomIOContext*)c->priv_data)->url_read_pause(c, pause);
    }
static int64_t read_seek(URLContext *c, int stream_index, int64_t timestamp, int flags) { return ((TCustomIOContext*)c->priv_data)->url_read_seek(c, stream_index, timestamp, flags);
    }
    static int get_file_handle(URLContext *c) {
      return ((TCustomIOContext*)c->priv_data)->url_get_file_handle(c);
    }
        
    static string genUrl(TCustomIOContext *cx) {
      return IUI::StrFormat("%s:%p", protocol.name, cx);
    }
        
    static URLProtocol protocol;
        
    TCustIoCaller() { av_register_protocol(&protocol); }
  } register_custio;

  URLProtocol TCustIoCaller::protocol = {
    "CustomIOContext",
    TCustIoCaller::open, TCustIoCaller::read, TCustIoCaller::write,
    TCustIoCaller::seek, TCustIoCaller::close,
    NULL,
TCustIoCaller::read_pause, TCustIoCaller::read_seek//, TCustIoCaller::get_file_handle
  };

  int TCustIoCaller::open(URLContext *c, const char *filename, int flags) {
    char* lastChar;
    int prefixLen= strlen(protocol.name);
    if (strncmp(protocol.name, filename, prefixLen) != 0) return -1;
    if (strncmp(":0x", filename+prefixLen, 3) != 0) return -1;
      uint64_t ptr_val= strtoll(filename + prefixLen+3, &lastChar, 16);
if ((lastChar == filename + prefixLen) || *lastChar != '\0' || !ptr_val)
        return -1;

    TCustomIOContext *ccx= (TCustomIOContext*) (void*) ptr_val;
    c->priv_data= ccx;

    return ccx->url_open(c, flags);
  }


--
Michael Conrad
IntelliTree Solutions llc.
513-552-6362
mcon...@intellitree.com
_______________________________________________
libav-user mailing list
libav-user@mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to