Raspberry Pi 4 saving corrupt h264 files? - raspberry-pi

I've been able to record .h264 files without a problem, both using raspivid and through Python, but whatever I try, I can't convert them to a .mp4, .mkv or .avi file.
I've tried converting using MP4box (suggested in several places) and mkvmerge, but to no avail.
When I use MP4box (MP4box -add <source.h264> <dest.mp4>), I get :
AVC-H264 import - frame size 1920 x 1080 at 25.000 FPS
WARNING: NAL Unit type 0 not handled - adding5/100)
AVC Import results: 44 samples - Slices: 3 I 41 P 0 B - 0 SEI - 3 IDR
Saving video.mp4: 0.500 secs Interleaving
Then I try to play this file using VLC, it doesn't give an error, but shows garbled data.
To be clear, the camera works fine (shows perfect video using Python code and raspistill outputs a perfect jpg file). I tried a different camera as well.
An attempt with mkvmerge :
pi#raspberrypi:~/cam $ raspivid -o test.h264 -fps 30 -t 15000 -w 1920 -h 1080
pi#raspberrypi:~/cam $ mkvmerge --default-duration 0:30p -o video.mkv test.h264
mkvmerge v31.0.0 ('Dolores In A Shoestand') 32-bit
'test.h264': Using the demultiplexer for the format 'AVC/h.264'.
'test.h264' track 0: Using the output module for the format 'AVC/h.264 (unframed)'.
The file 'video.mkv' has been opened for writing.
Error: 'test.h264' track 0: mkvmerge encountered broken or unparsable data in this AVC/h.264 video track. Either your file is damaged (which mkvmerge cannot cope with yet) or this is a bug in mkvmerge itself. The error message was:
Success
pi#raspberrypi:~/cam $
This is on a Raspberry Pi 4.
A sample file can be found here : https://filebin.net/c40usz0crhgggadf
Created with : raspivid -t 30000 -w 640 -h 480 -fps 25 -b 1200000 -p 0,0,640,480 -o pivideo.h264

I'm going to respond to this myself. After doing an 'apt-get upgrade', the problem is gone.
If anyone wants to figure this out to find the root cause, this is what apt-get did :
The following packages will be upgraded:
bind9-host bluez-firmware firmware-atheros firmware-brcm80211 firmware-libertas firmware-misc-nonfree firmware-realtek libbind9-161 libdns-export1104 libdns1104 libgs9 libgs9-common libisc-export1100 libisc1100 libisccc161
libisccfg163 liblwres161 libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel raspberrypi-kernel-headers raspi-config rpd-plym-splash
The following packages will be DOWNGRADED:
python3-pgzero
27 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.

Related

Tesseract make training missing ground truth for training

