0

I have a c++ script that coneverts a series of jpg into a .mp4 video, the command i use is the folllowing:

std::system("ffmpeg -threads auto -y -framerate 1.74659 -i /mnt/ev_ramdsk/1/%05d-capture.jpg -vcodec libx264 -preset ultrafast /mnt/ev_ramdsk/1/video.mp4");

which produces a .mp4 video file like its supposed to except it cant be played from anywhere (tested in 2 computers and html5 video)

But, if from the same computer where the program runs, i do:

ffmpeg -threads auto -y -framerate 2 -i %05d-capture.jpg -vcodec libx264 -preset ultrafast video.mp4

from the command line, the output video plays wonderfully (except in vlc, for vlc i have to use -vcodec mpeg4)

What can possibly cause this behaviour? could cp command corrupt the file? (ran after the mpeg to move it out of the ramfs)

EDIT:

As requested, i ran the whole set of commands one by one in the console exactly as the program do (the program logs every single command it runs, i just repeated them).

The commands are:

cp -r /var/cache/zoneminder/events/1/16/05/18/23/30/00/ /mnt/ev_ramdsk/1/
ffmpeg -threads auto -y -framerate 1.76729 -i /mnt/ev_ramdsk/1/%5d-capture.jpg -preset ultrafast /mnt/ev_ramdsk/1/video.mp4
cp /mnt/ev_ramdsk/1/video.mp4 /var/cache/evmanager/videos/1/2016_05_18_23_30_00_.mp4

The resulting .mp4 file can be played without any trouble. Also, is the only one with a preview image in the file explorer.

Thank you very much!

Arheisel
  • 186
  • 11
  • 1
    `-framerate 2` is not the same as `-framerate 1.74659`, you should try testing with the exact same command line. – The Dark May 18 '16 at 23:52
  • At first, because of fps being int (later changed to float) tge command used to execute with -framerate 1 and none of the videos are playable – Arheisel May 19 '16 at 00:16
  • @Arheisel `std::system` calls the command processor. You also have `execv` and similar functions. You may need to call the latter instead of `system`. See [here](http://stackoverflow.com/questions/1697440/difference-between-system-and-exec-in-linux) – PaulMcKenzie May 19 '16 at 00:41
  • What I meant was that you are saying "this command doesn't work from `system` but this *different* command works from the command line, therefore the problem is with `system`." I'm saying try running the *exact same command* from the command line as the problem may be with the actual command. – The Dark May 19 '16 at 00:57
  • You're right, im sorry. I will try it out and post the results. I also want to try execv but i cant find any documentation of it. – Arheisel May 19 '16 at 00:59
  • Execv is not an option as the manual says "There shall be no return from a successful exec, because the calling process image is overlaid by the new process image." – Arheisel May 19 '16 at 01:08
  • Im thinking of forking the process and caling execve on the child, but im not sure how to archieve this correctly or know when ffmpeg has finished to continue execution – Arheisel May 19 '16 at 03:11
  • Does this **[link](http://unix.stackexchange.com/a/86945)** help you? `-r 1` before specifying the PNG files seems important. Also according to that link, 10 FPS is the lowest acceptable framerate for VLC (things might have changed since 2013, but maybe not, so test that different FPS too) – VC.One May 19 '16 at 13:43

1 Answers1

4

Solved it!

this was the winning answer. finally got it to work using:

std::system("ffmpeg -threads auto -y -r 1.74659 -i /mnt/ev_ramdsk/1/%05d-capture.jpg -px_fmt yuv420p -preset ultrafast -r 10 /mnt/ev_ramdsk/1/video.mp4");

Thank you very much!

Community
  • 1
  • 1
Arheisel
  • 186
  • 11