ffmpeg whole directory file conversion question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ffmpeg whole directory file conversion question

Ashley Smiley
Hello,

I am writing to ask advice about how to augment my ffmpeg command line. I
am working through my iMac's Terminal.

The task I am trying to perform is to convert a whole directory of .mp4
files (all with unique filenames) to .png images whose labels correspond to
their original .mp4 files.

The line I've run is:

*for i in *.mp4; *

*do ffmpeg -1 "$i" image%03d.png; *

*done*

This command line batch converts all .mp4 files to continuous .png files.
That is, when moving from video 1 to video 2, the labeling does not start
all over to indicate a break between video files. I would like to insert
label breaks so that I can track which images correspond to which video and
know exactly how many frames exist per video by conveniently having them
labeled starting from 0 or 1 each time.

However, I don't know how to do this as I've searched online for a few days
and I think it's time for suggestions.

An example list of filenames:

calib_checker_22sep18_154022_top_1x1cm.*mp4*
calib_checker_22sep18_154022_side_1x1cm.*mp4*
calib_ball_22sep18_154750_top*.mp4*
calib_ball_22sep18_154930_side.*mp4*

and I want each to have a list of corresponding .pngs, i.e.:

calib_checker_22sep18_154022_top_1x1cm_*001.png*
calib_checker_22sep18_154022_top_1x1cm_*002.png*
calib_checker_22sep18_154022_top_1x1cm_*003.png*

calib_checker_22sep18_154022_side_1x1cm_*001.png*
calib_checker_22sep18_154022_side_1x1cm_*002.png*

calib_ball_22sep18_154750_top_*001.png.*....etc.

calib_ball_22sep18_154930_side_*001.png*....etc.

One last note:

The reason I want to batch process is because there are at least 64 video
files in the directory total.

Sincerely,

Ashley Smiley
--
Ashley Smiley
Ph.D. Candidate, Dudley Lab
Department of Integrative Biology
University of California, Berkeley
berkeleyflightlab.org
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg whole directory file conversion question

DopeLabs
use the variable for the filename in the output filename

for f in *.mp4; do ffmpeg -i "$f" "$f_%03d.png"; done

cheers =]

DL



> On Feb 27, 2019, at 6:04 52PM, Ashley Smiley <[hidden email]> wrote:
>
> Hello,
>
> I am writing to ask advice about how to augment my ffmpeg command line. I
> am working through my iMac's Terminal.
>
> The task I am trying to perform is to convert a whole directory of .mp4
> files (all with unique filenames) to .png images whose labels correspond to
> their original .mp4 files.
>
> The line I've run is:
>
> *for i in *.mp4; *
>
> *do ffmpeg -1 "$i" image%03d.png; *
>
> *done*
>
> This command line batch converts all .mp4 files to continuous .png files.
> That is, when moving from video 1 to video 2, the labeling does not start
> all over to indicate a break between video files. I would like to insert
> label breaks so that I can track which images correspond to which video and
> know exactly how many frames exist per video by conveniently having them
> labeled starting from 0 or 1 each time.
>
> However, I don't know how to do this as I've searched online for a few days
> and I think it's time for suggestions.
>
> An example list of filenames:
>
> calib_checker_22sep18_154022_top_1x1cm.*mp4*
> calib_checker_22sep18_154022_side_1x1cm.*mp4*
> calib_ball_22sep18_154750_top*.mp4*
> calib_ball_22sep18_154930_side.*mp4*
>
> and I want each to have a list of corresponding .pngs, i.e.:
>
> calib_checker_22sep18_154022_top_1x1cm_*001.png*
> calib_checker_22sep18_154022_top_1x1cm_*002.png*
> calib_checker_22sep18_154022_top_1x1cm_*003.png*
>
> calib_checker_22sep18_154022_side_1x1cm_*001.png*
> calib_checker_22sep18_154022_side_1x1cm_*002.png*
>
> calib_ball_22sep18_154750_top_*001.png.*....etc.
>
> calib_ball_22sep18_154930_side_*001.png*....etc.
>
> One last note:
>
> The reason I want to batch process is because there are at least 64 video
> files in the directory total.
>
> Sincerely,
>
> Ashley Smiley
> --
> Ashley Smiley
> Ph.D. Candidate, Dudley Lab
> Department of Integrative Biology
> University of California, Berkeley
> berkeleyflightlab.org
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg whole directory file conversion question

Ashley Smiley
Dear DL,

please see my previous message about what I am trying to accomplish with my
code. The code you sent, that is,

for f in *.mp4; do ffmpeg -i "$f" "$f_%03d.png"; done

works but is not what I want to accomplish. This line converts all the
videos to images, yes, but without restarting the numbering system within
each video. If I use this line of code for a directory filled with 64
videos I have to write 64 lines for each unique filename when I want to
write only one line.

To rephrase my question:

is it possible to write a line using ffmpeg to convert a large amount of
videos to images all at once while chronologically numbering the order of
images per video?

I'll give another example if the one I originally provided is unclear.