I'm trying to train Tesseract with image and i found this https://github.com/tesseract-ocr/tesstrain
I've followed the instructions on how to train images but I keep on getting this error
Tesseract Open Source OCR Engine v5.0.0-alpha-635-g90405 with Leptonica
Page 1
Warning: Invalid resolution 0 dpi. Using 70 instead.
find data/foo-ground-truth -name '*.lstmf' | python3 shuffle.py 0 > "data/foo/all-lstmf"
Error: missing ground truth for training
Makefile:147: recipe for target 'data/foo/list.train' failed
make: *** [data/foo/list.train] Error 1
It keeps on showing this error Error: missing ground truth for training
command i used make training
the image and ground truth text are from the same repo ocrd-testset.zip
what could possibly the solution to fix this?
EDIT:
Sorry forgot to mention that I only used 1 pair of training image from the ocrd-testset.zip
I followed the instructions in https://github.com/tesseract-ocr/tesstrain on Windows10.
It keeps on showing this error Error: missing ground truth for training at first. It because the code don't work on Windows:
(ALL_LSTMF): $(patsubst %.gt.txt,%.lstmf,$(shell find $(GROUND_TRUTH_DIR) -name '*.gt.txt'))
#mkdir -p $(OUTPUT_DIR)
find $(GROUND_TRUTH_DIR) -name '*.lstmf' | python3 shuffle.py $(RANDOM_SEED) > "$#"
and I change it to :
$(ALL_LSTMF): $(patsubst %.gt.txt,%.lstmf,$(wildcard $(GROUND_TRUTH_DIR)/*.gt.txt))
#mkdir -p $(OUTPUT_DIR)
find $(GROUND_TRUTH_DIR) -name '*.lstmf' -exec echo {} \; | sort -R -o "$#"
Then the error disappeared.
The changed code comes from the old version of tesseract-ocr/tesstrain. It should work on both linux and windows.Maybe you could try it.

Matlab's VideoReader not working on Ubuntu 17.04

I have been struggling to get VideoReader working on Ubuntu 17.04. If I run a simple program:
v = VideoReader('flame.avi')
I get the following:
Error using VideoReader/init (line 619)
Could not read file due to an unexpected error. Reason: Unable to initialize the video obtain properties
Error in VideoReader (line 172)
obj.init(fileName);
Now, I have done a little bit of digging, and most people say that this error comes from not having gstreamer0.10 installed.
See: https://www.mathworks.com/matlabcentral/answers/165584-cannot-read-video-matlab-2014b-linux
This one says that gstreamer1.0 is not sufficient to fix this problem: https://www.mathworks.com/matlabcentral/answers/255157-can-t-load-video-using-videoreader-in-matlab-r2015-on-ubuntu-15-04-could-not-read-file-due-to-an-un
The problem comes from trying to install gstreamer0.10. It doesn't appear to be working in Ubuntu 17.
This one talks about how gstreamer isn't working on Ubuntu 17: https://www.mathworks.com/matlabcentral/answers/294258-hello-i-have-a-problem-with-videoreader-on-matlab-r2016a-with-ubtuntu-lts16-04
I was wondering if anyone had any ideas on how to overcome this issue? Is there a different package that I could install that would fulfill the same requirements? I have tried installing matlab-support, and that hasn't helped either. Is there a different issue other than gstreamer0.10?
I would prefer not to re-install Ubuntu 16.04, but understand if that is the only way. But surely, someone has gotten MATLAB working on Ubuntu 17?
A colleague of mine found a link to a post that solved my problem https://www.mathworks.com/matlabcentral/answers/329796-issue-with-libstdc-so-6
Essentially, you need to redirect MATLAB and tell it to not use its default libstdc++6 file and use your Linux system's instead. I went with the solution at the bottom, and wrote an alias for my .bashrc file.
alias matlab='LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 /usr/local/bin/matlab -desktop'
After testing it out, I have confirmed it works.
I had the exact same problem and I was able to solve it by running
sudo apt install gstreamer1.0-plugins-*
on Ubuntu 20.04 with MATLAB R2018a
Moreover, forcing MATLAB to use the system libstdc++ in ways 1. and 2. did not solve the problem:
Write in ~/.bashrc
alias matlab='LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 /usr/local/bin/matlab -desktop'
closing the terminal, open again, run matlab and still did not work.
going to /usr/local/MATLAB/R2018a/sys/os/glnxa64 and adding .bak to all libstdc++ files (as a means of making them "invisible" to matlab and force it to look for them in the system) did not work either.
EDIT
This is working for at least one video, but still other videos give me the same error. So it is not a full solution
EDIT
One such video I could not open with matlab's video reader becomes accessible after converting it with this script (using opencv).
import cv2
import tqdm
cap = cv2.VideoCapture("output.avi")
vw = None
nframes = 100
# for fast test, change the for loop to
# while True:
# to convert the whole video
for _ in tqdm.tqdm(range(nframes)):
ret, frame = cap.read()
if not ret:
break
if vw is None:
vw = cv2.VideoWriter("output_safe.avi", cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame.shape[1], frame.shape[0]))
vw.write(frame)
cap.release()
if vw is None:
vw.release()
These were the properties of the original video as reported with ffmpeg -i output.avi
Input #0, avi, from 'output.avi':
Metadata:
encoder : Lavf58.64.100
Duration: 00:01:00.00, start: 0.000000, bitrate: 1822 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 2592x1944 [SAR 1:1 DAR 4:3], 1817 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
and these are the new properties
Input #0, avi, from 'output_safe.avi':
Metadata:
encoder : Lavf58.61.100
Duration: 00:00:10.00, start: 0.000000, bitrate: 7594 kb/s
Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 2592x1944, 7650 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc

installing RASPBIAN 3.18 + adicional packages into Raspberry Pi

I've just installed RASPBIAN 3.18 and next packages:
wget http://mirrordirector.raspbian.org/raspbian/pool/main/b/bluez/bluez_4.99- 2_armhf.deb
wget http://mirrordirector.raspbian.org/raspbian/pool/main/libc/libcap- ng/libcap-ng0_0.6.6-2_armhf.deb
wget http://mirrordirector.raspbian.org/raspbian/pool/main/r/radvd/radvd_1.8.5- 1_armhf.deb
wget -O kernel.zip http://www.nordicsemi.com/eng/nordic/download_resource/41602/5/28710770
unzip kernel.zip
sudo dpkg -i radvd_1.8.5-1_armhf.deb
sudo dpkg -i libcap-ng0_0.6.6-2_armhf.deb
sudo dpkg -i bluez_4.99-2_armhf.deb
sudo dpkg -i linux-image-3.17.4-release+_1_armhf.deb
sudo dpkg -i linux-headers-3.17.4-release+_1_armhf.deb
sudo nano /boot/config.txt
Add the following line:
kernel=vmlinuz-3.17.4-release+ to config.txt
save and exit
sudo reboot
and when I restart I got an screen more or less as the print screen attached. Any idea ?
One thing is sure: The rainbow screen means the GPU firmware is loaded, but there is a problem with the kernel image. Which one? Impossible to say from here. Perhaps not found or corrupt. Might be that the kernel you got from www.nordicsemi.com is broken. Might be you have a typo somewhere. But it can also be a faulty SD-card. Or a wrong power supply. According to Google:
In some cases (Stuck on the Rainbow Screen), freezing at this point has been fixed by adding "boot_delay=1" to the config.txt file.
If nothing helps, you probably have to go back to the default Raspian kernel. If you need a more recent kernel than in the default Raspian, you can switch to Raspian testing. The testing kernel should be a bit more recent... and definitely works for me.
This might also help you (https://www.raspberrypi.org/forums/viewtopic.php?t=58151)
Error ACT LED patterns
While booting the ACT LED should blink in an irregular pattern, indicating it is reading from the card. If it starts blinking in a regular (Morse code like) pattern then it is signaling an error.
When it blinks just once: possibly you have a Rpi from Micron. Take a good look at the processor if it says M with an orbit around it, then using the latest software ( after Sept 2013 ) will solve your problem. Also make sure you have a 4Gb SD card: a 2Gb doesn't work in this particular case.
Other patterns that might appear during a failed boot mean:
3 flashes: start.elf not found
4 flashes: start.elf not launch-able (corrupt)
7 flashes: kernel.img not found
8 flashes: SDRAM not recognized. You need newer bootcode.bin/start.elf firmware, or your SDRAM is damaged
Firmware before 20th October 2012 required loader.bin, and the meaning of the flashes was slightly different:
3 flashes: loader.bin not found
4 flashes: loader.bin not launch-able (corrupt)
5 flashes: start.elf not found
6 flashes: start.elf not launch-able
7 flashes: kernel.img not found

avconv: How to concatenate a bunch of flv files (h264 encoded video, adpcm_swf encoded audio)?

I want to concatenate some .flv files (each is h264/adpcm_swf encoded with the same settings). Ideally, I'd like to add something like a cut in between the files - a black screen for 1 or 2 seconds would suffice.
I've tried using avconv's "concat"-protocol, like this:
avconv -i concat:1.flv\|2.flv\|3.flv result.flv
That gives me a result, which contains only the contents of 1.flv and seems to be reencoded with the default flv-settings. That would be handable by giving appropriate output options, but in theory it should be possible to concatenate the files without much reencoding?
My avconv version:
avconv version 0.8.6-6:0.8.6-0ubuntu0.12.10.1, Copyright (c) 2000-2013 the Libav developers
built on Apr 2 2013 17:02:16 with gcc 4.7.2
avconv 0.8.6-6:0.8.6-0ubuntu0.12.10.1
libavutil 51. 22. 1 / 51. 22. 1
libavcodec 53. 35. 0 / 53. 35. 0
libavformat 53. 21. 1 / 53. 21. 1
libavdevice 53. 2. 0 / 53. 2. 0
libavfilter 2. 15. 0 / 2. 15. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 52. 0. 0 / 52. 0. 0
You can use ffmpeg for this concatenating movies. First check if you have ffmpeg installed by running ffmpeg. If the first line ends with "the FFmpeg developers", you're fine. If it is "the Libav developers", then ffmpeg is secretly an alias to avconv (this is the case on Ubuntu). If you don't have ffmpeg and the real ffmpeg is not in your repository, you have to compile ffmpeg yourself.
Now that you have the real ffmpeg, create the file inputs.txt with the following text:
file 1.flv
file 2.flv
file 3.flv
and run:
ffmpeg -f concat -i inputs.txt -c copy result.flv
Another way to concatenate files with ffmpeg without the need of store all the filenames in txt file is the following:
ffmpeg -f concat -i <(for f in *.flv; do echo "file '$f'"; done) -c copy result.flv
You could replace *.flv with whatever filetype you want. In that case do not forget to change the extension of the result file too.

flv reencode to mp4 for iphone/ipod via ffmpeg and x264 (quality issue)

There are a lot of questions on this topic, and I've read most of them and most of the google search results I could come up with.
When I use FFMPEG to convert a FLV to a iphone3 compatble MP4 file, it just doesn't preserver enough of the quality. Yes, I've worked the hell out of -sameq and -b and -bt settings, text just isn't readable.
Next I tried to split the video out and process it directly, using these instructions:
https://sites.google.com/site/linuxencoding/x264-encoding-guide
The problem is myplayer (via ffmpeg) was not able to determine the duration of the FLV (even though the metadata was set).
(I assume) Because of that unknown duration, when I create the MP4 file, the resulting x264 file plays through super-fast while the audio plays at the normal rate.
user#server:/tmp# mplayer -nosound -benchmark -sws 9 -vf dsize=640:480:0,scale=0:0,expand=640:480 -vo yuv4mpeg:file=>(x264 --demuxer y4m --crf 0 --preset slow --threads auto --output output.264 - 2>x264.log) 'input.flv'
MPlayer 1.0rc4-4.4.5 (C) 2000-2010 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing input.flv.
libavformat file format detected.
[flv # 0x1202460]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: video (vp6f), -vid 0
[lavf] stream 1: audio (nellymoser), -aid 0
VIDEO: [VP6F] 1680x992 0bpp 1000.000 fps 33.4 kbps ( 4.1 kbyte/s)
Clip info:
audiocodecid: 6
audiodatarate: 86
audiosamplerate: 44100
audiosamplesize: 16
audiosize: 6097005
canSeekToEnd: true
datasize: 8609138
duration: 567
framerate: 2
hasAudio: true
hasCuePoints: false
hasKeyframes: true
hasMetadata: true
hasVideo: true
height: 992
lasttimestamp: 567
metadatacreator: flvtool++ (Facebook, Motion project, dweatherford)
stereo: false
totalframes: 1043
videocodecid: 4
videodatarate: 33
videosize: 2316256
width: 1680
Using (default) progressive frame mode.Opening video filter: [expand w=640 h=480]
Expand: 640 x 480, -1 ; -1, osd: 0, aspect: 0.000000, round: 1
Opening video filter: [scale w=0 h=0]
Opening video filter: [dsize=640:480:0]
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffvp6f] vfm: ffmpeg (FFmpeg VP6 Flash)
==========================================================================
Audio: no sound
Starting playback...
Movie-Aspect is undefined - no prescaling applied.
[swscaler # 0x7f0c738b9620]Lanczos scaler, from yuv420p to yuv420p using MMX2
VO: [yuv4mpeg] 640x480 => 641x480 Planar YV12
I have also tried specifying FPS, but no change in results
user#server:/tmp# mplayer -nosound -fps 25-benchmark -sws 9 -vf dsize=640:480:0,scale=0:0,expand=640:480 -vo yuv4mpeg:file=>(x264 --demuxer y4m --fps 25 --crf 0 --preset slow --threads auto --output output.264 - 2>x264.log) 'input.flv'
Can someone tell me how to either:
fix my split A/V processing/timing/duration issues?
improve the
quality of the FFMPEG conversion of FLV to iphone3 compatible
format?
I would suggest trying handbreak(http://handbrake.fr/), I think it can encode flvs as well as almost every other file formate I have ever tried, and I'v never had any trouble with quality.