0

I have raw h264 data of my frames and its presentationTimeUs and I want to mux data in mp4 container. How can I do it with ffmpeg or any library except MediaMuxer ?

Update: I need a command to write h264 data of just one frame to mp4 container including presentatoinTimeUs

Sajad Norouzi
  • 1,790
  • 2
  • 17
  • 26
  • Sounds like you're looking for examples of using the ffmpeg library to do .mp4 muxing? – fadden Mar 23 '16 at 16:34
  • You can try `ffmpeg -f h264 -i raw.264 out.mp4` – Gyan Mar 24 '16 at 04:24
  • I encoded byte[] to h264 with MediaCodec but I didn't want to use MediaMuxer for muxing data in mp4 container(because it's added from android 4.3). so when I write raw h264 to file it doesn't play well and playing too fast and this command: ffmpeg -f h264 -i raw.264 out.mp4 just put video in mp4 container and doesn't solve anything. I need a command of ffmpeg to write just one h264 frame in mp4 file including setting presentationTimeUs or any meta data that it needs. – Sajad Norouzi Mar 24 '16 at 07:22

1 Answers1

0

You can't write arbitrary H264 raw data without associated meta-information, either with ffmpeg or any library. Container such as MP4 exist so that a player knows how to handle that raw data (e.g each frame's PTS, codec configuration, movie size, color format, etc), and more things that are not included in the raw compressed video stream.

You can however do the reverse, if you need to later analyze a compressor's bitstream:

ffmpeg -i file.mp4 -f h264 out.h264

Adrian Crețu
  • 878
  • 8
  • 17
  • I encoded byte[] to h264 with MediaCodec but I didn't want to use MediaMuxer for muxing data in mp4 container(because it's added from android 4.3). so when I write raw h264 to file it doesn't play well and playing too fast and this command: ffmpeg -f h264 -i raw.264 out.mp4 just put video in mp4 container and doesn't solve anything. I need a command of ffmpeg to write just one h264 frame in mp4 file including setting presentationTimeUs or any meta data that it needs. – Sajad Norouzi Mar 24 '16 at 06:43
  • 1
    Try adding "-r 24" to force frame-rate. You cannot add a single ENCODED frame raw data to a container and specify also its timestamp using ffmpeg or any other tool. That level of detail is well below what ffmpeg can do (that is, transmuxing or re-encoding from one container/format to another). That frame might as well be a keyframe (or not), encoded with its own settings. Having a raw buffer says almost nothing about how it was encoded and if it can be put together in a container or not. That's why MediaMuxer needs a BufferInfo, and it keeps internally the track number, and so on. – Adrian Crețu Mar 24 '16 at 12:26
  • so I don't need ffmpeg but there should be some library handle this. – Sajad Norouzi Mar 24 '16 at 22:19
  • ffmpeg is built on top of libav, libavcodec, libavformat, and so on. Those are the libraries you're looking for. ffmpeg is just a compiled utility, not a library. You will need to go native to achieve what you want, or find a Java equivalent for these things, if you don't wanna go the trouble of making your own one (which I assure you is no easy cake if you want a fully compliant MP4 file in the end).. – Adrian Crețu Mar 25 '16 at 12:18