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
- Read media packets from media source ( it may be real file(.avi,mov) or even rtsp server).
- 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.
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 withav_interleaved_write()
.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
you need to write an encoder to convert raw data to required video format
Probably this link may help you:
Output a media file in any supported libavformat format
I hope it helps.