Bulk convert AVCHD to AVI

Hi,

I would like to be able to quicky compress a lot of .m2ts files to a less disk space hungry format. I assume this can be done with ffmpeg (please correct me if I’m wrong). Would someone be so nice to supply me with some example commands to do the convertion or provide an easy alternative ?

yes ffmpeg is the way to go, but don’t use avi as avi defaults to xvid (mpeg4 part 2) and that is not as good as x264 or x265, the compression depends on the resolution and codec used, for example for SD video x264 is good with ~700k while x265 with 400k or you can use CRF and that value depends on the quality you want CRF can be between 0-51 with lower values having better quality the default is 23.
here is a simple ffmpeg command that you can tweak to your need

ffmpeg -i your_file.m2ts -c:v libx264 -preset slow -crf 22 -c:a copy your_output.mp4

the above converts to mp4 with crf=22 and copies ie does not re-compress audio

if you want to try h265 wich is better but a lot slower then h264 try this

ffmpeg -i your_file.m2ts -c:v libx265 -preset medium -x265-params crf=28 -c:a copy your_output.mp4

the default crf for h265 is 28 and results in files twice as small as h264 with about the same quality.

you can do a more controlled compression by specifying the bitrate and using 2 or more passes but that command will depend on the specific file, you can use crf value of 22 for h264 or 28 for h265 without taking the resolution in account the codec will do that for you.
You can also recompress the audio but that’s a different question.

Thanks a ton. This is exactly what I was looking for. The file I want to compress have got the following properties :

Video:
Resolution - 1920x1080
Frames per second - 25
Data speed - 16754 kb/s
Total transmission speed (hope I’m translating it correct) - 17010 kb/s

Audio:
Speed - 256 kb/s
2 channels
Frequency - 48 kHz

  1. So for an example above h265 is a better option ?
  2. Is it worth re-compressing audio here ?

h265 will make a smaller file then h264 but the compression will take a lot longer (unless you have a fast/powerfull PC) not a lot of hardware players support h265, if you want size go with h265 if you want compatibility and speed go with h264.
about the audio it’s your choice 256k does seam a lot for stereo you can re-compress it to 128k but the size reduction will be negligible compared to the video, but you can try using a vbr compression
see here for ffmpeg audio aac compression
https://trac.ffmpeg.org/wiki/Encode/AAC
just a note I believe the Fraunhoffer libfdk_aac library is not available for openSUSE so you’d need to use one of the other aac encoders (see above ffmpeg page)

h265 is definitely not an option for me since my CPU is weak to say the lest. I will also leave audio compression since I think it will mostly just waste time for me.

> cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Genuine Intel(R) CPU           U7300  @ 1.30GHz
stepping        : 10
microcode       : 0xa0b
cpu MHz         : 1300.000
cache size      : 3072 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority
bogomips        : 2678.03
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Genuine Intel(R) CPU           U7300  @ 1.30GHz
stepping        : 10
microcode       : 0xa0b
cpu MHz         : 800.000
cache size      : 3072 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fdiv_bug        : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority
bogomips        : 2678.03
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

Having said that my first video compression has just finished. The file size is 3 times lower and no noticeable quality differance !! :

ls -lh piracki_statek_20151204185349.m*
-rwxrwxrwx 2 root root 1.6G Dec  4 21:19 piracki_statek_20151204185349.m2ts
-rwxrwxrwx 1 root root 460M Dec  6 05:00 piracki_statek_20151204185349.mp4

The output of compression if some1 interested for future reference :

ffmpeg -i piracki_statek_20151204185349.m2ts -c:v libx264 -preset slow -c:a copy piracki_statek_20151204185349.mp4

Thank you open source for making this possible and so easy :

ffmpeg version 2.8.3 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (SUSE Linux)
  configuration: --shlibdir=/usr/lib --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib --enable-shared --disable-static --enable-debug --disable-stripping --extra-cflags='-fomit-frame-pointer -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g' --enable-pic --optflags='-fomit-frame-pointer -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g' --enable-gpl --enable-x11grab --enable-version3 --enable-pthreads --datadir=/usr/share/ffmpeg --enable-avfilter --enable-libpulse --enable-libwebp --enable-libvpx --enable-libopus --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libxvid --enable-libx264 --enable-libx265 --enable-libschroedinger --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-postproc --enable-libdc1394 --enable-librtmp --enable-libfreetype --enable-avresample --enable-libtwolame --enable-libvo-aacenc --enable-gnutls --enable-libass --disable-decoder=dca --enable-libdcadec --enable-frei0r --enable-libcelt --enable-libcdio --enable-ladspa
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from 'piracki_statek_20151204185349.m2ts':
  Duration: 00:12:41.28, start: 1.040000, bitrate: 17167 kb/s
  Program 1 
    Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:2[0x1200]: Subtitle: hdmv_pgs_subtitle ([144][0][0][0] / 0x0090), 1920x1080
