Video Editing

First you should install some video related packages:

apt-get install libav-tools vlc 

optional:

apt-get install mediainfo

Convert

Some Cameras divide the recording in several pieces. Then you first should concatenate with cat FILE1.MTS FILE2.MTS FILEx.MTS > OUTPUT.MTS Convert MTS files with AVCHD video format and ac3 sound format to MP4 and aac format.

#!/bin/bash
# put here original size of movie:
SIZE=1920x1080
avconv-copy() {
   avconv -i ${1}.MTS -c:a copy -c:v copy ${1}.mp4
}
case "$1" in
(avconv)
   avconv-copy $2
   ;;
(avconv-resize)
   avconv -i ${2}.mp4 -s $SIZE -strict experimental ${2}_$SIZE.mp4
   ;;
(avconv-full)
   avconv-copy $2
   avconv -i ${2}.mp4 -s $SIZE -strict experimental ${2}_$SIZE.mp4
   ;;
(*)
   echo "Usage: $0 avconv|avconv-resize|avconv-full <file> # ohne Endung .MTS angeben "
   ;;
esac

Handbrake

Tool in ubuntu packages from https://handbrake.fr/ Intermediate format on Linux is MKV because this is the most free video package

xmodulo

….

CLI Tools: avconv, mp4box, ffmpeg

avconv

avconv -i C00006.MTS -c:a copy -c:v copy -y Canon-00006.MTS.mp4
ffprobe C00006.MTS.mp4

or

avconv -i ${1}.MTS -c:a copy -c:v copy ${1}.mp4

Tools seen with „dpkg -l“

libav-tools - Multimedia player, server, encoder and transcoder winff - graphical video and audio batch converter using ffmpeg or avconv

mp4box

apt-get install gpac

http://gpac.wp.mines-telecom.fr/mp4box/

MP4Box -add input.h264:fps=29.97 -new output.mp4
/Applications/Free AVCHD to Mov.app/Contents/Resources/bin/com.geranium-soft.convert \
  -i /path/to/C00003.MTS \
  -map 0:0 -map 0:1 -c:a libfaac -vol 256 -b:a 128k -c:v copy \
  -sn -movflags faststart -threads 0 -pix_fmt yuv420p -y \
  /path/to/140710_C00003.mov

ffmpeg

obsolete use avconv instead

This package is very common but discontinued.

ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
  -vcodec copy -an 140612_Canon-00000.MTS.h264
ffmpeg -i 140612_Canon-00000.MTS -t 60 -y \
  -vn -acodec libfaac -ab 128k 140612_Canon-00000.MTS.aac
mp4box -add 140612_C00000.MTS.h264:fps=29.97 \
  -add 140612_C00000.MTS.aac \
  -new 140612_C00000.MTS.mp4

Adding: -r 29.97 option

Professor Sparkles gave me an advice to add „-r 29.97“. I tried that:

ffmpeg -i 140612_Canon-00001.MTS -t 60 -r 29.97 -y -vcodec copy -acodec libfaac -ab 128k

# see: http://video.stackexchange.com/questions/12156/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v

http://stackoverflow.com/questions/24720063/how-can-i-convert-mts-file-avchd-to-mp4-by-ffmpeg-without-re-encoding-h264-v

mencoder

Question: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.

I'll start with the end:

mencoder infile.mts -demuxer lavf -oac copy -ovc copy -of lavf=mp4 -o outfile.mp4

and now to explain myself:

AVCHD (MTS) is basically a container format for MPEG4-AVC video and AC-3 Audio. It's commonly found on modern camcorders. I have pulled files off a Sony Camcorder, which records in 1080i@50Hz. It seems there are timestamp problems, and both the even and odd fields are stamped with the same time, and not 1/50th of a second apart as you'd expect. This currently breaks ffmpeg (0.6~svn20100711), and the mencoder (SVN-r31722) internal demuxer doesn't like it either. The libavformat (lavf 0.6~svn20100711) demuxer/muxer seems to handle it, so that's what we'll use.

If you run 'mediainfo' over an MTS file, you'll see something like this:

    General
    ID                               : 0
    Complete name                    : infile.mts
    Format                           : BDAV
    Format/Info                      : Blu-ray Video
    File size                        : 62.6 MiB
    Duration                         : 56s 72ms
    Overall bit rate                 : 9 364 Kbps
    Maximum Overall bit rate         : 18.0 Mbps

    Video
    ID                               : 4113 (0x1011)
    Menu ID                          : 1 (0x1)
    Format                           : AVC
    Format/Info                      : Advanced Video Codec
    Format profile                   : High@L4.0
    Format settings, CABAC           : Yes
    Format settings, ReFrames        : 2 frames
    Duration                         : 56s 0ms
    Bit rate                         : 8 726 Kbps
    Width                            : 1 440 pixels
    Height                           : 1 080 pixels
    Display aspect ratio             : 16:9
    Frame rate                       : 25.000 fps
    Resolution                       : 8 bits
    Colorimetry                      : 4:2:0
    Scan type                        : Interlaced
    Scan order                       : Top Field First
    Bits/(Pixel*Frame)               : 0.224
    Stream size                      : 58.3 MiB (93%)

    Audio
    ID                               : 4352 (0x1100)
    Menu ID                          : 1 (0x1)
    Format                           : AC-3
    Format/Info                      : Audio Coding 3
    Duration                         : 56s 128ms
    Bit rate mode                    : Constant
    Bit rate                         : 256 Kbps
    Channel(s)                       : 2 channels
    Channel positions                : Front: L R
    Sampling rate                    : 48.0 KHz
    Video delay                      : -80ms
    Stream size                      : 1.71 MiB (3%)

    Text
    ID                               : 4608 (0x1200)
    Menu ID                          : 1 (0x1)
    Format                           : PGS
    Duration                         : 55s 575ms
    Video delay                      : -80ms

