2

I have these example files in an Ubuntu 18.04 system:

VID_20190407_160033.3gp  
VID_20190407_161444.3gp  
VID_20190407_161609.3gp  

VID_20190415_183315.3gp  
VID_20190415_183411.3gp  
VID_20190415_192712.3gp  

VID_20190420_124435.3gp  
VID_20190420_125755.3gp  
VID_20190420_130214.3gp  
VID_20190420_141700.3gp  

And I want to concatenate 3GP files by a script (perhaps with ffmpeg ?) into one file, selecting files by the YYYYMMDD date in the file name, with a result of:

VID_20190407.3gp
VID_20190415.3gp
VID_20190420.3gp

What is the best way to script that?

System

Linux local 5.0.0-29-lowlatency #31-Ubuntu SMP PREEMPT Thu Sep 12 14:13:01 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Thank you.

K7AAY
  • 17,705
genderbee
  • 860

1 Answers1

3

3GP files can be concatenated with the use of ffmpeg by a command similar to:

ffmpeg -f concat -i <(find . -name 'YYYYMMDD_XXXXXX.3gp' -printf "file '$PWD/%p'\n") -c copy YYYYMMDD.3gp

once you create a for-next loop to filter on the YYYYMMDD using the first instance of the first value for that as a variable, collect the _XXXXXX file name components, and step through them sequentially; then, move on to the next YYYYMMDD value and step through all its files.

--

An alternate and more elegant method using a virtual concat demuxer which has brought to my attention by llogan would be to

A) count the number of files with the first YYYYMMDD prefix, then
B) create a control file mylist.txt with a line for each of the files matching that date prefix, which would look like:

$ cat mylist.txt
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
file '/path/to/file4'

or

$ cat mylist.txt
file '/path/to/YYYYMMDD_XXXXX1.3gp'
file '/path/to/YYYYMMDD_XXXXX2.3gp'
file '/path/to/YYYYMMDD_XXXXX3.3gp'
file '/path/to/YYYYMMDD_XXXXX4.3gp'

then C) execute

ffmpeg -f concat -i mylist.txt -c copy YYYYMMDD.mp4

Now, you've concatenated the first file set. Step on to the next YYYYMMDD group and repeat.

K7AAY
  • 17,705