each video file has a unique name and there are A LOT of videos.
video_file_a_1.mp4
video_file_b_2.mp4
video_file_c_3 .mp4

I want my .pngs to look like:

video_file_a_1_001.png
video_file_a_1_002.png
video_file_a_1_003.png

video_file_b_2_001.png
video_file_b_2_002.png
video_file_b_2_003.png

video_file_c_3_001.png
video_file_c_3_002.png
video_file_c_3_003.png

If I use the code you sent:

for f in *.mp4; do ffmpeg -i "$f" "$f_%03d.png"; done

what I get is:

001.png
002.png
003.png
004.png
......
and on and on and on because I have 64 video files in this directory.

Which means I have to write that line 64 times and modify it per video
name. Is there a way around this? Can ffmpeg designate multiple outputs
options?

Sincerely,

Ashley



On Thu, Feb 28, 2019 at 2:57 AM DopeLabs <[hidden email]> wrote:

> use the variable for the filename in the output filename
>
> for f in *.mp4; do ffmpeg -i "$f" "$f_%03d.png"; done
>
> cheers =]
>
> DL
>
>
>
> > On Feb 27, 2019, at 6:04 52PM, Ashley Smiley <[hidden email]>
> wrote:
> >
> > Hello,
> >
> > I am writing to ask advice about how to augment my ffmpeg command line. I
> > am working through my iMac's Terminal.
> >
> > The task I am trying to perform is to convert a whole directory of .mp4
> > files (all with unique filenames) to .png images whose labels correspond
> to
> > their original .mp4 files.
> >
> > The line I've run is:
> >
> > *for i in *.mp4; *
> >
> > *do ffmpeg -1 "$i" image%03d.png; *
> >
> > *done*
> >
> > This command line batch converts all .mp4 files to continuous .png files.
> > That is, when moving from video 1 to video 2, the labeling does not start
> > all over to indicate a break between video files. I would like to insert
> > label breaks so that I can track which images correspond to which video
> and
> > know exactly how many frames exist per video by conveniently having them
> > labeled starting from 0 or 1 each time.
> >
> > However, I don't know how to do this as I've searched online for a few
> days
> > and I think it's time for suggestions.
> >
> > An example list of filenames:
> >
> > calib_checker_22sep18_154022_top_1x1cm.*mp4*
> > calib_checker_22sep18_154022_side_1x1cm.*mp4*
> > calib_ball_22sep18_154750_top*.mp4*
> > calib_ball_22sep18_154930_side.*mp4*
> >
> > and I want each to have a list of corresponding .pngs, i.e.:
> >
> > calib_checker_22sep18_154022_top_1x1cm_*001.png*
> > calib_checker_22sep18_154022_top_1x1cm_*002.png*
> > calib_checker_22sep18_154022_top_1x1cm_*003.png*
> >
> > calib_checker_22sep18_154022_side_1x1cm_*001.png*
> > calib_checker_22sep18_154022_side_1x1cm_*002.png*
> >
> > calib_ball_22sep18_154750_top_*001.png.*....etc.
> >
> > calib_ball_22sep18_154930_side_*001.png*....etc.
> >
> > One last note:
> >
> > The reason I want to batch process is because there are at least 64 video
> > files in the directory total.
> >
> > Sincerely,
> >
> > Ashley Smiley
> > --
> > Ashley Smiley
> > Ph.D. Candidate, Dudley Lab
> > Department of Integrative Biology
> > University of California, Berkeley
> > berkeleyflightlab.org
> > _______________________________________________
> > ffmpeg-user mailing list
> > [hidden email]
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> >
> > To unsubscribe, visit link above, or email
> > [hidden email] with subject "unsubscribe".
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".



--
Ashley Smiley
Ph.D. Candidate, Dudley Lab
Department of Integrative Biology
University of California, Berkeley
berkeleyflightlab.org
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: ffmpeg whole directory file conversion question

Carl Zwanzig
On 2/28/2019 5:12 PM, Ashley Smiley wrote:
> If I use the code you sent:
> for f in *.mp4; do ffmpeg -i "$f" "$f_%03d.png"; done
>
> what I get is:
> 001.png
> 002.png

Try this--
   for f in *.mp4; do ffmpeg -i "$f" "${f}_%03d.png"; done

(assuming bash shell)
without the {}, the second $f disappears because the underscore is
considered part of the variable name, i.e. variable "f_". If you used a
different separator character, this won't happen. (Always surround a var
name with {} when its used inside a string.)

The " also aren't needed unless there are spaces in the file names.

However.... you'll get filenames formed from "Sign_Off_clean.mp4_%03d.png"
with the ".mp4" in them.


If there aren't any spaces in the file names--
    for f in `ls *.mp4 | sed -e 's/.mp4//'`; do ffmpeg -i "$f"
"${f}_%03d.png"; done

ought do Do The Right Thing.

Past that, it's a shell scripting problem, not an ffmpeg one.

(please don't top-post on this list)

Later,

z!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".