Once you run it through the above command, the resultant container will look like this. The audio/video codec details will be the same because it's a straight (lossless) copy. Also note that the headers have been corrected from 25i to 50i.

    General
    Complete name                    : outfile.mp4
    Format                           : MPEG-4
    Format profile                   : Base Media
    Codec ID                         : isom
    File size                        : 58.7 MiB
    Duration                         : 56s 160ms
    Overall bit rate                 : 8 761 Kbps
    Writing application              : Lavf52.73.0

    Video
    ID                               : 1
    Format                           : AVC
    Format/Info                      : Advanced Video Codec
    Format profile                   : High@L4.0
    Format settings, CABAC           : Yes
    Format settings, ReFrames        : 2 frames
    Format_Settings_FrameMode        : Frame tripling
    Codec ID                         : avc1
    Codec ID/Info                    : Advanced Video Coding
    Duration                         : 56s 140ms
    Bit rate mode                    : Variable
    Bit rate                         : 8 504 Kbps
    Width                            : 1 440 pixels
    Height                           : 1 080 pixels
    Display aspect ratio             : 4:3
    Original display aspect ratio    : 16:9
    Frame rate mode                  : Constant
    Frame rate                       : 50.000 fps
    Original frame rate              : 8.333 fps
    Resolution                       : 8 bits
    Colorimetry                      : 4:2:0
    Scan type                        : Interlaced
    Scan order                       : Top Field First
    Bits/(Pixel*Frame)               : 0.109
    Stream size                      : 56.9 MiB (97%)

    Audio
    ID                               : 2
    Format                           : AC-3
    Format/Info                      : Audio Coding 3
    Codec ID                         : ac-3
    Duration                         : 56s 160ms
    Bit rate mode                    : Constant
    Bit rate                         : 256 Kbps
    Channel(s)                       : 2 channels
    Channel positions                : Front: L R
    Sampling rate                    : 48.0 KHz
    Resolution                       : 16 bits
    Stream size                      : 1.71 MiB (3%)

Note that the final video will still be interlaced. Removing the interlacing requires re-encoding. (This was tested on 10.04 with the VDPAU team's cutting-edge-multimedia PPA installed.)

by pHr34kY; September 11th, 2010 at 11:55 AM. Advanced reply September 14th, 2010 #2

I want to do this on files from a canon hg-21. Here is my output from mediainfo:

    General
    ID : 0
    Complete name : 00069.MTS
    Format : BDAV
    Format/Info : BluRay Video
    File size : 272 MiB
    Duration : 1mn 36s
    Overall bit rate : 23.8 Mbps
    Maximum Overall bit rate : 24.0 Mbps

    Video
    ID : 4113 (0x1011)
    Menu ID : 1 (0x1)
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.0
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Duration : 1mn 35s
    Bit rate : 22.6 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16/9
    Frame rate : 29.970 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Interlaced
    Scan order : Top Field First
    Bits/(Pixel*Frame) : 0.363

    Audio
    ID : 4352 (0x1100)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Duration : 1mn 36s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : L R
    Sampling rate : 48.0 KHz
    Video delay : -66ms
  This is after conversion:
    General
    Complete name : RyanFreakout.mp4
    Format : MPEG-4
    Format profile : Base Media
    Codec ID : isom
    File size : 260 MiB
    Duration : 1mn 36s
    Overall bit rate : 22.7 Mbps
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00
    Writing application : Lavf52.31.0

    Video
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.0
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Codec ID : avc1
    Codec ID/Info : Advanced Video Coding
    Duration : 1mn 36s
    Bit rate mode : Variable
    Bit rate : 22.4 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16/9
    Frame rate mode : Constant
    Frame rate : 59.940 fps
    Original frame rate : 29.970 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.181
    Stream size : 257 MiB (99%)
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00

    Audio
    Format : AC-3
    Format/Info : Audio Coding 3
    Codec ID : ac-3
    Duration : 1mn 36s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : L R
    Sampling rate : 48.0 KHz
    Resolution : 16 bits
    Stream size : 2.93 MiB (1%)
    Encoded date : UTC 1970-01-01 00:00:00
    Tagged date : UTC 1970-01-01 00:00:00

Does everything look right? The playback on .mp4 is still obviously interlaced but it seems to be worse than before. When usually I get better playback. Previously, I had always used Adobe Media Encoder on Windows (deinterlaces the file). Can I deinterlace this file (reencode with mencoder)? Are my settings right for converting this like yours?

Advanced reply
September 17th, 2010 #3
Looking to convert MTS into a usable format too …

WinFF gives this error when trying to convert MTS files:

Input #0, mpegts, from '/home/admin1/Pictures/AVCHD/BDMV/STREAM/00000.MTS':
Duration: 00:04:56.32, start: 1.000067, bitrate: 17173 kb/s
Program 1
Stream #0.0[0x1011]: Video: h264, yuv420p, 1920×1080 [PAR 1:1 DAR 16:9], 59.94 tbr, 90k tbn, 59.94 tbc
Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
Unknown encoder 'libmp3lame'
Press Enter to Continue …

Advanced reply
September 17th, 2010 #4
Re: How to convert AVCHD (MTS/M2TS) to MP4 losslessly.>Y
Unknown encoder 'libmp3lame'
Looks like your copy of FFmpeg has not been compiled for mp3 encoding,
have a look here for the fix:
HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoders in FFmpeg
http://ubuntuforums.org/showthread.php?t=1117283

QR-Code
QR-Code systemverwaltung:user_info:howto:videoedit (erstellt für aktuelle Seite)