diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 18e768b386..359936744d 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include #include @@ -95,7 +97,7 @@ void exit_program(int ret) if (program_exit) program_exit(ret); - exit(ret); + emscripten_force_exit(ret); } double parse_number_or_die(const char *context, const char *numstr, int type, diff --git a/lib.js b/lib.js new file mode 100644 index 0000000000..b7f8092dbf --- /dev/null +++ b/lib.js @@ -0,0 +1,8 @@ +mergeInto(LibraryManager.library, { + // Returns 0 if the processing is canceled. + wait_readable: function() { + return Asyncify.handleSleep(function(wakeUp) { + Module["waitReadable"](wakeUp); + }); + } +}); \ No newline at end of file diff --git a/libavformat/file.c b/libavformat/file.c index 98c9e81bcb..a7ec30252d 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "config_components.h" #include "libavutil/avstring.h" @@ -108,11 +110,17 @@ static const AVClass pipe_class = { .version = LIBAVUTIL_VERSION_INT, }; +extern int wait_readable(void); + static int file_read(URLContext *h, unsigned char *buf, int size) { FileContext *c = h->priv_data; int ret; size = FFMIN(size, c->blocksize); + if (wait_readable() == 0) { + // Quit ffmpeg if the processing is canceled. + emscripten_force_exit(0); + } ret = read(c->fd, buf, size); if (ret == 0 && c->follow) return AVERROR(EAGAIN); @@ -395,6 +403,10 @@ static int pipe_open(URLContext *h, const char *filename, int flags) #endif c->fd = fd; h->is_streamed = 1; + + // increase the packet size since file operations in WASM is emulated in + // JavaScript, and the context switching is expensive. + h->max_packet_size = 256 << 10; return 0; } diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 17649bc077..38b5d80f90 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -86,6 +86,8 @@ int ff_raw_video_read_header(AVFormatContext *s) st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; st->codecpar->codec_id = s->iformat->raw_codec_id; + st->codecpar->width = s1->width; + st->codecpar->height = s1->height; sti->need_parsing = AVSTREAM_PARSE_FULL_RAW; sti->avctx->framerate = s1->framerate; @@ -124,6 +126,7 @@ static int raw_data_read_header(AVFormatContext *s) static const AVOption rawvideo_options[] = { { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC}, { "raw_packet_size", "", OFFSET(raw_packet_size), AV_OPT_TYPE_INT, {.i64 = RAW_PACKET_SIZE }, 1, INT_MAX, DEC}, + { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, { NULL }, }; #undef OFFSET diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index f843fe5a2e..152663145e 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -31,6 +31,7 @@ typedef struct FFRawVideoDemuxerContext { char *video_size; /**< String describing video size, set by a private option. */ char *pixel_format; /**< Set by a private option. */ AVRational framerate; /**< AVRational describing framerate, set by a private option. */ + int width, height; /**< Integers describing video size, set by a private option. */ } FFRawVideoDemuxerContext; typedef struct FFRawDemuxerContext {