Need help with passing ffmpeg command line

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Malarki
Posts: 211
Joined: 03 Dec 2019 02:51
Location: Windows 10 x64; 100% Scaling

Need help with passing ffmpeg command line

Post by Malarki »

I'm trying to use ffmpeg in a script to extract subtitles from videos. The following works fine in a command prompt:

ffmpeg -i video.mp4 subtitle.srt

Here video.mp4 is the video file name, and subtitle.srt is the output subtitle file name.

My script is built on this. It expects the video files to have been selected:

Code: Select all

 $a = get("SelectedItemsPathNames", "|");
  foreach($file,$a,"|") {
    if($file == "") {break; }
    selectitems $file , 0 , 1;
    $ffm = "<xydata>\FFmpeg\bin\ffmpeg.exe";
    $subs = $file . ".srt";
    $retmsg = runret("$ffm -i $file $subs");
  }
My problem is in the last line, passing the info to ffmpeg. $retmsg is usually "file not found". I expect it has to do with quotes. I also tried the plain "run" command.

Can anyone tell me the secret handshake here?
Last edited by Malarki on 09 Jan 2021 02:22, edited 1 time in total.

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Need help with passing ffmpeg command line

Post by highend »

Why are you redefining $ffm in every loop?
You don't need the break, foreach() knows an argument for this
Why are you selecting files inside the loop??

Code: Select all

    $ffm = "<xydata>\FFmpeg\bin\ffmpeg.exe";
    $a = get("SelectedItemsPathNames", "|");
        foreach($file, $a, , "e") {
            $srt    = gpc($file, "path") . "\" . gpc($file, "base") . ".srt";
            $retmsg = runret("""$ffm"" -i ""$file"" ""$srt""");
    }
One of my scripts helped you out? Please donate via Paypal

Malarki
Posts: 211
Joined: 03 Dec 2019 02:51
Location: Windows 10 x64; 100% Scaling

Re: Need help with passing ffmpeg command line

Post by Malarki »

Yes, I see that I had needless stuff in the loop; I was cobbling this up from an earlier script. And I never knew about BREAK with the ForEach.

Your script works great. Thanks for the instant help.

Post Reply