2

I need to batch extract thumbnail pic from hundreds of .mpg files using the following bat code, which works like a charm, but the only drawback is that the output png are with file name like "filename.mp4.png". so my question is how can I rewrite the code so that there are no .mp4 in the output png file?

for %%A IN (*.mp4) DO ffmpeg -i "%%A" -vf "select=gte(n\,300)" -vframes 1 "%%A.png"
1
  • Welcome on SuperUser. Take your time to check the answer you received and to give us a feedback.
    – Hastur
    Jul 11 '16 at 14:50
1

It is possible to find [1] that %%~n should give you the filename with no extension.

Try if it works

for %%A IN (*.mp4) DO ffmpeg -i "%%A" -vf "select=gte(n\,300)" -vframes 1 "%%~nA.png"

Note: You can read more in many document on internet about the expansion rules, starting from that answer [1] and this old nt guide [2].

1
  • This is exactly what I want ,thank you very much. Jul 12 '16 at 7:16
2

What you are looking for is parameter expansion, specifically, the substring removal. Try this:

for file in *.mp4; do echo ffmpeg -i "$file" -vf "select=gte(n\,300)" -vframes 1 "${file%.mp4}.png"; done

If you have a variable $file, you can use ${file%.mp4} to output the contents, with the last .mp4 stripped off.

Here is an article with more information: http://wiki.bash-hackers.org/syntax/pe

EDIT: Very sorry, but I thought the tag said "BASH" instead of "batch". I wondered about the funny syntax. However, I'll leave this here for now. If nobody knows a way to do this with Windows, it's quite trivial with BASH, so perhaps you could pick up a BASH shell somewhere if there's no better alternative.

3
  • Hi, maybe you want to check the syntax of your command. It seems an hybrid between Windows and Bash. brrrr.... The Op seems to be from that world... the one without wall but still in need of Windows and Gates... ;-).
    – Hastur
    Jul 11 '16 at 14:21
  • Thanks. I had just made a note about that. The funny thing is that the line worked with the change in only the variable name and adding done. I didn't know that BASH would handle the uppercase like that, but it does. I modified the result to make it a bit more standard.
    – DKing
    Jul 11 '16 at 14:29
  • You're welcome. For windows 10 there is a bash shell (Ubuntu derived if I remember well). It exists cygwin so it is usable if he really wants. (cough.. echo ..cough). :-)
    – Hastur
    Jul 11 '16 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.