-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to write H264 bytestream and get valid H264 data back: ffmpeg reports "Invalid data found when processing input" #339
Comments
When I insert the module with debug=3 I do see attempts to write:
Is it possible that between the time I startup the writer and when I start v4l2rtspserver I am losing bytes? Is there a setting to indicate that unless both ends are connected not to start the stream and block? |
got same issue |
I know this is an old issue by now, but for posterity: The issue here is that
|
Are you saying that dd is asking the v4l2 device for at most 512 bytes at the start and then the v4l2 device is providing it but then throwing the rest of the frame away? So the next read of 512 bytes is infact a whole new frame? That's a lot of data to throw away isn't it since a frame is usually a lot more than 512 bytes right? |
Yep, you got it. I don't think this is intentional behavior, exactly, but the driver code to support the Support for partial buffer reads is dicey, because a fast producer can and will overwrite the partially-read buffer if the consumer is too slow reading it, and then the client is stuck with part of a frame. An H.264 decoder could resync on the next start code, but not all formats support that sort of thing. I think the upshot here is that as long as you're dealing with a format with variable-length frames like H.264, the only way to avoid trouble is to read whole buffers at a time, which means using |
It's also worth noting that there is apparently some work going on to move to a different buffer-management framework (#406), which might change the situation somewhat. |
Environment
This is an Ingenic T20 MIPS processor with custom kernel.
Reproduction
modprobe v4l2loopback devices=1
This gives me
/dev/video3
(this is because 0,1, and 2 are being used by Ingenic's custom kernel code and aren't really working v4l2 devices).Send some data to the
/dev/video3
device.I am using the code here:
https://gist.github.com/tachang/e0cdf9d72a4dd9db2050ff8daf3b9892
It retrieves H264 NAL units and writes it out to /dev/video3.
I then read from /dev/video3 and dump it out to a file. I do
dd if=/dev/video3 of=temp_video.264
.For some reason when I attempt
ffmpeg -i temp_video.264 -c copy -bsf:v trace_headers -f null -
I get
temp_video.264: Invalid data found when processing input
However when I write the to a file instead of
/dev/video3
I can see the frames:https://gist.github.com/tachang/51fec92dfdd65228e65bd32502bdc894
This is why I suspect it is an issue in the v4l2loopback driver.
I have the /dev/video3 raw dump here using dd:
https://github.com/tachang/attachments/blob/master/dev_video_3_dump.bin
It contains as the first few bytes
00 00 00 01
which is what you'd expect:So what I am observing is that the output from
/dev/video3
when doingdd
doesn't seem to parse inffmpeg
but when I dump it direct to a file and useffmpeg
it does parse it. So I thinkv4l2loopback
is doing something with the frames.The text was updated successfully, but these errors were encountered: