Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, my camcorder records in .mts I am unable to view .mts files to my satisfaction because if I stop the video while it is playing, the display will be ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    49

    command line - can I get terminal to convert multiple files and assign


    Hi,

    my camcorder records in .mts
    I am unable to view .mts files to my satisfaction because if I stop the video while it is playing, the display will be messed up when it restarts. because of this, I convert the files to .avi with ffmpeg

    here is the command that I use to convert:

    ffmpeg -i input.mts -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 output.avi

    so if the file's name is 1.mts and I want to convert to 1.avi then the command will go like this:

    ffmpeg -i 1.mts -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 1.avi

    the ffmpeg conversion works like a charm. the ffmpeg tool keeps the 1.mts file and puts a 1.avi file right in the same folder. the only drawback to this is that I have to run the command for each individual .mts file (I'm kind of a newb).

    for an experiment, I ran this command on several .mts files in the stream directory:

    ffmpeg -i *.mts -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 *.avi

    what I was hoping for, was that the file 1.mts would be converted to 1.avi and 2.mts would be converted to 2.avi and so on.

    this was the output from the terminal:

    Code:
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM# ls -a
    . 00000.MTS 00002.MTS 00004.MTS 00006.MTS 00008.MTS 00010.MTS 00012.MTS
    .. 00001.MTS 00003.MTS 00005.MTS 00007.MTS 00009.MTS 00011.MTS
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM# clear
    
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM# ffmpeg -i *.mts -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 *.avi
    FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: --extra-version=4:0.5.1-1ubuntu1.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 1 / 52.20. 1
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    libavfilter 0. 4. 0 / 0. 4. 0
    libswscale 0. 7. 1 / 0. 7. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Sep 16 2011 17:04:18, gcc: 4.4.3
    *.mts: no such file or directory
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM# ffmpeg -i *.mts -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 *.avi
    FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: --extra-version=4:0.5.1-1ubuntu1.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 1 / 52.20. 1
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    libavfilter 0. 4. 0 / 0. 4. 0
    libswscale 0. 7. 1 / 0. 7. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Sep 16 2011 17:04:18, gcc: 4.4.3
    *.mts: no such file or directory
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM# ffmpeg -i *.MTS -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 *.avi
    FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration: --extra-version=4:0.5.1-1ubuntu1.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 1 / 52.20. 1
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    libavfilter 0. 4. 0 / 0. 4. 0
    libswscale 0. 7. 1 / 0. 7. 1
    libpostproc 51. 2. 0 / 51. 2. 0
    built on Sep 16 2011 17:04:18, gcc: 4.4.3
    Input #0, mpegts, from '00000.MTS':
    Duration: 00:04:47.80, start: 0.767000, bitrate: 7040 kb/s
    Program 1
    Stream #0.0[0x1011]: Video: h264, yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
    Unable to find a suitable output format for '00001.MTS'
    root@ed-desktop:/home/ed/Desktop/rebate/STREAM#
    if there is any confusion as to what I am trying to do, let me see if I can't explain further. I want to convert ALL the files with one command and have the terminal give the new converted files names as well. the name is not important to me. if 1.mts gets named 1.avi and 2.mts gets named 2.avi and so on, this will be fine. or the terminal can name the files something else. I realize each name has to differ.

    is it possible to have/use such a command?

    thanks for your reply.

  2. #2
    Just Joined!
    Join Date
    Dec 2008
    Posts
    49
    here's the command to convert. however, the end result is every file ending in >.MTS.avi

    for file in *.mts; do ffmpeg -i $file -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 $file.avi; done


    bulk rename

    rename -v 's/\.MTS.avi$/\.avi/' *.MTS.avi

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    ejames's answer is in the form of a Bash script. As you may know, Bash is the shell (program that takes commands and executes them) that most modern Linux users use. Bash scripts allow you to combine commands in numerous new ways.

    For the sake of learning, I've broken up his script a bit and improved it:
    Code:
    for file in *.mts; do
        base=$(basename "$file" .mts)
        ffmpeg -i "$file" -f avi -vcodec dvvideo -s pal -aspect 4:3 -qscale 4 -acodec pcm_s16le -ac 2 "$base.avi"
    done
    This script loops over each file in the current directory ending with .mts. For each such file, it determines the base ("1.mts" -> "1", "input.mts" -> "input", etc.), and then uses variables ($file, $base) in the command in order to modify the command for each file.

    Bash scripting is one of the great strengths of using the commandline. If you're interested in learning more, this is a pretty good beginner's introduction:
    Bash Guide for Beginners

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •