How to record a video with resolution over the limitations of h264?
KansaiUser opened this issue · comments
I have a similar situation as this issue.
In my case I would like to use rpicam-vid to record a video with a resolution of 1600x1300 (or in another case 3280x2462)
However due to the limitations of h264 it seems this is not possible.
rpicam-vid -t 5000 --width 3280 --height 2462
ERROR: *** failed to start output streaming ***
I read that using mjpeg this is possible and yes when I tried
rpicam-vid -t 5000 --width 3280 --height 2462 --codec mjpeg
I could see my desired video, Yeah!!
However the problem is when I tried to save it
rpicam-vid -t 5000 --width 3280 --height 2462 --codec mjpeg -o hello.mjpeg
I get a file hello.mjpeg
but it is just a static picture, not a movie.
FYI
I am doing this in two rpi 4
in one the version of rpicam-apss is 1.4.3-1 and I have to check on the other but perhaps it is a bit older.
Is there a way to be able to record high definition videos with rpicam-vid?
Attach an example file.
Almost certainly it is an issue in your player seeing the JPEG header (as MJPEG is just a set of concatenated JPEGs) and only looking for one image.
If you want to confirm that, use JPEGsnoop to load the stream, and Tools/Image Search Fwd to search ahead for the next frame.
record with... rpicam-vid -t 10000 --width 3200 --height 1300 --codec mjpeg -o output.mjpeg
convert to mp4 for viewing... ffmpeg -i output.mjpeg -pix_fmt yuv420p -b:v 4000k -c:v libx264 output.mp4
rpicam-vid -t 5000 --width 3280 --height 2462 --codec mjpeg -o hello.mjpeg doesn't play well with vlc when converted...
If the output file is identified as a transport stream, it can be played in mpv Media Player.
rpicam-vid -t 10000 --width 3200 --height 1300 --codec mjpeg -o output.ts
Edit ..to note that mpv can play it even if identified as .mjpeg.
Thank you very much! I managed to do it.
One problem was that VLC could not play it correctly so I kept seeing one frame only. (as 6bya said )
To reproduce it I had to do (and not in the RPI)
vlc --demux=avformat file.mjpeg
Now only remain:
. It seems that the end of the mjpeg is broken because when I read it with opencv, it reads fine but when it finishes it shows [mjpeg @ 00000284baee9480] overread 8 and also the cap.get(cv2.CAP_PROP_FRAME_COUNT) gives a negative number (where cap is cap = cv2.VideoCapture(video_file))
minor nuisances but still wondering why it is happening
One problem was that VLC could not play it correctly so I kept seeing one frame only. (as 6bya said )
VLC has problems during playback if streams don't have timestamps. Try ffplay
and it ought to work correctly.
. It seems that the end of the mjpeg is broken because when I read it with opencv, it reads fine but when it finishes it shows [mjpeg @ 00000284baee9480] overread 8 and also the cap.get(cv2.CAP_PROP_FRAME_COUNT) gives a negative number (where cap is cap = cv2.VideoCapture(video_file))
If ffplay
or ffprobe
does not report any errors in the file, I would ignore this opencv warning(?) if it does not cause any other problems further on.
I think this can be resolved now. Please reopen if there are further questions.