6

I'm looking for a way to mux mjpeg (compressed) video data into a video container like mp4 or avi. (I'll also need to add audio in the future). Since i use FFMPEG in other parts of my project as well i'd like to do it using those libraries if possible. I'm not looking for command line FFMPEG use! I've tried to use the muxing example in ffmpeg with that i can only create a (very large) .mjpeg file with video information. This is not what I am looking for.

Examples would be very welcome, but a pointer in the right direction also works!

edit: I have output the yuvj422p stream to jpeg images and I want to put this into a mp4 container. Using ffmpeg commandline this works:

ffmpeg -i yuvy%01d.jpg -vcodec mjpeg out.mp4 

I would like to do this directely in my code (without creating jpeg images first ofcourse)

malat
  • 12,152
  • 13
  • 89
  • 158
p.streef
  • 3,652
  • 3
  • 26
  • 50

2 Answers2

4

I fixed it doing the following:

I used the muxing example and in stead of using the encode functions i just skipped it and directly loaded the JPEG data into the packet. To set up the OutputContext i used guess format functions and i set the codec to MJPEG. I changed the PTS data to a frame counter. since all frames are chronologic anyway.

p.streef
  • 3,652
  • 3
  • 26
  • 50
-2

three major steps

  1. decode ( using avcodec_decode_video() )
  2. convert raw frame to yuv420p format ( using swscale() )
  3. encode ( using avcodec_encode_video() )

I can provide a sample code if you need

arash kordi
  • 2,470
  • 1
  • 22
  • 24
  • The poster should have already done all this. Having JPEG on hands now he wants to write frames into video file. – Roman R. Oct 09 '12 at 12:00
  • ok then only step 2 and 3, since jpeg frames are in yuvj422p if I remember correctly – arash kordi Oct 09 '12 at 12:14
  • I am running the encoding on an embedded platform and am getting a raw yuvj422p encoded bitstream. I want to directly put this into an mp4 container. Decoding and encoding would take too much cycletime. – p.streef Oct 09 '12 at 12:15
  • 1
    @arash kordi: No, he needs step 4 which is to come next – Roman R. Oct 09 '12 at 12:22
  • Let me clear this, did you created an .mjpeg file from raw yuvj422p bitstream or from jpeg images? – arash kordi Oct 09 '12 at 12:37
  • I have output the yuvj422p stream to jpeg images and I want to put this into a mp4 container. Using ffmpeg commandline this works: ffmpeg -i yuvy%01d.jpg -vcodec mjpeg out.mp4 I would like to do this directely in my code (without creating jpeg images first ofcourse) – p.streef Oct 09 '12 at 12:50