[libx264 @ 0x989b240] using SAR=1/1
[libx264 @ 0x989b240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0x989b240] profile High, level 5.0
[libx264 @ 0x989b240] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=umh subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp4 @ 0x989a4a0] Codec for stream 1 does not use global headers but container format requires global headers                       
[mp4 @ 0x989a4a0] track 1: codec frame size is not set            
Output #0, mp4, to 'piracki_statek_20151204185349.mp4':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.60.100 libx264
    Stream #0:1: Audio: ac3 ([165][0][0][0] / 0x00A5), 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, ?] for help
frame=    8 fps=0.0 q=0.0 size=       0kB time=00:00:00.38 bitrateframe=   19 fps= 19 q=0.0 size=       0kB time=00:00:00.83 bitrateframe=   31 fps= 20 q=0.0 size=       0kB time=00:00:01.28 bitrateframe=   43 fps= 21 q=0.0 size=       0kB time=00:00:01.69 bitrateframe=   54 fps= 21 q=0.0 size=       0kB time=00:00:02.11 bitratekey    function=1.8 q=28.0 size=  461584kB time=00:12:29.34 bitrate=5046.1kbits/s    
?      show this help                                                                                                                 
+      increase verbosity                                                                                                             
-      decrease verbosity                                                                                                             
c      Send command to first matching filter supporting it                                                                            
C      Send/Que command to all matching filters                                                                                       
D      cycle through available debug modes                                                                                            
h      dump packets/hex press to cycle through the 3 states                                                                           
q      quit                                                                                                                           
s      Show QP histogram                                                                                                              
frame=19032 fps=1.8 q=-1.0 Lsize=  470854kB time=00:12:41.28 bitrate=5066.8kbits/s    30.97 bitrate=5046.4kbits/s                     
video:446579kB audio:23790kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.103017%                             
[libx264 @ 0x989b240] frame I:80    Avg QP:19.18  size:107669                                                                         
[libx264 @ 0x989b240] frame P:5186  Avg QP:22.21  size: 44669                                                                         
[libx264 @ 0x989b240] frame B:13766 Avg QP:24.35  size: 15766                                                                         
[libx264 @ 0x989b240] consecutive B-frames:  0.7%  1.7% 20.3% 77.2%                                                                   
[libx264 @ 0x989b240] mb I  I16..4: 38.7% 52.5%  8.9%                                                                                 
[libx264 @ 0x989b240] mb P  I16..4:  4.4%  5.6%  0.6%  P16..4: 46.3% 10.1%  7.2%  0.0%  0.0%    skip:25.8%                            
[libx264 @ 0x989b240] mb B  I16..4:  0.2%  0.3%  0.1%  B16..8: 36.8%  3.1%  0.8%  direct: 3.9%  skip:54.8%  L0:41.2% L1:53.6% BI: 5.3%
[libx264 @ 0x989b240] 8x8 transform intra:52.8% inter:78.9%
[libx264 @ 0x989b240] direct mvs  spatial:100.0% temporal:0.0%
[libx264 @ 0x989b240] coded y,uvDC,uvAC intra: 44.7% 60.2% 20.6% inter: 14.2% 24.6% 1.2%
[libx264 @ 0x989b240] i16 v,h,dc,p: 37% 39% 10% 15%
[libx264 @ 0x989b240] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  6% 10% 22%  7% 11%  8% 13%  7% 16%
[libx264 @ 0x989b240] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  4% 36%  5%  5%  8%  7% 12%  6% 17%
[libx264 @ 0x989b240] i8c dc,h,v,p: 32% 38% 14% 16%
[libx264 @ 0x989b240] Weighted P-Frames: Y:3.8% UV:2.8%
[libx264 @ 0x989b240] ref P L0: 48.3%  8.8% 23.9%  8.7%  8.7%  1.6%  0.0%
[libx264 @ 0x989b240] ref B L0: 78.6% 15.4%  4.7%  1.3%
[libx264 @ 0x989b240] ref B L1: 93.6%  6.4%
[libx264 @ 0x989b240] kb/s:4805.55

there are a few gui wrappers for ffmpeg if you’d like it even simpler
there should be a 13.1 build of ffmpegyag from packman you can get it

zypper in ffmpegyag

about quality well you can try and use a lover crf value
if you’d like a bash file to manually convert all m2ts files in a folder try


#!/bin/bash
for name in *.m2ts; do
ffmpeg -i "$name" -c:v libx264 -crf 22 -c:a libfaac -b:a 128k "${name%.*}.mp4" 
done

save the above as m2ts_to_mp4.sh, copi it to the folder where m2ts are and just double click it.
The above script should re-compress the audio to 128k cbr, you can always edit the above script to finetune your compression options, if the video looks bad you can always reduce the crf to 20 which should be almost perfect.