decode AVPacket into AVFrame #61

pull/63/head
nick black 5 years ago committed by Nick Black
parent cf557ff500
commit 9ed5a8b6c7

@ -428,10 +428,14 @@ ncplane_rounded_box_cells(struct ncplane* n, cell* ul, cell* ur, cell* ll,
}
// multimedia functionality
struct AVFrame;
API struct ncvisual* notcurses_visual_open(struct notcurses* nc,
const char* filename);
API void ncvisual_destroy(struct ncvisual* ncv);
API struct AVFrame* ncvisual_decode(struct ncvisual* nc);
#undef API
#ifdef __cplusplus

@ -31,10 +31,31 @@ void ncvisual_destroy(ncvisual* ncv){
}
}
AVFrame* ncvisual_decode(struct ncvisual* nc){
int ret = avcodec_send_packet(nc->codecctx, nc->packet);
if(ret < 0){
fprintf(stderr, "Error processing AVPacket (%s)\n", av_err2str(ret));
return NULL;
}
do{
ret = avcodec_receive_frame(nc->codecctx, nc->frame);
if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF){
// FIXME can we still use nc->frame?
return NULL;
}else if(ret < 0){
fprintf(stderr, "Error decoding AVPacket (%s)\n", av_err2str(ret));
return NULL;
}
fprintf(stderr, "Got frame %05d\n", nc->codecctx->frame_number);
}while(ret > 0);
return NULL; // FIXME
}
ncvisual* notcurses_visual_open(struct notcurses* nc __attribute__ ((unused)),
const char* filename){
ncvisual* ncv = ncvisual_create();
if(ncv == NULL){
fprintf(stderr, "Couldn't create %s (%s)\n", filename, strerror(errno));
return NULL;
}
int ret = avformat_open_input(&ncv->fmtctx, filename, NULL, NULL);

@ -1,18 +1,45 @@
#include <cstdlib>
#include <libgen.h>
#include <iostream>
#include "notcurses.h"
void usage(std::ostream& o, char* argv0, int exitcode){
o << "usage: " << basename(argv0) << " files" << '\n';
static void usage(std::ostream& os, const char* name, int exitcode)
__attribute__ ((noreturn));
void usage(std::ostream& o, const char* name, int exitcode){
o << "usage: " << name << " files" << '\n';
exit(exitcode);
}
int ncview(struct ncvisual* ncv, const notcurses_options* opts){
ncvisual_decode(ncv);
auto nc = notcurses_init(opts);
if(nc == nullptr){
return -1;
}
ncvisual_destroy(ncv);
return notcurses_stop(nc);
}
int main(int argc, char** argv){
if(argc == 1){
usage(std::cerr, argv[0], EXIT_FAILURE);
}
notcurses_options opts{};
opts.outfp = stdout;
bool success = true;
for(int i = 1 ; i < argc ; ++i){
std::cout << "file: " << argv[i] << std::endl;
auto ncv = notcurses_visual_open(nullptr, argv[i]);
if(ncv == nullptr){
success = false;
continue;
}
if(ncview(ncv, &opts)){
success = false;
}
}
if(!success){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

Loading…
Cancel
Save