https://pymotw.com/2/multiprocessing/basics.html
Friday, 26 March 2021
Wednesday, 24 March 2021
How to change docker image directory path?
ref: https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/
If you want to move the docker data directory on another location you can follow the following simple steps.
1. Stop the docker daemon
sudo service docker stop
2. Add a configuration file to tell the docker daemon what is the location of the data directory
Using your preferred text editor add a file named daemon.json under the directory /etc/docker. The file should have this content:
sudo vi /etc/docker/daemon.json
{
"data-root": "/home/ninja/docker/",
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
}
}
of course you should customize the location “/path/to/your/docker” with the path you want to use for your new docker data directory.
3. Copy the current data directory to the new one
sudo rsync -aP /var/lib/docker/ /path/to/your/docker
4. Rename the old docker directory
sudo mv /var/lib/docker /var/lib/docker.old
This is just a sanity check to see that everything is ok and docker daemon will effectively use the new location for its data.
5. Restart the docker daemon
sudo service docker start
6. Test
If everything is ok you should see no differences in using your docker containers. When you are sure that the new directory is being used correctly by docker daemon you can delete the old data directory.
sudo rm -rf /var/lib/docker.old
Follow the previous steps to move docker data directory and you won’t risk any more to run out of space in your root partition, and you’ll happily use your docker containers for many years to come. 😉
How to mount the remote folder into a local folder?
sshfs -o big_writes user@192.168.1.123:/remote/folder/ /home/ninja/local/folder
Monday, 15 March 2021
How to sort file name according to numerical order in python?
before_255/1.npy
before_255/2.npy
before_255/3.npy
before_255/4.npy
before_255/5.npy
before_255/6.npy
before_255/7.npy
before_255/8.npy
before_255/9.npy
before_255/10.npy
before_255/11.npy
before_255/12.npy
before_255/13.npy
before_255/14.npy
before_255/15.npy
before_255/16.npy
before_255/17.npy
before_255/18.npy
before_255/19.npy
before_255/20.npy
How to compress video to mp4 using FFMPEG?
ffmpeg -i input.name -vcodec libx264 output.mp4
ffmpeg -i input.name -vcodec mpeg4 output.mp4
(these videos are playable by browser)
ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4
Tuesday, 9 March 2021
How to do screen recording in ubuntu using kazam?
sudo apt install kazam
then just open kazam and record
Monday, 8 March 2021
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_CUDA_LIBRARY (ADVANCED)
linked by target "opencv_cudacodec" in directory /home/user/workspace/opencv_contrib-4.4.0/modules/cudacodec
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:CUDA_nvcuvid_LIBRARY (ADVANCED)
linked by target "opencv_cudacodec" in directory /home/user/workspace/opencv_contrib-4.4.0/modules/cudacodec
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:CUDA_nvcuvenc_LIBRARY (ADVANCED)
linked by target "opencv_cudacodec" in directory /home/user/workspace/opencv_contrib-4.4.0/modules/cudacodec
1. check the libcuda, libnvcuvid and libnvidia-encode found in the system. Remove them all except the one under /usr/lib/x86_64-linux-gnu which corresponds to nvidia-smi driver version, the non related one just remove
2. version tested as following:-
version 1:
gpu 3090, ubuntu18, nvidia-smi 455.32.00, /usr/lib/x86_64-linux-gnu/libcuda.so /usr/lib/x86_64-linux-gnu/libcuda.so.1, /usr/lib/x86_64-linux-gnu/libcuda.so.455.32.00, /usr/local/cuda-11.0/lib64/libnvcuvid.so, /usr/local/cuda-11.0/lib64/libnvcuvid.so.455.32.00, /usr/local/cuda-11.0/lib64/libnvcuvid.so.1
version 2:
Sunday, 7 March 2021
How to use FFMPEG to stream RTSP into a video?
A Simple Way:
ffmpeg -i rtsp://192.168.80.112 -r 30 -vcodec copy -an -t 60 temp.mp4
ffmpeg -i rtsp://192.168.80.112 -b 900k -vcodec copy -r 60 -y MyVdeoFFmpeg.avi
ffmpeg -i rtsp://192.168.80.112 -acodec copy -vcodec copy ./abc.mp4
Simple Stream to file
Simple stream to file. Full resolution
ffmpeg -loglevel debug -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live" \
-c copy -map 0 foo.mp4
Break streamed file into time segments
ffmpeg can save file in arbitrary segments at fixed intervals. In this example, we save a new file at
10 second intervals, but the value for segment_time
can be any positive integer
ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live" \
-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 \
-c copy -map 0 test%d.mp4
Timestamped output
Output files can be timestamped as well.
ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/live" \
-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 \
-strftime 1 -c copy -map 0 dauphine-%Y%m%d-%H%M%S.mp4
Select stream to read from.
A different url is used to select the substream. Set subtype
to 0 for main hi-res stream, or
1 for low res substream. Channel looks to always be set to 1
ffmpeg -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/cam/realmonitor?channel=1&subtype=1" \
-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 \
-strftime 1 -c copy -map 0 test-%Y%m%d-%H%M%S.mp4
p/s: copied from https://gist.github.com/mowings/6960b8058daf44be1b4e
Wednesday, 3 March 2021
How to convert to opencv Mat to float based on NCHW in C++?
void convertToVector(cv::Mat &img, std::vector<float> &values, int count)
{
std::vector<float> normalize(3, 1);
normalize = {255, 255, 255};
std::vector<float> mean(3, 0);
std::vector<float> std(3, 1);
bool bgrtorgb = false;
int size = img.cols * img.rows;
int channel = img.channels();
std::cout << size << " " << channel << std::endl;
// for (int i = 0; i < steps.size(); i++) {
// auto step = steps[i];
// if (step == "subtract128") {
// mean = {128, 128, 128};
// std = {1, 1, 1};
// normalize = {1, 1, 1};
// } else if (step == "normalize") {
// normalize = {255, 255, 255};
// } else if (step == "mean") {
// mean = {0.406f, 0.456f, 0.485f};
// } else if (step == "std") {
// std = {0.225f, 0.224f, 0.229f};
// } else if (step == "bgrtorgb") {
// bgrtorgb = true;
// } else {
// CAFFE_ENFORCE(
// false,
// "Unsupported preprocess step. The supported steps are: subtract128, "
// "normalize,mean, std, swaprb.");
// }
// }
int C = channel ? 3 : 1;
int total_size = C * size;
// std::vector<float> values(total_size);
if (C == 1)
{
cv::MatIterator_<float> it, end;
int idx = 0;
for (it = img.begin<float>(), end = img.end<float>(); it != end; ++it)
{
values[idx++] = (*it / normalize[0]);
}
}
else
{
int i = count;
cv::Mat_<cv::Vec3b>::iterator it, end;
int b = bgrtorgb ? 2 : 0;
int g = 1;
int r = bgrtorgb ? 0 : 2;
for (it = img.begin<cv::Vec3b>(), end = img.end<cv::Vec3b>(); it != end; ++it, i++)
{
//std::cout << (int)(*it)[b] << " " << (int)(*it)[g] << " " << (int)(*it)[r] << std::endl;
values[i] = (((*it)[b] / normalize[0]));
int offset = size + i;
values[offset] = (((*it)[g] / normalize[1]));
offset = size + offset;
values[offset] = (((*it)[r] / normalize[2]));
}
}
}