I want to save a video file from the raspberry camera, by using the v4l2 driver and ffmpeg. v4l2-ctl is able to capture the video, though ffmpeg is not. When i run the command: ffmpeg -f video4linux2 -i /dev/video0 test.mp4 i get output like this:

DTS 140462612207577, next:1759963 st:0 invalid dropping
PTS 140462612207577, next:1759963 invalid dropping st:0
DTS 140462612247558, next:1799963 st:0 invalid dropping
PTS 140462612247558, next:1799963 invalid dropping st:0

and the video file is empty. When i run ffmpeg -f video4linux2 -i /dev/video0 -c:v copy test.mp4 i get

[mp4 @ 0x1e44570] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0x1e44570] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.

and the video file is again empty. I manage to capture with ffmpeg and raspivid with pipelining " | ", but i want to do it with v4l2 driver as well. Any suggestions?


You need to select the input and output format. The v4l2 driver and the Pi Camera can stream video directly compressed with h264, which is convenient. By not specifying any format, you get some raw video format which then gets encoded by ffmpeg in h264 (this usually takes a lot of CPU and time).

The command would be

ffmpeg -f v4l2 -input_format h264 -i /dev/video0 -c:v copy -f mp4 file.mp4

Which selects h264 as input format for the camera (-input_format h264), and then uses it as it is (-c:v copy means do not transcode) and then bundles it into an mp4 container (-f mp4).

The first warning says "fix your code", so I suppose it's a warning left to a developer, so I imagine you can safely ignore ti.

The second warning (Non-monotonous DTS) is about the timestamp for each frame. It seems not to be affecting the resulting file.


The command is ffmpeg -f video4linux2 -input_format h264 -i /dev/video0 out.h264

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.