harryjackson / ffmpeg_split

Split an ffmpeg file by chapter
Apache License 2.0
56 stars 20 forks source link

Doesn't seem to work... Errors out: invalid syntax, line 17 #5

Closed iconoclasthero closed 6 months ago

iconoclasthero commented 3 years ago

It would definitely help if you included the command syntax so maybe the problem is that I had to guess...maybe it is a dependency issue?

$ ls
 split_ffmpeg2.py           'Time_on_Two_Crosses_The_Collected_Writings_of_Bayard_Rustin_(1215).jpg'
 split_ffmpeg.py             Time_on_Two_Crosses_The_Collected_Writings_of_Bayard_Rustin-chapters.json
'Time on Two Crosses.opus'   Time_on_Two_Crosses_The_Collected_Writings_of_Bayard_Rustin-LC_64_22050_stereo.aax

$ python3 split_ffmpeg.py Time\ on\ Two\ Crosses.opus
  File "split_ffmpeg.py", line 17
    except CalledProcessError, e:
                             ^
SyntaxError: invalid syntax

$ python3 split_ffmpeg.py 
  File "split_ffmpeg.py", line 17
    except CalledProcessError, e:
                             ^
SyntaxError: invalid syntax

$ python3 split_ffmpeg.py *
  File "split_ffmpeg.py", line 17
    except CalledProcessError, e:
                             ^
SyntaxError: invalid syntax

$ mediainfo Time\ on\ Two\ Crosses.opus 
General
Complete name                            : Time on Two Crosses.opus
Format                                   : Ogg
File size                                : 104 MiB
Duration                                 : 14 h 0 min
Overall bit rate                         : 17.4 kb/s
Album                                    : Time on Two Crosses (Unabridged)
Album/Performer                          : Bayard Rustin, Devon W. Carbado, Donald Weise
Track name                               : Time on Two Crosses: The Collected Writings of Bayard Rustin
Performer                                : Bayard Rustin, Devon W. Carbado, Donald Weise
Genre                                    : Audiobook
Description                              : Bayard Rustin (1912 to1987), the famed openly gay African American organizer, taught Martin Luther King Jr. strategies of nonviolence during the Montgomery Bus Boycott....
Recorded date                            : 2012
Writing application                      : Lavc59.4.101 libopus
Copyright                                : ©2011 Cleis Press (P)2012 Audible, Inc.
creation_time                            : 2021-08-28T18:34:55.000000Z
handler_name                             : Apple Sound Media Handler
vendor_id                                : [0][0][0][0]
major_brand                              : aax 
minor_version                            : 1
compatible_brands                        : aax M4B mp42isom

Audio
ID                                       : 842047308 (0x32309F4C)
Format                                   : Opus
Duration                                 : 14 h 0 min
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 24.0 kHz
Compression mode                         : Lossy
Writing library                          : Lavf59.4.101
Language                                 : English

Menu
00:00:00.000                             : Chapter 1
00:00:15.093                             : Chapter 2
01:28:17.215                             : Chapter 3
01:35:27.923                             : Chapter 4
01:46:57.556                             : Chapter 5
01:52:12.394                             : Chapter 6
02:22:39.550                             : Chapter 7
02:29:14.450                             : Chapter 8
03:26:09.270                             : Chapter 9
03:41:32.984                             : Chapter 10
04:48:25.857                             : Chapter 11
05:06:05.498                             : Chapter 12
05:17:13.165                             : Chapter 13
05:21:13.562                             : Chapter 14
05:28:57.822                             : Chapter 15
06:04:15.318                             : Chapter 16
06:24:54.381                             : Chapter 17
06:42:51.276                             : Chapter 18
06:50:10.808                             : Chapter 19
07:12:08.959                             : Chapter 20
07:16:45.344                             : Chapter 21
07:36:52.410                             : Chapter 22
07:58:42.784                             : Chapter 23
08:02:00.500                             : Chapter 24
08:05:50.424                             : Chapter 25
08:28:11.912                             : Chapter 26
08:42:31.515                             : Chapter 27
08:53:02.051                             : Chapter 28
08:57:36.464                             : Chapter 29
09:03:54.603                             : Chapter 30
09:09:24.605                             : Chapter 31
10:00:48.283                             : Chapter 32
10:05:11.226                             : Chapter 33
10:47:27.216                             : Chapter 34
10:52:30.587                             : Chapter 35
11:06:17.378                             : Chapter 36
11:10:42.946                             : Chapter 37
11:17:03.939                             : Chapter 38
11:22:01.898                             : Chapter 39
11:25:20.521                             : Chapter 40
11:31:36.288                             : Chapter 41
11:55:29.424                             : Chapter 42
12:00:18.233                             : Chapter 43
12:07:28.174                             : Chapter 44
12:15:10.601                             : Chapter 45
12:31:48.502                             : Chapter 46
12:40:16.880                             : Chapter 47
13:01:10.804                             : Chapter 48
13:13:21.325                             : Chapter 49
13:54:31.092                             : Chapter 50
13:59:32.791                             : Chapter 51
drgeoffb commented 2 years ago

I found, and used, this script today (thank-you kindly, @harryjackson, this works beautifully!)

It errored for me when I used a command line similar to yours, @iconoclasthero.

When I ran it with python 2 and the -f command line option, all good. I also had minor dramas with the dir it wrote output to. prefix the filename with a path helped. (ubuntu 20.04, python 2.7.18)

bad examples:

python3 split_ffmpeg.py myfile.mp4 - nope (errors) python2 split_ffmpeg.py myfile.mp4 - nope (errors similar to yours, I think, didn't make a note) python2 split_ffmpeg.py -f myfile.mp4 - nope - write error, can't access /myfile dir

working example:

python2 split_ffmpeg.py -f ./myfile.mp4 - yes - works nicely

I also tweaked lines 87-92 to change the ffmpeg command line to add some encoding, but I think that's unrelated to issues you're having / I had.

for interest, my workflow:

  1. rip dvd using old faithful 'dvd decrypter' (on windows)
  2. convert/encode (as pass-through as possible) to m4v using handbrake with chapters -> create chapter markers enabled (windows)
  3. use this script - split_ffmpeg.py - to split the m4v files to individual chapters (on linux, my go to wherever possible, I didn't try this script on windows but it'll probably work fine if dependencies are all OK)

hth,

G