VideoHelp Forum




+ Reply to Thread
Results 1 to 13 of 13
  1. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    Is there a tool to batch remux a bunch (over 1000) of AVCHD (m2ts) clips? I simply want to replace the audio stream for each clip. The original AVCHD clips (from a Sony handycam) and the new audio clips (AC3) have the same file name. TSMuxer will do the remux, but one at a time would be impractical. Thanks.

    wwaag
    Quote Quote  
  2. You can do it with ffmpeg batch processing.

    This example will copy the video, copy the new ac3 track, and create a new .mts with the name "new" appended to it. The original files won't be overwritten. You can change the directories if you want by specifying a path

    e.g from commandline

    Code:
    for %a in ("*.mts") do ffmpeg -i "%~na.mts" -i "%~na.ac3" -c copy -map 0:0 -map 1:0 "%~na.new.mts"
    or batch file, just replace the "%" with "%%"

    Code:
    for %%a in ("*.mts") do ffmpeg -i "%%~na.mts" -i "%%~na.ac3" -c copy -map 0:0 -map 1:0 "%%~na.new.mts"
    pause
    Quote Quote  
  3. I should mention this method doesn't keep the original file metadata (e.g. some cameras have GPS, date, time etc.. )

    So for that and other reasons - you should always backup your original camera files in their own original folder structure if they are even remotely semi-important. (The original folder structure is necessary for NLE's to do seamless gaps between filespanned clips)
    Quote Quote  
  4. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    Thanks for the quick reply. Have not used Ffmpeg before nor am I familiar with using command lines, so please bear with me. I downloaded and installed the latest 64bit version. Using the command line you provided, I changed the MTS to m2ts and the ac3 to wav (I haven't yet converted all my wav files to ac3). In a test directory, it did successfully execute and create new files with the .new extension. However, the new files had only the video stream--no audio. Mediainfo shows only a video track. Any ideas? Thanks.

    wwaag
    Quote Quote  
  5. Originally Posted by wwaag View Post
    Thanks for the quick reply. Have not used Ffmpeg before nor am I familiar with using command lines, so please bear with me. I downloaded and installed the latest 64bit version. Using the command line you provided, I changed the MTS to m2ts and the ac3 to wav (I haven't yet converted all my wav files to ac3). In a test directory, it did successfully execute and create new files with the .new extension. However, the new files had only the video stream--no audio. Mediainfo shows only a video track. Any ideas? Thanks.
    yep - ffmpeg has problems muxing uncompressed pcm wav into transport streams . That's probably why

    So batch encode the wav files to ac3 first, and use the original commandline, but with m2ts instead of mts (if your files are m2ts)
    Quote Quote  
  6. Here is an example for batch encoding wav => AC3 . The bitrate is 384k, you can change that value if you want. The filename.ac3 will be derived from filename.wav (no "new" appended to the name) - hopefully filename.wav matches with the corresponding filename.m2ts that it's supposed to match up with, that way filename.ac3 will match

    Code:
    for %a in ("*.wav") do ffmpeg -i "%a" -acodec ac3 -b:a 384k "%~na.ac3"
    Quote Quote  
  7. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    It works. Converted my wav files to ac3 and tried again. Thanks so much. Just curious--the new files are larger than the original (e.g. 215mb vs 226mb). The ac3 file was only 2mb. Is this normal?

    wwaag
    Quote Quote  
  8. Originally Posted by wwaag View Post
    It works. Converted my wav files to ac3 and tried again. Thanks so much. Just curious--the new files are larger than the original (e.g. 215mb vs 226mb). The ac3 file was only 2mb. Is this normal?

    wwaag

    It might be; what was the bitrate of the audio before and after?

    Use mediainfo (view=>text) on the original file, and the "audio-replaced" file , copy & paste the text back here please

    There are slightly different types of transport streams. For example, .m2ts have extra bytes as TC data, and others are sometimes padded
    Quote Quote  
  9. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    Here are the two media info panes. I also notice there is a 17 msec delay in the new file. Can this be changed?

    Original File--------------------------------------

    General
    ID : 0 (0x0)
    Complete name : F:\Oregon 2013 March\Video Clips\Temp\20130328120742.m2ts
    Format : BDAV
    Format/Info : Blu-ray Video
    File size : 210 MiB
    Duration : 1mn 6s
    Overall bit rate mode : Variable
    Overall bit rate : 26.5 Mbps
    Maximum Overall bit rate : 28.0 Mbps

    Video
    ID : 4113 (0x1011)
    Menu ID : 1 (0x1)
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.2
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Format settings, GOP : M=1, N=15
    Codec ID : 27
    Duration : 1mn 6s
    Bit rate mode : Variable
    Bit rate : 25.2 Mbps
    Maximum bit rate : 26.0 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16:9
    Frame rate : 59.940 fps
    Color space : YUV
    Chroma subsampling : 4:2:0
    Bit depth : 8 bits
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.203
    Stream size : 200 MiB (95%)

    Audio
    ID : 4352 (0x1100)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Codec ID : 129
    Duration : 1mn 6s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : Front: L R
    Sampling rate : 48.0 KHz
    Bit depth : 16 bits
    Compression mode : Lossy
    Stream size : 2.03 MiB (1%)

    Text
    ID : 4608 (0x1200)
    Menu ID : 1 (0x1)
    Format : PGS
    Codec ID : 144
    Duration : 1mn 6s

    New File------------------------------------------

    General
    ID : 1 (0x1)
    Complete name : F:\Oregon 2013 March\Video Clips\Temp\20130328120742.new.m2ts
    Format : BDAV
    Format/Info : Blu-ray Video
    File size : 221 MiB
    Duration : 1mn 6s
    Overall bit rate mode : Variable
    Overall bit rate : 27.8 Mbps

    Video
    ID : 256 (0x100)
    Menu ID : 1 (0x1)
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : High@L4.2
    Format settings, CABAC : Yes
    Format settings, ReFrames : 2 frames
    Format settings, GOP : M=1, N=15
    Codec ID : 27
    Duration : 1mn 6s
    Bit rate mode : Variable
    Bit rate : 26.0 Mbps
    Width : 1 920 pixels
    Height : 1 080 pixels
    Display aspect ratio : 16:9
    Frame rate : 59.940 fps
    Color space : YUV
    Chroma subsampling : 4:2:0
    Bit depth : 8 bits
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.209
    Stream size : 210 MiB (95%)

    Audio
    ID : 257 (0x101)
    Menu ID : 1 (0x1)
    Format : AC-3
    Format/Info : Audio Coding 3
    Mode extension : CM (complete main)
    Codec ID : 129
    Duration : 1mn 6s
    Bit rate mode : Constant
    Bit rate : 256 Kbps
    Channel(s) : 2 channels
    Channel positions : Front: L R
    Sampling rate : 48.0 KHz
    Bit depth : 16 bits
    Compression mode : Lossy
    Delay relative to video : -17ms
    Stream size : 2.03 MiB (1%)

    Menu
    ID : 4096 (0x1000)
    Menu ID : 1 (0x1)
    Duration : 1mn 6s
    List : 256 (0x100) (AVC) / 257 (0x101) (AC-3)
    Service name : Service01
    Service provider : FFmpeg
    Service type : digital television
    Quote Quote  
  10. The filesize can change depending on the -muxrate you set . It's basically padding the transport stream. It's tricky business, and you can end up with buffer underflows or overflows if you're not careful. It's automatically set so I wouldn't touch it in ffmpeg. If you demux both those files (e.g. with tsmuxer or ffmpeg), you will notice the video stream will be the same size for both (despite what mediainfo says - it only reads the header, and not accurate for many things) . ie. the extra size is just in the container . It's likely the Sony values are different than the ones used by ffmpeg



    Is the delay real ? Note mediainfo misreports many things, and 17ms is hardly perceptible

    for the delay, you can use -itsoffset in ffmpeg, but I think it only works on video relative to audio. And it might be different for each file

    Code:
    ‘-itsoffset offset (input)’ Set the input time offset in seconds. [-]hh:mm:ss[.xxx] syntax is also supported. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by offset seconds.
    Last edited by poisondeathray; 26th Jul 2013 at 21:25.
    Quote Quote  
  11. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    Using some test files in Vegas and viewing their waveforms, I confirmed that there is a 10 msec. delay being introduced during muxing which is the same value that encoders such as Main Concept and Procoder also introduce. Using the itsoffset command for the ac3 file, I was able to correct for the delay so that the waveforms of the original and remuxed files are the same. I'm happy!

    Here is the command line:
    Code:
    for %a in ("*.m2ts") do ffmpeg -i "%~na.m2ts" -itsoffset 00:00:00.010 -i "%~na.ac3" -c copy -map 0:0 -map 1:0 "%~na.new.m2ts"
    One final question. Can the wav to ac3 command line be incorporated into the batch remux command line? I'm sure it can, but I'm not quite sure how to proceed. Thanks so much.

    wwaag
    Last edited by wwaag; 28th Jul 2013 at 13:44.
    Quote Quote  
  12. Originally Posted by wwaag View Post
    Can the wav to ac3 command line be incorporated into the batch remux command line?
    separate the 2 commands by "&&" (without the quotes) for sequential processing (1st command is executed before the 2nd), or use a batch file
    Quote Quote  
  13. Member wwaag's Avatar
    Join Date
    Jan 2002
    Location
    Olympic Peninsula, US
    Search Comp PM
    One additional question. Is there a way to also include a PGS text stream in addition to the video and audio? Thanks.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!