.{Y,U,V} image2 support
Originally committed as revision 3802 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
1b2dcdc1e0
commit
55cf195952
4
ffmpeg.c
4
ffmpeg.c
@ -83,8 +83,8 @@ static int nb_meta_data_maps;
|
|||||||
static AVInputFormat *file_iformat;
|
static AVInputFormat *file_iformat;
|
||||||
static AVOutputFormat *file_oformat;
|
static AVOutputFormat *file_oformat;
|
||||||
static AVImageFormat *image_format;
|
static AVImageFormat *image_format;
|
||||||
static int frame_width = 160;
|
static int frame_width = 0;
|
||||||
static int frame_height = 128;
|
static int frame_height = 0;
|
||||||
static float frame_aspect_ratio = 0;
|
static float frame_aspect_ratio = 0;
|
||||||
static enum PixelFormat frame_pix_fmt = PIX_FMT_YUV420P;
|
static enum PixelFormat frame_pix_fmt = PIX_FMT_YUV420P;
|
||||||
static int frame_padtop = 0;
|
static int frame_padtop = 0;
|
||||||
|
@ -50,9 +50,35 @@ static const IdStrMap img_tags[] = {
|
|||||||
{ CODEC_ID_MPEG2VIDEO, "mpg2-img"},
|
{ CODEC_ID_MPEG2VIDEO, "mpg2-img"},
|
||||||
{ CODEC_ID_MPEG4 , "mpg4-img"},
|
{ CODEC_ID_MPEG4 , "mpg4-img"},
|
||||||
{ CODEC_ID_FFV1 , "ffv1-img"},
|
{ CODEC_ID_FFV1 , "ffv1-img"},
|
||||||
|
{ CODEC_ID_RAWVIDEO , "y"},
|
||||||
{0, NULL}
|
{0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int sizes[][2] = {
|
||||||
|
{ 640, 480 },
|
||||||
|
{ 720, 480 },
|
||||||
|
{ 720, 576 },
|
||||||
|
{ 352, 288 },
|
||||||
|
{ 352, 240 },
|
||||||
|
{ 160, 128 },
|
||||||
|
{ 512, 384 },
|
||||||
|
{ 640, 352 },
|
||||||
|
{ 640, 240 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static int infer_size(int *width_ptr, int *height_ptr, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
|
||||||
|
if ((sizes[i][0] * sizes[i][1]) == size) {
|
||||||
|
*width_ptr = sizes[i][0];
|
||||||
|
*height_ptr = sizes[i][1];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
|
static enum CodecID av_str2id(const IdStrMap *tags, const char *str)
|
||||||
{
|
{
|
||||||
str= strrchr(str, '.');
|
str= strrchr(str, '.');
|
||||||
@ -178,6 +204,11 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
|
|||||||
st->codec.frame_rate_base = ap->frame_rate_base;
|
st->codec.frame_rate_base = ap->frame_rate_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ap && ap->width && ap->height){
|
||||||
|
st->codec.width = ap->width;
|
||||||
|
st->codec.height= ap->height;
|
||||||
|
}
|
||||||
|
|
||||||
if (!s->is_pipe) {
|
if (!s->is_pipe) {
|
||||||
if (find_image_range(&first_index, &last_index, s->path) < 0)
|
if (find_image_range(&first_index, &last_index, s->path) < 0)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
@ -209,8 +240,10 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
{
|
{
|
||||||
VideoData *s = s1->priv_data;
|
VideoData *s = s1->priv_data;
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
int ret;
|
int i;
|
||||||
ByteIOContext f1, *f;
|
int size[3]={0}, ret[3]={0};
|
||||||
|
ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]};
|
||||||
|
AVCodecContext *codec= &s1->streams[0]->codec;
|
||||||
|
|
||||||
if (!s->is_pipe) {
|
if (!s->is_pipe) {
|
||||||
/* loop over input */
|
/* loop over input */
|
||||||
@ -220,33 +253,44 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||||||
if (get_frame_filename(filename, sizeof(filename),
|
if (get_frame_filename(filename, sizeof(filename),
|
||||||
s->path, s->img_number)<0 && s->img_number > 1)
|
s->path, s->img_number)<0 && s->img_number > 1)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
f = &f1;
|
for(i=0; i<3; i++){
|
||||||
if (url_fopen(f, filename, URL_RDONLY) < 0)
|
if (url_fopen(f[i], filename, URL_RDONLY) < 0)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
|
size[i]= url_filesize(url_fileno(f[i]));
|
||||||
|
|
||||||
|
if(codec->codec_id != CODEC_ID_RAWVIDEO)
|
||||||
|
break;
|
||||||
|
filename[ strlen(filename) - 1 ]= 'U' + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
|
||||||
|
infer_size(&codec->width, &codec->height, size[0]);
|
||||||
} else {
|
} else {
|
||||||
f = &s1->pb;
|
f[0] = &s1->pb;
|
||||||
if (url_feof(f))
|
if (url_feof(f[0]))
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
|
size[0]= 4096;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->is_pipe) {
|
av_new_packet(pkt, size[0] + size[1] + size[2]);
|
||||||
av_new_packet(pkt, 4096);
|
|
||||||
}else{
|
|
||||||
av_new_packet(pkt, url_filesize(url_fileno(f)));
|
|
||||||
}
|
|
||||||
pkt->stream_index = 0;
|
pkt->stream_index = 0;
|
||||||
pkt->flags |= PKT_FLAG_KEY;
|
pkt->flags |= PKT_FLAG_KEY;
|
||||||
|
|
||||||
ret = get_buffer(f, pkt->data, pkt->size);
|
pkt->size= 0;
|
||||||
if (!s->is_pipe) {
|
for(i=0; i<3; i++){
|
||||||
url_fclose(f);
|
if(size[i]){
|
||||||
|
ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);
|
||||||
|
if (!s->is_pipe)
|
||||||
|
url_fclose(f[i]);
|
||||||
|
if(ret[i]>0)
|
||||||
|
pkt->size += ret[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret <= 0) {
|
if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
|
||||||
av_free_packet(pkt);
|
av_free_packet(pkt);
|
||||||
return AVERROR_IO; /* signal EOF */
|
return AVERROR_IO; /* signal EOF */
|
||||||
} else {
|
} else {
|
||||||
pkt->size = ret;
|
|
||||||
s->img_count++;
|
s->img_count++;
|
||||||
s->img_number++;
|
s->img_number++;
|
||||||
return 0;
|
return 0;
|
||||||
@ -280,24 +324,42 @@ static int img_write_header(AVFormatContext *s)
|
|||||||
static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
|
static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
VideoData *img = s->priv_data;
|
VideoData *img = s->priv_data;
|
||||||
ByteIOContext pb1, *pb;
|
ByteIOContext pb1[3], *pb[3]= {&pb1[0], &pb1[1], &pb1[2]};
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
|
AVCodecContext *codec= &s->streams[ pkt->stream_index ]->codec;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!img->is_pipe) {
|
if (!img->is_pipe) {
|
||||||
if (get_frame_filename(filename, sizeof(filename),
|
if (get_frame_filename(filename, sizeof(filename),
|
||||||
img->path, img->img_number) < 0 && img->img_number>1)
|
img->path, img->img_number) < 0 && img->img_number>1)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
pb = &pb1;
|
for(i=0; i<3; i++){
|
||||||
if (url_fopen(pb, filename, URL_WRONLY) < 0)
|
if (url_fopen(pb[i], filename, URL_WRONLY) < 0)
|
||||||
return AVERROR_IO;
|
return AVERROR_IO;
|
||||||
|
|
||||||
|
if(codec->codec_id != CODEC_ID_RAWVIDEO)
|
||||||
|
break;
|
||||||
|
filename[ strlen(filename) - 1 ]= 'U' + i;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pb = &s->pb;
|
pb[0] = &s->pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
put_buffer(pb, pkt->data, pkt->size);
|
if(codec->codec_id == CODEC_ID_RAWVIDEO){
|
||||||
put_flush_packet(pb);
|
int size = (codec->width * codec->height)>>2;
|
||||||
|
put_buffer(pb[0], pkt->data , 4*size);
|
||||||
|
put_buffer(pb[1], pkt->data + 4*size, size);
|
||||||
|
put_buffer(pb[2], pkt->data + 5*size, size);
|
||||||
|
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) {
|
if (!img->is_pipe) {
|
||||||
url_fclose(pb);
|
url_fclose(pb[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
img->img_number++;
|
img->img_number++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user