2

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
  • *"I believe they are even using the same codecs, aac and h.264"* This is important info. Please verify the formats contained in the ts file. Will the other ts files have the same formats, or will they be arbitrary? Are you re-encoding or only re-muxing? – llogan Nov 04 '21 at 16:45
  • Yes, my desktop FFmpeg outputs `Stream #0:1[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720, 30 fps, 30 tbr, 90k tbn, 60 tbc` `Stream #0:2[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 140 kb/s`. All files will be exactly the same and I think I only need to do re-muxing since I do not need to change the codecs. – Aidan Dempster Nov 04 '21 at 17:06
  • Yes, the other ts files have the same formats (H.264 + AAC)? Or yes, they will be arbitrary/random/mixed? Are you re-encoding (`ffmpeg -i input.ts output.mp4`) or only re-muxing/[stream copying](https://ffmpeg.org/ffmpeg.html#Stream-copy) (`ffmpeg -i input.ts -c copy output.ts`)? – llogan Nov 04 '21 at 17:14
  • All of the inputs are exactly the same type of file and I am stream copying. – Aidan Dempster Nov 04 '21 at 17:15

2 Answers2

2

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.

  1. I had to manually enable a bitstream filter by adding --enable-bsf=aac_adtstoasc to the configure call.
  2. This also caused another issue that I still don't really understand. I also needed to manually set --enable-parser=h264 and --enable-parser=aac for the video to mux correctly (Source).
  3. And finally in order to concat the ts files I also needed to manually enable that protocol with --enable-protocol=concat.
1

This is very similar to How to compile ffmpeg to get only mp3 and mp4 support, but with a few different compilation options:

./configure --disable-everything --disable-network --disable-autodetect --enable-small --enable-demuxer=mpegts --enable-muxer=mp4 --enable-parser=aac,h264 --enable-decoder=aac,h264 --enable-protocol=file

The the link above for more details.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • That's more of a next step for me. This line of that answer `--enable-demuxer=mov,m4v,matroska` assumes I know which muxers are neccesary. – Aidan Dempster Nov 04 '21 at 18:00
  • Which I actually think I just figured out. I need the `mpegts` muxer. – Aidan Dempster Nov 04 '21 at 18:09
  • @AidanDempster Your question implied that you are only using your custom ffmpeg for .ts to .mp4 remuxing. In that case you don't need the mpegts muxer. You only need the mpegts demuxer and mp4 muxer. – llogan Nov 04 '21 at 20:02
  • Yes, you are correct about that. And I'm trying to reduce the size of the binary as much as possible so I will have to go and prune the muxers and codecs I am not using. – Aidan Dempster Nov 04 '21 at 20:50