for(i=0; i<128; i++){
int stream_num= asf->asfid2avid[i];
if(stream_num>=0){
- AVCodecContext *codec= s->streams[stream_num]->codec;
- if (!codec->bit_rate)
- codec->bit_rate = bitrate[i];
+ AVStream *st = s->streams[stream_num];
+ if (!st->codec->bit_rate)
+ st->codec->bit_rate = bitrate[i];
if (dar[i].num > 0 && dar[i].den > 0)
- av_reduce(&codec->sample_aspect_ratio.num,
- &codec->sample_aspect_ratio.den,
+ av_reduce(&st->sample_aspect_ratio.num,
+ &st->sample_aspect_ratio.den,
dar[i].num, dar[i].den, INT_MAX);
-//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den);
+//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
}
}
get_le32(pb); //nbFieldsPerFrame
if(active_aspect.num && active_aspect.den && active.num && active.den){
- st->codec->sample_aspect_ratio= av_div_q(active_aspect, active);
+ st->sample_aspect_ratio= av_div_q(active_aspect, active);
//av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect.den, active.num, active.den);
}
size -= 9*4;
}
if( stream->codec_type == CODEC_TYPE_VIDEO
- && stream->sample_aspect_ratio.num>0
- && stream->sample_aspect_ratio.den>0){
+ && s->streams[i]->sample_aspect_ratio.num>0
+ && s->streams[i]->sample_aspect_ratio.den>0){
int vprp= start_tag(pb, "vprp");
- AVRational dar = av_mul_q(stream->sample_aspect_ratio,
+ AVRational dar = av_mul_q(s->streams[i]->sample_aspect_ratio,
(AVRational){stream->width, stream->height});
int num, den;
av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
video->codec->width = 320;
video->codec->height = 192;
/* 4:3 320x200 with 8 empty lines */
- video->codec->sample_aspect_ratio = (AVRational) { 5, 6 };
+ video->sample_aspect_ratio = (AVRational) { 5, 6 };
video->time_base = (AVRational) { 2, 25 };
video->nb_frames = framecount;
video->duration = framecount;
apt = frame[4] & 0x07;
is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
(!apt && (vsc_pack[2] & 0x07) == 0x07)));
- avctx->sample_aspect_ratio = c->sys->sar[is16_9];
+ c->vst->sample_aspect_ratio = c->sys->sar[is16_9];
avctx->bit_rate = av_rescale(c->sys->frame_size * 8,
c->sys->frame_rate,
c->sys->frame_rate_base);
st->codec->width = s[i].width;
st->codec->height = s[i].height;
- st->codec->sample_aspect_ratio.num = s[i].sample_width;
- st->codec->sample_aspect_ratio.den = s[i].sample_height;
+ st->sample_aspect_ratio.num = s[i].sample_width;
+ st->sample_aspect_ratio.den = s[i].sample_height;
break;
}
if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n");
st->codec->codec_tag = track->video.fourcc;
st->codec->width = track->video.pixel_width;
st->codec->height = track->video.pixel_height;
- av_reduce(&st->codec->sample_aspect_ratio.num,
- &st->codec->sample_aspect_ratio.den,
+ av_reduce(&st->sample_aspect_ratio.num,
+ &st->sample_aspect_ratio.den,
st->codec->height * track->video.display_width,
st->codec-> width * track->video.display_height,
255);
// XXX: interlace flag?
put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width);
put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height);
- if (codec->sample_aspect_ratio.num) {
- AVRational dar = av_mul_q(codec->sample_aspect_ratio,
- (AVRational){codec->width, codec->height});
- put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , dar.num);
- put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, dar.den);
+ if (st->sample_aspect_ratio.num) {
+ int d_width = codec->width*av_q2d(st->sample_aspect_ratio);
+ put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width);
+ put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height);
}
end_ebml_master(pb, subinfo);
break;
((int64_t) display_matrix[2][i] << 16);
//sample aspect ratio is new width/height divided by old width/height
- st->codec->sample_aspect_ratio = av_d2q(
+ st->sample_aspect_ratio = av_d2q(
((double) disp_transform[0] * height) /
((double) disp_transform[1] * width), INT_MAX);
}
return updateSize(pb, pos);
}
-static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track)
+static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
{
int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP);
int version = duration < INT32_MAX ? 0 : 1;
/* Track width and height, for visual only */
if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
- double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio);
+ double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio);
if(!sample_aspect_ratio) sample_aspect_ratio = 1;
put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000);
put_be32(pb, track->enc->height*0x10000);
return 0x34;
}
-static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track)
+static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st)
{
offset_t pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "trak");
- mov_write_tkhd_tag(pb, track);
+ mov_write_tkhd_tag(pb, track, st);
if (track->mode == MODE_PSP || track->hasBframes)
mov_write_edts_tag(pb, track); // PSP Movies require edts box
mov_write_mdia_tag(pb, track);
//mov_write_iods_tag(pb, mov);
for (i=0; i<mov->nb_streams; i++) {
if(mov->tracks[i].entry > 0) {
- mov_write_trak_tag(pb, &(mov->tracks[i]));
+ mov_write_trak_tag(pb, &(mov->tracks[i]), s->streams[i]);
}
}
put_be32(pb, st->codec->height);
mxf_write_local_tag(pb, 8, 0x320E);
- put_be32(pb, st->codec->height * st->codec->sample_aspect_ratio.den);
- put_be32(pb, st->codec->width * st->codec->sample_aspect_ratio.num);
+ put_be32(pb, st->codec->height * st->sample_aspect_ratio.den);
+ put_be32(pb, st->codec->width * st->sample_aspect_ratio.num);
// tmp write, will modified later
mxf_write_local_tag(pb, 16, 0x3201);
if (st->codec->codec_type == CODEC_TYPE_VIDEO){
GET_V(st->codec->width , tmp > 0)
GET_V(st->codec->height, tmp > 0)
- st->codec->sample_aspect_ratio.num= ff_get_v(bc);
- st->codec->sample_aspect_ratio.den= ff_get_v(bc);
- if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){
- av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->codec->sample_aspect_ratio.num, st->codec->sample_aspect_ratio.den);
+ st->sample_aspect_ratio.num= ff_get_v(bc);
+ st->sample_aspect_ratio.den= ff_get_v(bc);
+ if((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)){
+ av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
return -1;
}
ff_get_v(bc); /* csp type */
}
}
-static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext *codec, int i){
+static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, int i){
+ AVCodecContext *codec = st->codec;
put_v(bc, i);
switch(codec->codec_type){
case CODEC_TYPE_VIDEO: put_v(bc, 0); break;
put_v(bc, codec->width);
put_v(bc, codec->height);
- if(codec->sample_aspect_ratio.num<=0 || codec->sample_aspect_ratio.den<=0){
+ if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){
put_v(bc, 0);
put_v(bc, 0);
}else{
- put_v(bc, codec->sample_aspect_ratio.num);
- put_v(bc, codec->sample_aspect_ratio.den);
+ put_v(bc, st->sample_aspect_ratio.num);
+ put_v(bc, st->sample_aspect_ratio.den);
}
put_v(bc, 0); /* csp type -- unknown */
break;
put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE);
for (i=0; i < nut->avf->nb_streams; i++){
- AVCodecContext *codec = nut->avf->streams[i]->codec;
-
ret = url_open_dyn_buf(&dyn_bc);
if(ret < 0)
return ret;
- write_streamheader(nut, dyn_bc, codec, i);
+ write_streamheader(nut, dyn_bc, nut->avf->streams[i], i);
put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
}
vst->codec->width = width;
vst->codec->height = height;
vst->codec->bits_per_sample = 10;
- vst->codec->sample_aspect_ratio = av_d2q(aspect * height / width, 10000);
+ vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000);
vst->r_frame_rate = av_d2q(fps, 60000);
av_set_pts_info(vst, 32, 1, 1000);
} else
st->codec->time_base.num = get_bits_long(&gb, 32);
st->time_base = st->codec->time_base;
- st->codec->sample_aspect_ratio.num = get_bits_long(&gb, 24);
- st->codec->sample_aspect_ratio.den = get_bits_long(&gb, 24);
+ st->sample_aspect_ratio.num = get_bits_long(&gb, 24);
+ st->sample_aspect_ratio.den = get_bits_long(&gb, 24);
if (version >= 0x030200)
skip_bits(&gb, 38);
av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1);
- aspectn = st->codec->sample_aspect_ratio.num;
- aspectd = st->codec->sample_aspect_ratio.den;
+ aspectn = st->sample_aspect_ratio.num;
+ aspectd = st->sample_aspect_ratio.den;
if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown
st->codec->pix_fmt = pix_fmt;
st->codec->codec_type = CODEC_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_RAWVIDEO;
- st->codec->sample_aspect_ratio= (AVRational){aspectn, aspectd};
+ st->sample_aspect_ratio= (AVRational){aspectn, aspectd};
return 0;
}