#include "fileffmpeg.h"
#include "file.h"
#include "ffmpeg.h"
+#include "libdv.h"
+#include "libmjpeg.h"
#include "mainerror.h"
#include "mwindow.h"
#include "vframe.h"
return max_err < 0.0001 ? best_rate : (AVRational) { 0, 0 };
}
-AVRational FFMPEG::to_sample_aspect_ratio(double aspect_ratio)
+AVRational FFMPEG::to_sample_aspect_ratio(Asset *asset)
{
#if 1
- int height = 1000000, width = height * aspect_ratio;
+ double display_aspect = asset->width / (double)asset->height;
+ double sample_aspect = asset->aspect_ratio / display_aspect;
+ int width = 1000000, height = width * sample_aspect + 0.5;
float w, h;
MWindow::create_aspect_ratio(w, h, width, height);
- return (AVRational){(int)w, (int)h};
+ return (AVRational){(int)h, (int)w};
#else
// square pixels
return (AVRational){1, 1};
AVStream *st = fmt_ctx->streams[i];
if( st->duration == AV_NOPTS_VALUE ) bad_time = 1;
AVCodecContext *avctx = st->codec;
+ const AVCodecDescriptor *codec_desc = avcodec_descriptor_get(avctx->codec_id);
+ if( !codec_desc ) continue;
if( avctx->codec_type == AVMEDIA_TYPE_VIDEO ) {
+ if( avctx->width < 1 ) continue;
+ if( avctx->height < 1 ) continue;
+ AVRational framerate = av_guess_frame_rate(fmt_ctx, st, 0);
+ if( framerate.num < 1 ) continue;
has_video = 1;
FFVideoStream *vid = new FFVideoStream(this, st, i);
int vidx = ffvideo.size();
ffvideo.append(vid);
vid->width = avctx->width;
vid->height = avctx->height;
- AVRational framerate = av_guess_frame_rate(fmt_ctx, st, 0);
vid->frame_rate = !framerate.den ? 0 : (double)framerate.num / framerate.den;
double secs = to_secs(st->duration, st->time_base);
vid->length = secs * vid->frame_rate;
vid->create_filter(opt_video_filter, avctx,avctx);
}
else if( avctx->codec_type == AVMEDIA_TYPE_AUDIO ) {
+ if( avctx->channels < 1 ) continue;
+ if( avctx->sample_rate < 1 ) continue;
has_audio = 1;
FFAudioStream *aud = new FFAudioStream(this, st, i);
int aidx = ffaudio.size();
return 1;
}
+ if( !strcmp(codec_name, CODEC_TAG_DVSD) ) strcpy(codec_name, "dv");
+ else if( !strcmp(codec_name, CODEC_TAG_MJPEG) ) strcpy(codec_name, "mjpeg");
+ else if( !strcmp(codec_name, CODEC_TAG_JPEG) ) strcpy(codec_name, "jpeg");
+
int ret = 0;
ff_lock("FFMPEG::open_encoder");
FFStream *fst = 0;
vid->height = asset->height;
ctx->height = (vid->height+3) & ~3;
vid->frame_rate = asset->frame_rate;
- ctx->sample_aspect_ratio = to_sample_aspect_ratio(asset->aspect_ratio);
+ ctx->sample_aspect_ratio = to_sample_aspect_ratio(asset);
ctx->pix_fmt = codec->pix_fmts ? codec->pix_fmts[0] : AV_PIX_FMT_YUV420P;
AVRational frame_rate = check_frame_rate(codec, vid->frame_rate);
if( !frame_rate.num || !frame_rate.den ) {
}
}
if( !ret ) {
+ if( fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER )
+ st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
ret = avcodec_open2(st->codec, codec, &sopts);
if( ret < 0 ) {
ff_err(ret,"FFMPEG::open_encoder");
ret = 0;
}
if( !ret ) {
- if( fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER )
- st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
if( fst && bsfilter[0] )
fst->add_bsfilter(bsfilter, !bsargs[0] ? 0 : bsargs);
}