Changing time base on an ffmpeg encode (libffmpeg) - ffmpeg

I'm using libffmpeg to decode an RTSP video stream and write it to a file.
The time_base reported by the codec when I open the stream is 1 / 180000. When I create my output AVStream, I'm copying this time_base over to the output. It works, but I get this message when I call avformat_write_header:
"WARNING codec timebase is very high. If duration is too long,file may not be playable by quicktime. Specify a shorter timebase"
I tried specifying a shorter timebase (say, 1/30) but when I do this, the video plays back at the wrong speed.
What's the right way to adjust the time_base on my output stream without modifying the playback time?
Thanks.

Related

ffmpeg: Decoding specific AVProgram from the hls stream

I am developing a player based on ffmpeg.
Now I try to decode hls video. The video stream has several programs (AVProgram) separated by quality. I want to select one specific program with desired quality. But ffmpeg reads packets from all programs (all streams).
How can I tell ffmpeg which streams to read?
Solved by using disard field in AVStream structure:
_stream->discard = AVDISCARD_ALL;

packet size in ffmpeg after av_read_frame

I have following doubts in ffmpeg.Please clarify.
1.I am reading mp4 file using ffmpeg and after doing av_read_frame
i am getting video(stream_index = 0),audio(stream_index = 1) packets
First there is no order of coming of video/audio packets.Is it the standard case.
2.Video packets are coming of various sizes from the minimum of 14 to the maximum of 21824.Please point why the video packet size varies,somewhere it
is written that for video one packet means one frame,so if for video pkt->size = 14 also equals one frame of video.(pkt is of type AVPacket).
3.If we demux the incoming mp4 stream in Probe function while parsing it and store the info in some buffer or calling av_read_frame demuxes it.
4.Is it possible in ffmpeg to demux the mp4 file and then assign both a/v in one stream of packets where video packet has stream_index = 1,and for audio = 0.
or it has to be in separate stream.
5.Diff between ffmpeg processing for transport stream and mp4 file.
if both are demuxed,decoded in same way or is it different.
Regards
Mayank
A media file is created from mutipule streams. A stream can be of mnay types. Audio, video, captions, metadata etc. But a stream can NOT be of multiple types.
1) av_read_frame will (usually) return the frames in the order they are written to the file. If the software that created the file did not mux them monotonically, you can not read it monotonically.
2) This is precisely how video compression works. The codec stores only the changes between frames. If there is very little motion, then one frame may be very similar to the previous frame, so the delta is very small.
3) This is not a question.
4) No.
5) Largely, no. But there is some difference in the file types. mp4 requires random access, while TS does not.

I cannot use AV_CODEC_ID_MPEG2TS in ffmpeg

I wanna use ffmpeg to convert yuv raw video file into ts stream video file.So I do this in my code:
avcodec_find_encoder(AV_CODEC_ID_MPEG2TS);
But when I run it ,it occurs that:
[NULL # 0x8832020] No codec provided to avcodec_open2()
I change the "AV_CODEC_ID_MPEG2TS" into "AV_CODEC_ID_MPEG2VIDEO", it works well ,and generate a mpg file running well too.So I wanna ask why I cannot use "AV_CODEC_ID_MPEG2TS"?
I'm also looking for streaming a file with ffmpeg so I'm not sure about that but it is what I understand....
Mpeg TS (Transport Stream) is not a codec, it is an encapsulation method, so you have to encode the stream with some code (I'm not sure if you can chose any codec) and then you can encapsulate it with mpeg ts before transmit over the network.
If you don't need to transmit the stream over the network maybe you don't need mpeg ts.
I hope this will helpful....!
Look here: ffmpeg doxygen

What is the minimum amount of metadata is needed to stream only video using libx264 to encode at the server and libffmpeg to decode at the client?

I want to stream video (no audio) from a server to a client. I will encode the video using libx264 and decode it with ffmpeg. I plan to use fixed settings (at the very least they will be known in advance by both the client and the server). I was wondering if I can avoid wrapping the compressed video in a container format (like mp4 or mkv).
Right now I am able to encode my frames using x264_encoder_encode. I get a compressed frame back, and I can do that for every frame. What extra information (if anything at all) do I need to send to the client so that ffmpeg can decode the compressed frames, and more importantly how can I obtain it with libx264. I assume I may need to generate NAL information (x264_nal_encode?). Having an idea of what is the minimum necessary to get the video across, and how to put the pieces together would be really helpful.
I found out that the minimum amount of information are the NAL units from each frame, this will give me a raw h264 stream. If I were to write this to a file, I could watchit using VLC if adding a .h264
I can also open such a file using ffmpeg, but if I want to stream it, then it makes more sense to use RTSP, and a good open source library for that is Live555: http://www.live555.com/liveMedia/
In their FAQ they mention how to send the output from your encoder to live555, and there is source for both a client and a server. I have yet to finish coding this, but it seems like a reasonable solution

Save Live Video Stream To Local Storage

Problem:
I have to save live video streams data which come as an RTP packets from RTSP Server.
The data come in two formats : MPEG4 and h264.
I do not want to encode/decode input stream.
Just write to a file which is playable with proper codecs.
Any advice?
Best Wishes
History:
My Solutions and their problems:
Firt attempt: FFmpeg
I use FFmpeg libary to get audio and video rtp packets.
But in order to write packets i have to use av_write_frame :
which seems that decode /encode takes place.
Also, when i give output format as mp4 ( av_guess_format("mp4", NULL, NULL)
the output file is unplayable.
[ any way ffmpeg has bad doc. hard to find what is wrong]
Second attempth: DirectShow
Then i decide to use DirectShow. I found a RTSP Source Filter.
Then a Mux and File Writer.
Cretae Single graph:
RTSP Source --> MPEG MUX ---> File Writer
It worked but the problem is that the output file is not playable
if graph is not stoped. If something happens, graph crashed for example
the output file is not playable
Also i can able to write H264 data, but the video is completely unplayable.
The MP4 file format has an index that is required for correct playback, and the index can only be created once you've finished recording. So any solution using MP4 container files (and other indexed files) is going to suffer from the same problem. You need to stop the recording to finalise the file, or it will not be playable.
One solution that might help is to break the graph up into two parts, so that you can keep recording to a new file while stopping the current one. There's an example of this at www.gdcl.co.uk/gmfbridge.
If you try the GDCL MP4 multiplexor, and you are having problems with H264 streams, see the related question GDCL Mpeg-4 Multiplexor Problem

Resources