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.
Mixaz
  • 4,068
  • 1
  • 29
  • 55
NoviceAndNovice
  • 705
  • 2
  • 13
  • 21
  • 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 09 '11 at 08:44
  • check this link which demonstrates the writing video file using FFMPEG libs : https://stackoverflow.com/a/43464269/6180077 – Abdullah Farweez Aug 09 '17 at 04:35

3 Answers3

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

Mixaz
  • 4,068
  • 1
  • 29
  • 55
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

Community
  • 1
  • 1
Aditya P
  • 1,862
  • 5
  • 28
  • 39
  • 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). – NoviceAndNovice Feb 25 '11 at 08: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().

Maister
  • 4,978
  • 1
  • 31
  • 34
  • 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. – NoviceAndNovice Feb 25 '11 at 08: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? – NoviceAndNovice Feb 25 '11 at 08:37
  • It looks like the repo has vanished off the net. Searching for the filename found https://blog.naver.com/p4violet/120150852154. – mwfearnley Nov 18 '18 at 17:06