kaegi / alass

"Automatic Language-Agnostic Subtitle Synchronization"
GNU General Public License v3.0
994 stars 52 forks source link

Implement support for --audio-index #14

Closed boolemancer closed 4 years ago

boolemancer commented 4 years ago

Hey, thanks for creating such a useful tool.

I was running into a problem where my reference video had multiple audio streams in different languages, and the alignment would be slightly different depending on the language I was aligning against. I wanted a little more control, so I went ahead and implemented the functionality myself.

This PR adds an --audio-index command line parameter that can be used to specify which audio stream within a video to use as the reference.

I'm somewhat of a novice when it comes to Rust, so apologies in advance if there's anything terribly off.

I couldn't get ffmpeg-sys built in my environment, so I didn't have a chance to try out the ffmpeg_library implemenation, but I think that it should work. ffmpeg_binary works fine.

Dnkhatri commented 4 years ago

@boolemancer Hi is it possible to get the linux binary with your patch. I am running across files where media info shows audio and video as 3rd and 4th stream and alass errors out. I want to see if your patch works for my files.

Video
ID                                       : 3
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=60
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 h 9 min
Bit rate mode                            : Constant
Bit rate                                 : 5 500 kb/s
Maximum bit rate                         : 8 155 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 (30000/1001) FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.089
Stream size                              : 2.69 GiB (95%)
Encoded date                             : UTC 2020-02-12 13:27:07
Tagged date                              : UTC 2020-02-12 13:27:07
Codec configuration box                  : avcC

Audio
ID                                       : 4
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 1 h 9 min
Bit rate mode                            : Constant
Bit rate                                 : 256 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 128 MiB (4%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 2020-02-12 13:27:07
Tagged date                              : UTC 2020-02-12 13:27:07

Other #1
ID                                       : 1
Type                                     : Object description
Format                                   : System
Codec ID                                 : mp4s-01
Duration                                 : 1 ms
Encoded date                             : UTC 2020-02-12 13:27:07
Tagged date                              : UTC 2020-02-12 13:27:07

Other #2
ID                                       : 2
Type                                     : Scene description
Format                                   : System
Codec ID                                 : mp4s-01
Duration                                 : 1 ms
Encoded date                             : UTC 2020-02-12 13:27:07
Tagged date                              : UTC 2020-02-12 13:27:07 
boolemancer commented 4 years ago

alass-cli.zip

Built for 1.41.1-x86_64-unknown-linux-gnu.

kaegi commented 4 years ago

Thanks! I've always wondered whether there is a need to select the audio stream - apparently there is.

Based on this there probably should be a way to print the audio streams (default?), so you don't have to ffprobe them for yourself.

archiif commented 3 years ago

I want to ask a question, what is the index number based on? Is it the same as the index key outputted by ffprobe -print_format json?

boolemancer commented 2 years ago

@archiif

I want to ask a question, what is the index number based on? Is it the same as the index key outputted by ffprobe -print_format json?

Sorry, I don't login often, but to answer your question (assuming you haven't already discovered the answer), yes, the index should match the index printed in ffprobe -print_format json.