Darknet: Save detection to video file

Created on 7 Nov 2018  路  11Comments  路  Source: pjreddie/darknet

After the latest commits by @pjreddie, the steps listed here by @AlexeyAB don't work anymore.

I have tried using https://github.com/AlexeyAB/darknet but there is a weird issue where-in I don't get any predictions when using that repository, while it works perfectly well when using this repo.

Any help is appreciated!

Most helpful comment

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

All 11 comments

you can change name as .avi

@C-Aniruddh:
I'm searching a solution for the same issue at the moment. Have you found something that works fine?

Thanks in advance for your help!

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

Nice, it works. Thank you very much.

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

how to use it bash script?thanks

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

how to use it bash script?thanks

If I remember right, you can just call the script with the path to the source video as argument. I hope this is enough to help you, otherwise please clarify your problem.

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

Excellent script. It worked for me!

I created a bash script that uses libav (ffmpeg also possible for newer Linux versions). You have to pass the input video as first argument. The output is a MP4 file.

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "ERROR! Usage: help/video filepath"
    exit
fi

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights $1 -prefix pictures
avconv -i pictures_%08d.jpg video.mp4
avconv -i video.mp4 -i $1 output.mp4

rm pictures_*.jpg video.mp4

Thank you for the solution. For some reason avconv doesn't work for me, so I changed your code into:

`#!/bin/bash
if [ $# -eq 0 ]
then
echo "ERROR! Usage: help/video filepath"
exit
fi

./darknet detector demoyolo.data yolov3.cfg backup/yolov3_8000.weights $1 -prefix pictures
ffmpeg -framerate 25 -i pictures_%08d.jpg -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p output.mp4

rm pictures_*.jpg`

That did work. For anyone new to working with bash scripts:

  1. copy the code above
  2. change your paths in the code fpr the cf. file and so on according to your system
  3. save the file
  4. navigate in the terminal (bash) to the place you saved this code
  5. make it executeable by chmod 755 TheNameOfTheFile
  6. Execute the script by entering: ./TheNameOfTheFile PathToYourVideoFile

That's it.

Hello @fj0n @LinderPi while running your scripts, i am getting this error.

rm: cannot remove 'pictures_*.jpg': No such file or directory

Any help?

Hello @fj0n @LinderPi while running your scripts, i am getting this error.

rm: cannot remove 'pictures_*.jpg': No such file or directory

Any help?

Try to only use the darknet command of line 8. To do so, change $1 to the desired filepath. What is your output? It seems that it does not create the wanted output pictures.

Was this page helpful?
0 / 5 - 0 ratings