ffmpeg.js uses a custom build of FFmpeg to keep its size low. I am trying to convert a .ts
into a .mp4
which has always been an easy task on my desktop (especially since they are even using the same codecs, aac and h.264), but on the custom build, I get the error sample1.ts: Invalid data found when processing input
.
The command being run is ffmpeg -i sample1.ts -report -c copy out.mp4
.
Other questions I see on this topic get past the initial reading of the input file and I cannot find good resources on what my problem is or how to fix it.
This is a rather nondescript error so I am not sure exactly what the problem is. I assume it means that this build does not have support for ts
files, but I am not even sure what that means in terms of codecs and muxers.
From the custom build make file, the enabled demuxers and decoders are
COMMON_DEMUXERS = matroska ogg mov mp3 wav image2 concat
COMMON_DECODERS = vp8 h264 vorbis opus mp3 aac pcm_s16le mjpeg png
These are used for the --enable-demuxer
and --enable-decoder
flags.
I see both h264 and aac in the decoders so I don't see why there would be a codec problem.
It does work with some file types so it is not the build itself that is the problem.
I have tried adding demuxers and decoders like mpeg2
, but that just earned me a WARNING: Option --enable-decoder=mpeg2 did not match anything
.
The full output when I use the -report
flag is
./this.program -i sample1.ts -report -c copy out.mp4
ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with emcc (Emscripten gcc/clang-like replacement) 1.39.11
configuration: --cc=emcc --ranlib=emranlib --enable-cross-compile --target-os=none --arch=x86 --disable-runtime-cpudetect --disable-asm --disable-fast-unaligned --disable-pthreads --disable-w32threads --disable-os2threads --disable-debug --disable-stripping --disable-safe-bitstream-reader --disable-all --enable-ffmpeg --enable-avcodec --enable-avformat --enable-avfilter --enable-swresample --enable-swscale --disable-network --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vdpau --enable-decoder=vp8 --enable-decoder=h264 --enable-decoder=vorbis --enable-decoder=opus --enable-decoder=mp3 --enable-decoder=aac --enable-decoder=pcm_s16le --enable-decoder=mjpeg --enable-decoder=png --enable-demuxer=matroska --enable-demuxer=ogg --enable-demuxer=mov --enable-demuxer=mp3 --enable-demuxer=wav --enable-demuxer=image2 --enable-demuxer=concat --enable-protocol=file --enable-filter=aresample --enable-filter=scale --enable-filter=crop --enable-filter=overlay --enable-filter=hstack --enable-filter=vstack --dis libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'sample1.ts'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option 'out.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url sample1.ts.
Successfully parsed a group of options.
Opening an input file: sample1.ts.
[NULL @ 0x72c300] Opening 'sample1.ts' for reading
[file @ 0x72c9f0] Setting default whitelist 'file,crypto'
[AVIOContext @ 0x734ab0] Statistics: 448192 bytes read, 0 seeks
sample1.ts: Invalid data found when processing input
Update:
I figured this out after a hint from logan
Are you re-encoding (ffmpeg -i input.ts output.mp4) or only re-muxing/stream copying (ffmpeg -i input.ts -c copy output.ts)?
This meant the problem was with the muxer. Specifically, I had put mpegts
under the decoders section as I misunderstood the difference. Moving it to the demuxer section fixed that issue.
There was a second problem as well. FFmpeg.js
builds with the --disable-all
option which means that it also disables a lot of other stuff.
--enable-bsf=aac_adtstoasc
to the configure call.--enable-parser=h264
and --enable-parser=aac
for the video to mux correctly (Source).--enable-protocol=concat
.