Kagami / ffmpeg.js

Port of FFmpeg with Emscripten
Other
3.24k stars 329 forks source link

Building with support for ts files #168

Closed Veldrovive closed 2 years ago

Veldrovive commented 2 years ago

I am able to transcode mkv files to mp4, but I am not sure how to build with ts file support. For the sake of clarity, attempting to transcode a ts file results in sample.ts: Invalid data found when processing input.

Since the only thing I changed was the file type, I assume this is because default versions were not built with support for ts.

Based on a quick search, I believe ts files use MPEG2-TS for encoding, but I really don't understand enough about video types and how a codec relates to a file extension to be certain of that.

I am also not sure how to add support for that encoding type. Based on random guessing, I would assume that you would add MPEG2-TS to the line COMMON_DECODERS = vp8 h264 vorbis opus mp3 aac pcm_s16le mjpeg png in the make file, but I would like verification on that.

I would just verify it myself by building, but when I run the build script in the docker container, I get the error error waiting for container: invalid character 'u' looking for beginning of value. Since I exactly followed the steps outlined in the README and used a docker container, I am not sure what caused this. It also seems to crash the docker daemon as running docker ps after yields Error response from daemon: Bad response from Docker engine until I restart docker entirely.

Full output of build process here: https://pastebin.com/2syUH7ph

Veldrovive commented 2 years ago

The invalid character issue was with docker on mac, not with ffmpeg.js. I needed to give docker more memory to build.

I am still having issues with getting the built version to work with my ts files. I feel like I am shooting in the dark and I cannot find resources on building with support for certain file types. What I know is that my ts file is actually just a MPEG with a different file extension. My computer says that the codes are AAC, H.264. Based on this, it seems that the basic build should work since it already has decoder support for both of these.

I am not sure what I'm missing here.

Veldrovive commented 2 years ago

Update:

A comment on my stack overflow post let me solve this.

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.
haroonmoh commented 2 years ago

@Veldrovive Could you link your stack overflow post?

fyuhkust commented 1 year ago

Here is the link: https://stackoverflow.com/questions/69842795/ffmpeg-custom-build-support-for-converting-ts-to-mp4-files

Thanks you @Veldrovive for investigation! Greatly appreciated. Also Upvoted your stackoverflow question && answer.