static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
{
    VideoData *img = s->priv_data;
    ByteIOContext *pb[3];
    char filename[1024];
    AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec;
    int i;
    if (!img->is_pipe) {
        if (av_get_frame_filename(filename, sizeof(filename),
                                  img->path, img->img_number) < 0 && img->img_number>1)
            return AVERROR(EIO);
        for(i=0; i<3; i++){
            if (url_fopen(&pb[i], filename, URL_WRONLY) < 0)
                return AVERROR(EIO);
            if(codec->codec_id != CODEC_ID_RAWVIDEO)
                break;
            filename[ strlen(filename) - 1 ]= 'U' + i;
        }
    } else {
        pb[0] = s->pb;
    }
    if(codec->codec_id == CODEC_ID_RAWVIDEO){
        int ysize = codec->width * codec->height;
        put_buffer(pb[0], pkt->data        , ysize);
        put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
        put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);
        put_flush_packet(pb[1]);
        put_flush_packet(pb[2]);
        url_fclose(pb[1]);
        url_fclose(pb[2]);
    }else{
        put_buffer(pb[0], pkt->data, pkt->size);
    }
    put_flush_packet(pb[0]);
    if (!img->is_pipe) {
        url_fclose(pb[0]);
    }
    img->img_number++;
    return 0;
}
["static int img_write_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    VideoData *img = s->priv_data;\n    ByteIOContext *pb[3];\n    char filename[1024];\n    AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec;\n    int i;\n    if (!img->is_pipe) {\n        if (av_get_frame_filename(filename, sizeof(filename),\n                                  img->path, img->img_number) < 0 && img->img_number>1)\n            return AVERROR(EIO);\n        for(i=0; i<3; i++){\n            if (url_fopen(&pb[i], filename, URL_WRONLY) < 0)\n                return AVERROR(EIO);\n            if(codec->codec_id != CODEC_ID_RAWVIDEO)\n                break;\n            filename[ strlen(filename) - 1 ]= 'U' + i;\n        }\n    } else {\n        pb[0] = s->pb;\n    }\n    if(codec->codec_id == CODEC_ID_RAWVIDEO){\n        int ysize = codec->width * codec->height;\n        put_buffer(pb[0], pkt->data        , ysize);\n        put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);\n        put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);\n        put_flush_packet(pb[1]);\n        put_flush_packet(pb[2]);\n        url_fclose(pb[1]);\n        url_fclose(pb[2]);\n    }else{\n        put_buffer(pb[0], pkt->data, pkt->size);\n    }\n    put_flush_packet(pb[0]);\n    if (!img->is_pipe) {\n        url_fclose(pb[0]);\n    }\n    img->img_number++;\n    return 0;\n}"]