motherfucking video #94

pull/98/head
nick black 5 years ago committed by Nick Black
parent 19e1b3ac94
commit 56e637d006

@ -60,6 +60,7 @@ typedef struct ncvisual {
struct SwsContext* swsctx;
int packet_outstanding;
int dstwidth, dstheight;
int stream_index; // match against this following av_read_frame()
ncplane* ncp;
} ncvisual;

@ -68,14 +68,28 @@ print_frame_summary(const AVCodecContext* cctx, const AVFrame* f){
}
AVFrame* ncvisual_decode(struct ncvisual* nc, int* averr){
if(nc->packet_outstanding){
*averr = avcodec_send_packet(nc->codecctx, nc->packet);
if(*averr < 0){
fprintf(stderr, "Error processing AVPacket (%s)\n", av_err2str(*averr));
bool unref = false;
do{
if(nc->packet_outstanding){
break;
}
if(unref){
// fprintf(stderr, "stream index %d != %d\n", nc->packet->stream_index, nc->stream_index);
av_packet_unref(nc->packet);
}
if((*averr = av_read_frame(nc->fmtctx, nc->packet)) < 0){
fprintf(stderr, "Error reading frame info (%s)\n", av_err2str(*averr));
return NULL;
}
--nc->packet_outstanding;
unref = true;
}while(nc->packet->stream_index != nc->stream_index);
++nc->packet_outstanding;
*averr = avcodec_send_packet(nc->codecctx, nc->packet);
if(*averr < 0){
fprintf(stderr, "Error processing AVPacket (%s)\n", av_err2str(*averr));
return ncvisual_decode(nc, averr);
}
--nc->packet_outstanding;
*averr = avcodec_receive_frame(nc->codecctx, nc->frame);
if(*averr == AVERROR(EAGAIN) || *averr == AVERROR_EOF){
return NULL; // FIXME do something smarter
@ -118,6 +132,7 @@ print_frame_summary(nc->codecctx, nc->frame);
}
print_frame_summary(nc->codecctx, nc->oframe);
#undef IMGALLOCALIGN
av_frame_unref(nc->frame);
return nc->oframe;
}
@ -147,15 +162,11 @@ ncvisual* ncplane_visual_open(struct ncplane* nc, const char* filename, int* ave
*averr = AVERROR(ENOMEM);
goto err;
}
if((*averr = av_read_frame(ncv->fmtctx, ncv->packet)) < 0){
fprintf(stderr, "Error reading frame info from %s (%s)\n", filename,
av_err2str(*averr));
goto err;
}
if((*averr = av_find_best_stream(ncv->fmtctx, AVMEDIA_TYPE_VIDEO, -1, -1, &ncv->codec, 0)) < 0){
fprintf(stderr, "Couldn't find visuals in %s (%s)\n", filename, av_err2str(*averr));
goto err;
}
ncv->stream_index = *averr;
if(ncv->codec == NULL){
fprintf(stderr, "Couldn't find decoder for %s\n", filename);
goto err;
@ -178,12 +189,6 @@ ncvisual* ncplane_visual_open(struct ncplane* nc, const char* filename, int* ave
fprintf(stderr, "Couldn't get codec params for %s (%s)\n", filename, av_err2str(*averr));
goto err;
}
if((*averr = avcodec_send_packet(ncv->codecctx, ncv->packet)) < 0){
fprintf(stderr, "Error decoding packet from %s (%s)\n", filename,
av_err2str(*averr));
goto err;
}
++ncv->packet_outstanding;
if((ncv->frame = av_frame_alloc()) == NULL){
fprintf(stderr, "Couldn't allocate frame for %s\n", filename);
*averr = AVERROR(ENOMEM);

@ -28,7 +28,10 @@ int ncview(struct notcurses* nc, struct ncvisual* ncv, int* averr){
return -1;
}
++frame;
struct timespec ts = { .tv_sec = 1, .tv_nsec = 0 }; // FIXME
struct timespec ts = {
.tv_sec = avf->pkt_duration / 1000000,
.tv_nsec = avf->pkt_duration * 1000000,
};
nanosleep(&ts, NULL);
}
if(*averr == AVERROR_EOF){

Loading…
Cancel
Save