1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

use ffmpeg slice, add watermark and converting at once in PHP

Discussion in 'Programming' started by vOlLvEriNe, Nov 14, 2016.

  1. #1
    Hi everyone, I'm using 3 commands to slice a video, add watermark on it and convert it to gif animation through ffmpeg nad PHP, how can use these commands to execute at once, commands are:
    exec('ffmpeg -ss 00:00:08 -i movie.mp4 -to 00:00:10 -c copy -copyts output.mp4');
    PHP:
    exec('ffmpeg -i output.mp4 -i watermark.jpg -filter_complex "[1:v]scale=-1:120*(1/6)[wm];[0:v][wm]overlay=x=main_w-overlay_w-main_w/20:y=main_h-overlay_h-main_w/20" output2.mp4');
    PHP:
    exec('C:\xampp\ffmpeg.exe -i cut.mp4 -pix_fmt rgb24 output.gif');
    PHP:

     
    vOlLvEriNe, Nov 14, 2016 IP
  2. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #2
    Seems like you're on windows, try using the & to do separate commands

    exec('dir & dir & echo foo');
     
    Einheijar, Nov 14, 2016 IP
  3. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Yes, I'm windows user, And I'm trying to avoid from saving file everytime, proceed all processes at once
     
    vOlLvEriNe, Nov 14, 2016 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Shouldn't something like this work:
    
    exec('ffmpeg -ss 00:00:08 -i movie.mp4 -to 00:00:10 -i watermark.jpg -filter_complex "[1:v]scale=-1:120*(1/6)[wm];[0:v][wm]overlay=x=main_w-overlay_w-main_w/20:y=main_h-overlay_h-main_w/20" -pix_fmt rgb24 output.gif');
    
    PHP:
    Not tested, mind, but taken out all the copying - the only thing I didn't use was the "-c copy -copyts" but as far as I can see that shouldn't be needed as long as you're not remaking the file.
     
    PoPSiCLe, Nov 15, 2016 IP
  5. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Its not working, I've 0% experience of linux commands
     
    vOlLvEriNe, Nov 18, 2016 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Try running it via command-line, to see what error it gives, or look at the PHP-logs or other logs to see if there's an error there.
     
    PoPSiCLe, Nov 19, 2016 IP
  7. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Option to (record or transcode stop time) cannot be applied to input file watermark.jpg -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
    Error parsing options for input file watermark.jpg.
    Error opening input files: Invalid argument
    Code (markup):
     
    Last edited: Nov 19, 2016
    vOlLvEriNe, Nov 19, 2016 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    Aha. Oh, well. You can probably put all of them in one exec(), at least - although I don't exactly remember the syntax. Each string separated by one |, maybe?
     
    PoPSiCLe, Nov 19, 2016 IP
  9. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #9
    Dear But I want to avoid from saving multiple files, like first created cut file from main file, seconds it generates with watermark, and then It saves the gif file, I want to execute all commands and save a single file
     
    vOlLvEriNe, Nov 19, 2016 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Well.. I get that. However, right now, I don't know how :) But if the concern is the multiple files added, just remove the extra files after running through the commands?
     
    PoPSiCLe, Nov 20, 2016 IP
  11. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #11
    If you're worried about generating duplicate files halfway, you could always use the tempnam() command :)
     
    Einheijar, Nov 20, 2016 IP
  12. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #12
    Yes Deleting Files Is better option, But it takes time to execute :(
     
    vOlLvEriNe, Nov 20, 2016 IP
  13. Einheijar

    Einheijar Well-Known Member

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    165
    #13
    You won't save much time skipping out on temp files, it will still be processed step by step.
     
    Einheijar, Nov 20, 2016 IP
  14. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #14
    I mean It takes time to read file for watermark and after that again get a file and save, It takes time to proceed
     
    vOlLvEriNe, Nov 21, 2016 IP
  15. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #15
    Run it on an SSD-drive. The file-fetching will make minimal impact, the real time-consume is the actual processing of the files by ffmpeg.
     
    PoPSiCLe, Nov 21, 2016 IP
  16. vOlLvEriNe

    vOlLvEriNe Member

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #16
    Thank you All of you for great response
     
    vOlLvEriNe, Nov 21, 2016 IP