Skip to main content
Topic: Trim opus lossless/ no transcode: Any tools for that? (Read 6017 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Trim opus lossless/ no transcode: Any tools for that?

Hi

I'm looking for a tool to trim/ cut opus losslessly, without transcoding.
Is there a tool to opus like mp3DirectCut is to mp3 & aac?

- Olav

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #1
I'm interested in this to :-)

I found this development question about it here.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #2
You can split opus files using mkvmerge's --split option, or using mkvtoolnix-gui. Split files created are in Matroska (.mka) format. You can remux them to ogg/opus using ffmpeg.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #3
You can split opus files using mkvmerge's --split option, or using mkvtoolnix-gui. Split files created are in Matroska (.mka) format. You can remux them to ogg/opus using ffmpeg.
Thanks. Does it do it losslessly?

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #4
Having tested ffmpeg it can definitely split/crop/edit opus files. It appears to do it losslessly.

Here's a (windows) script I created that you can run that requires you to input the start time of the split and then the end time of the split:

Code: [Select]
:: Name:     opus-split-ffmpeg.cmd
:: Purpose:  Configures ffmpeg to losslessly split/crop an opus file
:: Author:   jaybeee @ themixingbowl.org
:: Revision: Jan 2017 - v0.1

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

:: variables begin with v

:: set name of this script without file extension
SET vMe=%~n0

:: set name of the parent directory where this script resides
SET vParent=%~dp0

:: set location of ffmpeg ** CHANGE ME **
SET vffmpeg="C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe"


:: Ask for the user to enter the Start & End times in hours, minutes, seconds
echo ** Enter Start Time of where to begin split in hh mm ss.mmm format when prompted **
SET /p vShh="Start Time (hh): "
SET /p vSmm="Start Time (mm): "
SET /p vSss="Start Time (ss.mmm): "

echo ** Enter End Time of where to end split in hh mm ss.mmm format when prompted **
SET /p vEhh="End Time (hh): "
SET /p vEmm="End Time (mm): "
SET /p vEss="End Time (ss.mmm): "

:: convert Start & End input time to seconds
SET /A vStart=(%vShh%*3600)+(%vSmm%*60)+(%vSss)
SET /A vEnd=(%vEhh%*3600)+(%vEmm%*60)+(%vEss)

:: set this variable to Start Time minus 1 second for the fastest seek time
SET /A vFastSeekStart=%vStart%-1

ECHO ffmpeg will now split the file starting at %vStart% seconds and ending at %vEnd% seconds...
ECHO %vFastSeekStart%

:: call ffmpeg to split/crop (copy) out the audio using -ss (start time) & -to (end time) (-t [duration time]) 
:: time can be: [HH:MM:SS.mmm] eg 01:59:58.123 OR in seconds: [S+.mmm] eg 7198.123
:: Please note: -hide_banner will suppress printing the banner info. Ensure you are running an up to date ffmpeg version
:: -ss %vFastSeekStart%
MKDIR split-opus
FOR %%f IN ("*.opus") DO %vffmpeg% -i "%%f" -ss %vStart% -to %vEnd% -map 0:a -c copy "split-opus\%%~nf.opus"

:: Finish
ECHO Finished opus split

:: pause can be used to view the extraction details
PAUSE

:END
ENDLOCAL
ECHO ON
@EXIT /B 0

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #5
Cool, thanks for the answers guys! Think I'll use ffmpeg, like jaybeee suggested. What a tool, I find new uses for it all the time!

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #6
Yeah, ffmpeg really is a great tool. Glad to have helped.


Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #8
It would be good if it had GUI. Without GUI it's shit

Any solution for cutting OPUS files with GUI?

A GUI prog that opens the file and presents you with a waveform to allow you to find where to add the start-cut and end-cut points would be great (like mp3directcut; mp3 & aac only), but at the moment I do not believe it exists (in lossless editing form).

Therefore, maybe you can try expanding you computer skills and use a cmd line program. I even gave you the (windows) script that you simply double-click and up pops a cmd window for you to enter the start and end times (6 numbers in total); not sure how much more simple you need.


Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #9
There are some ffmpeg GUIs.  Google them, try them and see if they offer your particular use as a menu. 

@jaybeee:  I think most users even need to get explained the "copy this into notepad, save it as opuscutter.bat and then doubleclick it" thing.  Oh, maybe Windows will even need you to manually rename it to .bat afterwards.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #10
On *nix I have this in my mpv input.conf
Code: [Select]
# copy current time to clipboard
Meta+c run "/bin/sh" "-c" "/bin/echo -n ${time-pos/full} | xsel --clipboard --input"
Irc it is in the correct format for feeding directly to ffmpeg. You can probably expand this further to a more auto or a at least semi-auto option.
https://github.com/mpv-player/mpv/issues/4653
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #11
@jaybeee:  I think most users even need to get explained the "copy this into notepad, save it as opuscutter.bat and then doubleclick it" thing.  Oh, maybe Windows will even need you to manually rename it to .bat afterwards.
sadly, you're probably correct... and I'm certainly no techie/coding "guru".

--

I never even thought to look for a GUI when I started out using ffmpeg ~2 years ago. But then I decided to have a play with it and rather enjoyed figuring out the various commands and if I could then create script files to make it easier for me.

Anyway, I found these two (NOT tested by me at all:
1. Avanti GUI - free and allows custom commands to be entered that would in theory allow full use of ffmpeg... but then that negates niga_in_da_block's desire for exclusive GUI functionality. And keeping on topic, it doesn't appear to allow splitting/cutting unless you use the custom command option.
2. myFFmpeg - this is not free (free trail available), but if you were willing to spend a little money on it I dare say it's a winner and would do all you need. If I used ffmpeg everyday I'd seriously consider it. It does appear to allow splitting/cutting (at least for videos, and one would assume audio to).

--

btw the username "niga_in_da_block" is a terrible handle and I would say offensive to many. tbh I'm surprised it even complies with HA's ToS; I would suggest that ToS11 be expanded to include offensive usernames... or create a new one.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #12
Hey jaybeee--I use your excellent script to losslessly trim Opus files, and thank you!

Q:  Is there a way to alter the script to allow your .bat to operate on only a selected Opus file, via the Windows right-click "sendto" menu, instead of every *.opus file in the directory?  I know this is probably an easy change but being a script novice could not find a way myself after some Googling.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #13
Cross platform GUI tool for lossless trimming / cutting of video and audio files using ffmpeg
https://github.com/mifi/lossless-cut
| TAK pMax | QAAC ~ 192 kbps |

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #14
Shinsekai--thank you for the heads up on this!  I have tried LosslessCut today and can verify that it will read and cut Opus audio files.  I replaced the included ffmpeg.exe/ffprobe.exe with the latest release versions from the Zeranoe site and tested the output cut with opusinfo.exe, all seems "as advertised."  Note that GUI interface does not show waveform, you advance through the audio itself by playing it from a simple play/pause control or with a rather rough seek bar but times are shown to the millisecond. Portable but does create a GPU cache folder in User/Appdata/Roaming.  Thanks again for pointing out this tool.

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #15
Here's a (windows) script …

Maybe someone finds it interesting: I have created a script, too. It also controls ffmpeg avconv. It’s Python 2. It can split a media file (including opus) into parts of a given length. Alternatively, it takes a cuesheet (refering to one media file with multiple tracks) and extract the splitpoints from there.

Please note that there is no awesome error checking or the like. Also I don’t know what happens when title or artist string contains by chance e.g. "INDEX" or "TITLE". But to me, with "sweet-tempered" cuesheets, it’s doing its job.

I’m running it under Linux. I don’t know why it shouldn’t run under Win, as long as the shell execution of ffmpeg is similar.

Code: [Select]
#!/usr/bin/env python

"""Script in order to split a media file in smaller parts. Either in equal sized
parts with given length or in induvidual sized parts as stated by a cuesheet."""

import subprocess
import re
import math
from optparse import OptionParser


length_regexp      = 'Duration: (\d{2}):(\d{2}):(\d{2})\.\d+,'
cue_reffile_regexp = 'FILE\s"(.*)"'
cue_index_regexp   = 'INDEX\s01\s(\d{2}):(\d{2}):(\d{2})'
cue_title_regexp   = r'TITLE\s"(.*)"'
re_length      = re.compile(length_regexp)
re_cue_reffile = re.compile(cue_reffile_regexp)
re_cue_index   = re.compile(cue_index_regexp)
re_cue_title   = re.compile(cue_title_regexp, re.MULTILINE)
splitbin = "ffmpeg"
splitbin = "avconv"

def main():

    (filename, split_length) = parse_options()
    if split_length <= 0:
        # Cuesheet operation (individual split lengths)
        cuefile = open (filename, "U")
        cue=cuefile.read ()
        cuefile.close ()
        filename = re_cue_reffile.search(cue).group(1)
        #This finds only the first FILE; there should be only one FILE per cuesheet for this script being and working reasonable.
        cue_tracks="\n".join((cue.split("FILE")[1]).split("\n")[1:])
        cue_tracks=cue_tracks.split("  TRACK ")[1:]
        split_points=[]
        try:
            for t in cue_tracks:
                s=re_cue_index.search(t)
                split_points.append((re_cue_title.search(t).group(1), int(s.group(1))*60 + int(s.group(2)) + float(s.group(3))/75))
        except AttributeError:
        split_points = [(None, int(indx.group(1))*60 + int(indx.group(2)) + float(indx.group(3))/75) for indx in re_cue_index.finditer(cue)]
        equal = False
    else:
        equal = True

    output = subprocess.Popen(splitbin+" -i '"+filename+"' 2>&1 | grep 'Duration'",
                            shell = True,
                            stdout = subprocess.PIPE
                            ).stdout.read()
    print output
    matches = re_length.search(output)
    if matches:
        video_length = int(matches.group(1)) * 3600 + \
                       int(matches.group(2)) * 60 + \
                       int(matches.group(3))
        print "Video length in seconds: "+str(video_length)
    else:
        print "Can't determine video length."
        raise SystemExit

    tmp=filename.split(".")
    filenamebase = ".".join(tmp[:-1])
    filenameext  = tmp[-1]
    if equal:
        split_count = int(math.ceil(video_length/float(split_length)))
        if(split_count == 1):
            print "Video length is less then the target split length."
            raise SystemExit

        split_cmd = splitbin + " -i '"+filename+"' -vcodec copy "
        for n in range(0, split_count):
            split_str = ""
            if n == 0:
                split_start = 0
            else:
                split_start = split_length * n
       
            split_str += " -ss "+str(split_start)+" -t "+str(split_length) + \
                        " '"+filenamebase + "-" + str(n) + "." + filenameext + \
                        "'"
            print "About to run: "+split_cmd+split_str
            output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
                                   subprocess.PIPE).stdout.read()
    else:
        if(len (split_points) <= 1):
            print "There aren't at least two indices in cuefile."
            raise SystemExit

        split_cmd = splitbin + " -i '"+filename+"' -codec copy "  # Enable audio, too
        n = 1
        split_points.append(("",-1))
        split_start = split_points [0][1]
        name        = split_points [0][0]
        for split_end in split_points[1:]:
            try:
                neuname = split_end [0]
            except NameError:
                neuname = ""
            split_end=split_end[1]
            split_str = " -ss "+str(split_start)+((" -t "+str(split_end - split_start)) if split_end != -1 else "") + \
                        " '"+filenamebase + "-" + str(n) + ("-" + name if name!=None else "") + "." + filenameext + \
                        "'"   #Omit -t when last piece will be created
            print "About to run: "+split_cmd+split_str
            output = subprocess.Popen(split_cmd+split_str, shell = True, stdout =
                                   subprocess.PIPE).stdout.read()
            n += 1
            split_start = split_end
            name=neuname



def parse_options():
    parser = OptionParser()   
   
    parser.add_option("-f", "--file",
                        dest = "filename",
                        help = "file to split, for example sample.avi",
                        type = "string",
                        action = "store"
                        )
    parser.add_option("-s", "--split-size",
                        dest = "split_size",
                        help = "split or chunk size in seconds, for example 10; if 0 is given, -f refers to a cuefile",
                        type = "int",
                        action = "store"
                        )
    (options, args) = parser.parse_args()

    if options.filename and (options.split_size != None):

        return (options.filename, options.split_size)

    else:

        parser.print_help()
        raise SystemExit

if __name__ == '__main__':

    try:
        main()
    except Exception, e:
        print "Exception occured running main():"
        print str(e)


The cuesheet is like the one proposed by, AFAIR, CDRWIN.
Code: [Select]
 
FILE "music.opus" WAVE
  TRACK 01 AUDIO
    TITLE "Track title A"
    INDEX 00 00:00:00
    INDEX 01 00:00:20
  TRACK 02 AUDIO
    TITLE "Track title B"
    INDEX 01 05:43:21
  …


HTH – Peter

Re: Trim opus lossless/ no transcode: Any tools for that?

Reply #16
Shinsekai--thank you for the heads up on this!  I have tried LosslessCut today and can verify that it will read and cut Opus audio files.  I replaced the included ffmpeg.exe/ffprobe.exe with the latest release versions from the Zeranoe site and tested the output cut with opusinfo.exe, all seems "as advertised."  Note that GUI interface does not show waveform, you advance through the audio itself by playing it from a simple play/pause control or with a rather rough seek bar but times are shown to the millisecond. Portable but does create a GPU cache folder in User/Appdata/Roaming.  Thanks again for pointing out this tool.

Just updating my old post, LosslessCut (now version 1.10) does include back/forward buttons that use an extremely small increment (milliseconds) to allow for precise cueing, not just a seek bar/pause.  The new version also now includes a very recent version of the ffmpeg/ffprobe executables (3.4.2) which are built with opuslib 1.2.1, no need to download separately.  Still at:
https://github.com/mifi/lossless-cut/releases

Thanks again to Shinsekai for the original pointer.

 
SimplePortal 1.0.0 RC1 © 2008-2018