Good Day,
I have written an application that uses the V4L2 driver to capture H264 Raw frames from a C920. The bytes are output into stdout, and can be piped to a file or any program
What I am trying to do is this:
./capture | ffmpeg -f h264 -i - -b 500000 -vcodec copy out.mp4
The idea is to capture a raw video and convert it to an mp4 file on the fly. It works perfectly, however, the bit rate compression is never applied. It ends up with a file the same size as the raw file (since the camera outputs a compressed h264 file but in raw frames already)
However, if I was to do this instead
./cature > input.raw
ffmpeg -i out.mp4 -b 500000 output.mp4
Now, it compresses the file down to a reasonable size. Is there a reason for this? My only current solution right now is to use an alternative like gstreamer (which has issues with h264) or to figure out the ffmpeg API and see if I can add some code to make it do compression on the frames on the fly.
I guess the problem is that you use -vcodec copy
that says don't touch the video codec. I would just omit that argument for a full reencoding.
From the ffmpeg documentation:
Stream copy is a mode selected by supplying the copy parameter to the ‘-codec’ option. It makes ffmpeg omit the decoding and encoding step for the specified stream, so it does only demuxing and muxing. It is useful for changing the container format or modifying container-level metadata.
Please note that -vcodec
is an alias for -codec:v
that is the reason why -codec
answers you problem.