Skip to content

Commit e6fc536

Browse files
committed
Fix: Handling with indexes
1 parent 3e00123 commit e6fc536

File tree

4 files changed

+40
-38
lines changed

4 files changed

+40
-38
lines changed

composeApp/src/desktopMain/kotlin/edneyosf/edconv/features/converter/ConverterViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ class ConverterViewModel(private val config: EdConfig, private val process: EdPr
266266
sampleRate = sampleRate?.value,
267267
channels = channels?.value,
268268
filterVideo = filterVideo,
269-
custom = customChannelsArgs,
269+
customVideo = null,
270+
customAudio = customChannelsArgs,
270271
noSubtitle = noSubtitle,
271272
noChapters = noChapters,
272273
noMetadata = noMetadata

composeApp/src/desktopMain/kotlin/edneyosf/edconv/features/converter/states/ConverterState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ data class ConverterState(
1010
val type: MediaType? = null,
1111
val output: Pair<String, String>? = null,
1212
val queueSize: Int = 0,
13-
val indexAudio: Int? = 0,
14-
val indexVideo: Int? = 0,
13+
val indexAudio: Int? = -1,
14+
val indexVideo: Int? = -1,
1515
val encoderAudio: Encoder? = null,
1616
val encoderVideo: Encoder? = null,
1717
val compressionTypeAudio: CompressionType? = null,

composeApp/src/desktopMain/kotlin/edneyosf/edconv/features/converter/ui/ConverterScreen.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ private fun ConverterState.Content(command: String, event: ConverterEvent) {
101101
horizontalArrangement = Arrangement.spacedBy(space = dimens.xl),
102102
verticalAlignment = Alignment.CenterVertically
103103
) {
104-
IndexInput(
105-
value = indexVideo?.takeIf { it >= 0 },
106-
max = input.videos.size,
107-
enabled = indexVideo != null && indexVideo >= 0,
108-
onValueChange = event::setIndexVideo,
109-
onClick = { event.setIndexVideo(0) }
110-
)
111104
if(input.videos.size > 1) {
105+
IndexInput(
106+
value = indexVideo?.takeIf { it >= 0 },
107+
max = input.videos.size,
108+
enabled = indexVideo != null && indexVideo >= 0,
109+
onValueChange = event::setIndexVideo,
110+
onClick = { event.setIndexVideo(0) }
111+
)
112112
AllIndexesInput(
113113
enabled = indexVideo == null,
114114
onClick = { event.setIndexVideo(null) }
@@ -195,13 +195,15 @@ private fun ConverterState.Content(command: String, event: ConverterEvent) {
195195
horizontalArrangement = Arrangement.spacedBy(space = dimens.xl),
196196
verticalAlignment = Alignment.CenterVertically
197197
) {
198-
IndexInput(
199-
value = indexAudio?.takeIf { it >= 0 },
200-
max = input.audios.size,
201-
enabled = indexAudio != null && indexAudio >= 0,
202-
onValueChange = event::setIndexAudio,
203-
onClick = { event.setIndexAudio(0) }
204-
)
198+
if(input.audios.size > 1) {
199+
IndexInput(
200+
value = indexAudio?.takeIf { it >= 0 },
201+
max = input.audios.size,
202+
enabled = indexAudio != null && indexAudio >= 0,
203+
onValueChange = event::setIndexAudio,
204+
onClick = { event.setIndexAudio(0) }
205+
)
206+
}
205207
if(input.audios.size > 1 && indexVideo != -1) {
206208
AllIndexesInput(
207209
enabled = indexAudio == null,

composeApp/src/desktopMain/kotlin/edneyosf/edconv/ffmpeg/ffmpeg/FFmpeg.kt

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import edneyosf.edconv.ffmpeg.ffmpeg.extensions.addCmd
77
class FFmpeg private constructor(
88
val logLevel: String,
99
val mediaType: MediaType,
10-
val indexVideo: Int? = null,
11-
val indexAudio: Int? = null,
10+
val indexVideo: Int? = -1,
11+
val indexAudio: Int? = -1,
1212
val encoderAudio: String? = null,
1313
val encoderVideo: String? = null,
1414
var bitrateAudio: String? = null,
@@ -25,7 +25,8 @@ class FFmpeg private constructor(
2525
val noSubtitle: Boolean = false,
2626
val noMetadata: Boolean = false,
2727
val noChapters: Boolean = false,
28-
val custom: List<String>? = null,
28+
val customAudio: List<String>? = null,
29+
val customVideo: List<String>? = null,
2930
val uncompressedVideo: Boolean = false,
3031
val uncompressedAudio: Boolean = false
3132
) {
@@ -51,7 +52,7 @@ class FFmpeg private constructor(
5152
filterAudio = filter,
5253
noMetadata = noMetadata,
5354
noChapters = noChapters,
54-
custom = custom
55+
customAudio = custom
5556
)
5657
}
5758

@@ -61,8 +62,8 @@ class FFmpeg private constructor(
6162
bitrateControlVideo: Int?, bitrateControlAudio: Int?, bitrateVideo: String?, bitrateAudio: String?,
6263
profileVideo: String? = null, pixelFormat: String? = null, filterVideo: String? = null,
6364
filterAudio: String? = null, sampleRate: String? = null, channels: String? = null,
64-
noSubtitle: Boolean = false, noMetadata: Boolean = false, custom: List<String>? = null,
65-
noChapters: Boolean = false
65+
noSubtitle: Boolean = false, noMetadata: Boolean = false, customVideo: List<String>? = null,
66+
customAudio: List<String>? = null, noChapters: Boolean = false
6667
): FFmpeg {
6768

6869
return FFmpeg(
@@ -88,67 +89,65 @@ class FFmpeg private constructor(
8889
noSubtitle = noSubtitle,
8990
noMetadata = noMetadata,
9091
noChapters = noChapters,
91-
custom = custom
92+
customAudio = customAudio,
93+
customVideo = customVideo
9294
)
9395
}
9496
}
9597

9698
fun build(): String {
9799
val data = mutableListOf<String>()
100+
val noAudio = indexAudio == -1
98101

99102
data.addCmd(param = FFmpegArgs.LOG_LEVEL, value = logLevel)
100103
data.add(FFmpegArgs.STATS)
104+
101105
if(isVideo() && !noSubtitle) data.addCmd(param = FFmpegArgs.MAP, value = "0:s?")
102106

103107
if(indexVideo != -1) {
104108
data.addCmd(param = FFmpegArgs.MAP, value = if(indexVideo == null) "0:v" else "0:v:$indexVideo")
105109

106110
if(!uncompressedVideo) {
111+
data.addCmd(param = FFmpegArgs.FILTER_VIDEO, value = filterVideo)
107112
data.addCmd(param = FFmpegArgs.ENCODER_VIDEO, value = encoderVideo)
108113
data.addCmd(param = FFmpegArgs.BITRATE_VIDEO, value = bitrateVideo)
109114
data.addCmd(param = FFmpegArgs.PRESET, value = presetVideo)
110115
data.addCmd(param = FFmpegArgs.CRF, value = bitrateControlVideo?.toString())
111116
data.addCmd(param = FFmpegArgs.PROFILE_VIDEO, value = profileVideo)
112117
data.addCmd(param = FFmpegArgs.PIXEL_FORMAT, value = pixelFormat)
113-
data.addCmd(param = FFmpegArgs.FILTER_VIDEO, value = filterVideo)
118+
customVideo?.let { data.addAll(customVideo) }
114119
}
115120
else {
116121
data.addCmd(param = FFmpegArgs.ENCODER_VIDEO, value = FFmpegArgs.COPY)
117122
}
118123
}
119-
else {
120-
data.addCmd(param = FFmpegArgs.MAP, value = "-0:v")
121-
}
122124

123125
if(indexAudio != -1) {
124126
data.addCmd(param = FFmpegArgs.MAP, value = if(indexAudio == null) "0:a" else "0:a:$indexAudio")
125127

126128
if(!uncompressedAudio) {
129+
data.addCmd(param = FFmpegArgs.FILTER_AUDIO, value = filterAudio)
127130
data.addCmd(param = FFmpegArgs.ENCODER_AUDIO, value = encoderAudio)
128131
data.addCmd(param = FFmpegArgs.BITRATE_AUDIO, value = bitrateAudio)
129132
data.addCmd(param = FFmpegArgs.VBR, value = bitrateControlAudio?.toString())
130133
data.addCmd(param = FFmpegArgs.SAMPLE_RATE, value = sampleRate)
131134
data.addCmd(param = FFmpegArgs.CHANNELS, value = channels)
132-
data.addCmd(param = FFmpegArgs.FILTER_AUDIO, value = filterAudio)
135+
customAudio?.let { data.addAll(customAudio) }
133136
}
134137
else {
135138
data.addCmd(param = FFmpegArgs.ENCODER_AUDIO, value = FFmpegArgs.COPY)
136139
}
137140
}
138-
else {
139-
data.addCmd(param = FFmpegArgs.MAP, value = "-0:a")
140-
}
141141

142-
if(noSubtitle) data.add(FFmpegArgs.NO_SUBTITLE)
142+
if(isVideo() && !noSubtitle) data.addCmd(param = FFmpegArgs.ENCODER_SUBTITLES, value = FFmpegArgs.COPY)
143+
144+
if(isVideo() && noAudio) data.add(FFmpegArgs.NO_AUDIO)
145+
if(isVideo() && noSubtitle) data.add(FFmpegArgs.NO_SUBTITLE)
143146
if(noMetadata) data.addCmd(param = FFmpegArgs.MAP_METADATA, value = "-1")
144147
if(noChapters) data.addCmd(param = FFmpegArgs.MAP_CHAPTERS, value = "-1")
145148

146-
custom?.let { data.addAll(custom) }
147-
148-
if(isVideo() && !noSubtitle) data.addCmd(param = FFmpegArgs.ENCODER_SUBTITLES, value = FFmpegArgs.COPY)
149-
150149
return data.joinToString(separator = " ")
151150
}
152151

153-
private fun isVideo() = mediaType == MediaType.VIDEO
152+
private fun isVideo() = mediaType == MediaType.VIDEO && indexVideo != -1
154153
}

0 commit comments

Comments
 (0)