13

What i want is

 1. Get video packet from stream source
 2. Decode it
 3. And write  that decoded data as video file(avi, mpeg etc)

I can able to get video Packets from a file (as AVPacket) and also can decode and save as an image.(raw)( FFmpeg tutorials show how to do it). But i can not ( do not know ) write that video data to a file(other) which can be played by media players(such as VLC).

Best Wishes

Ps: Real code samples will be great if possible...

Now i make test with av_interleaved_write but i got strange error "non monotone timestamps" ( i have no control over pts values of media source )

Some Extra Info

In FFmpeg I have to

  1. Read media packets from media source ( it may be real file(.avi,mov) or even rtsp server).
  2. Then write those media packets to a real file (physical .avi, .mov etc file)

I need reader and writer. I can read the media source file ( even encode packets according to given format). But i can not write to file...(which any player can play)

And some pseudoCode

File myFile("MyTestFile.avi");

while ( source ->hasVideoPackets)
{
     packet = source->GetNextVideoPacket();
     Frame decodedFrame = Decode(packet);
     VideoPacket encodedPacket = Encode( decodedFrame);
     myFile.WriteFile(encodedPacket);
 }

Or Just write the original file without encode decode

     File myFile("MyTestFile.avi");

     while ( source ->hasVideoPackets)
     {
         packet = source->GetNextVideoPacket();
         myFile.WriteFile(packet);
     }

Then

I can able to open MyTest.avi file with a player.
2
  • Bounty Award to the person that provides a link to an good example which implements this. using av_interleaved_write_frame or av_write_frame
    – Aditya P
    May 9, 2011 at 8:44
  • check this link which demonstrates the writing video file using FFMPEG libs : stackoverflow.com/a/43464269/6180077 Aug 9, 2017 at 4:35

3 Answers 3

2

Now there's a new example of video transcoding in doc/examples/transcoding.c of FFmpeg trunk, and it does exactly what you need: API example for demuxing, decoding, filtering, encoding and muxing.

This is for the current ffmpeg 2.4.4

0

you need to write an encoder to convert raw data to required video format

ffmpeg encoding sample wanted?

Encode audio to aac with libavcodec

1
  • I can encode and decode data using ffmpeg library( not cli, use api). What i can not do is write to actual file using av_interleaved_write function so that any player can play it.(sure player has neccessary codecs). Feb 25, 2011 at 8:12
-1

I did something like this at some point using libx264 and vorbis.

A code example. https://github.com/Themaister/SSNES/blob/master/record/ffemu.c

The basic idea is that you have to set timestamps yourself in the AVFrame when you want to encode it. Then you can take that packet and write it with av_interleaved_write().

3
  • Well, i can not figure out how to to tell "av_interleaved_write_frame" function write packets to which physical file( such as read packets and write to "mytest.avi" file. Feb 25, 2011 at 8:29
  • Well i figure out. ctx->oformat = av_guess_format(NULL, ctx->filename, NULL); But since i have one source file and destination file, should i have to create 2 AVFormatContext : one for reading and one for writing? Feb 25, 2011 at 8:37
  • It looks like the repo has vanished off the net. Searching for the filename found blog.naver.com/p4violet/120150852154.
    – mwfearnley
    Nov 18, 2018 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.