Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg How to write video to a file

Tags:

c

ffmpeg

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.
like image 431
NoviceAndNovice Avatar asked Feb 24 '11 17:02

NoviceAndNovice


People also ask

Can FFmpeg convert video?

FFmpeg is an open-source audio and video converter that supports most industry-standard codecs and can convert from one file format to another quickly and easily. It also lets you capture video and audio from a live source and process it.

Does FFmpeg work with mp4?

FFmpeg can input most container formats natively, including MP4, . ts, MOV, AVI, Y4M, MKV, and many others.

What is FFmpeg video format?

ffmpeg is a command-line tool that converts audio or video formats. It can also capture and encode in real-time from various hardware and software sources such as a TV capture card. ffplay is a simple media player utilizing SDL and the FFmpeg libraries.


1 Answers

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

like image 97
Mixaz Avatar answered Oct 22 '22 09:10

Mixaz