#include <endian.h>
#include <limits.h>
#include <sys/stat.h>
+// work arounds (centos)
+#ifndef INT64_MAX
+#define INT64_MAX 9223372036854775807LL
+#endif
+#ifndef INT64_MIN
+#define INT64_MIN (-INT64_MAX-1)
+#endif
#include "arraylist.h"
#include "cstrdup.h"
int write();
mpls_pi() {}
- ~mpls_pi() {}
+ ~mpls_pi() {
+ clip.remove_all_objects();
+ }
};
class _mpls_plm {
strcpy(filename, fn);
brk = 0; pidx = 0; pgm_pid = -1; still = 0;
}
- ~media_info() { streams.remove_all_objects(); }
+ ~media_info() {
+ streams.remove_all_objects();
+ programs.remove_all_objects();
+ }
int scan();
int scan(AVFormatContext *fmt_ctx);
exit(1);
}
-static int bd_aspect_ratio(int w, double ratio)
+static int bd_aspect_ratio(int w, int h, double ratio)
{
- if( fabs(ratio-1.333) < 0.01 ) return BLURAY_ASPECT_RATIO_4_3;
- if( fabs(ratio-1.777) < 0.01 ) return BLURAY_ASPECT_RATIO_16_9;
+ double aspect = (w * ratio) / h;
+ if( fabs(aspect-1.333) < 0.01 ) return BLURAY_ASPECT_RATIO_4_3;
+ if( fabs(aspect-1.777) < 0.01 ) return BLURAY_ASPECT_RATIO_16_9;
return w == 720 ? BLURAY_ASPECT_RATIO_4_3 : BLURAY_ASPECT_RATIO_16_9;
- fprintf(stderr, "unknown bluray aspect ratio %5.3f\n",ratio);
+ fprintf(stderr, "unknown bluray aspect ratio %5.3f\n",aspect);
exit(1);
}
av_dict_set(&fopts, "threads", "auto", 0);
int ret = avformat_open_input(&fmt_ctx, filename, NULL, &fopts);
av_dict_free(&fopts);
+ if( ret < 0 ) return ret;
+ ret = avformat_find_stream_info(fmt_ctx, NULL);
- if( ret >= 0 )
- ret = avformat_find_stream_info(fmt_ctx, NULL);
-
- if( ret >= 0 ) {
- bit_rate = fmt_ctx->bit_rate;
- }
+ bit_rate = fmt_ctx->bit_rate;
int ep_pid = -1;
for( int i=0; ret>=0 && i<(int)fmt_ctx->nb_streams; ++i ) {
st->codec->flags & CODEC_FLAG_INTERLACED_ME);
s->rate = bd_video_rate(!st->codec->framerate.den ? 0 :
(double)st->codec->framerate.num / st->codec->framerate.den);
- s->aspect = bd_aspect_ratio(st->codec->width,!st->sample_aspect_ratio.den ? 0 :
- (double)st->sample_aspect_ratio.num / st->sample_aspect_ratio.den);
+ s->aspect = bd_aspect_ratio(st->codec->width, st->codec->height,
+ !st->sample_aspect_ratio.num || !st->sample_aspect_ratio.den ? 1. :
+ (double)st->sample_aspect_ratio.num / st->sample_aspect_ratio.den);
break; }
case AVMEDIA_TYPE_AUDIO: {
s->coding_type = bd_stream_type(codec_id);
pgm->ep_pid = ep_pid;
pgm->pmt_pid = 0x1000;
pgm->pcr_pid = 0x100;
- for( int jj=0; jj<streams.size(); ++jj )
+ pgm->duration = 0;
+ for( int jj=0; jj<streams.size(); ++jj ) {
+ AVStream *st = fmt_ctx->streams[jj];
+ AVMediaType type = st->codec->codec_type;
+ switch( type ) {
+ case AVMEDIA_TYPE_VIDEO:
+ case AVMEDIA_TYPE_AUDIO:
+ break;
+ default:
+ continue;
+ }
pgm->strm_idx.append(jj);
+ if( pgm->duration < st->duration )
+ pgm->duration = av_rescale_q(st->duration, st->time_base, clk45k);
+ }
+ programs.append(pgm);
}
for( int ii=0; ii<npgm; ++ii ) {
if( ret >= 0 )
ret = scan(fmt_ctx);
- if( fmt_ctx )
- avformat_close_input(&fmt_ctx);
+ for( int i=0; i<(int)fmt_ctx->nb_streams; ++i )
+ avcodec_close(fmt_ctx->streams[i]->codec);
+ avformat_close_input(&fmt_ctx);
return ret;
}