Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes from single ffprobe command #57

Merged
merged 8 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ dist
# Design Templates
Design/Cover.psd
Design/Programmatic.psd
#Design/Sidebar.xd
#Design/Sidebar.xd

# XCUserData
Converter.xcworkspace/xcuserdata
Binary file not shown.
Binary file not shown.
17 changes: 16 additions & 1 deletion Converter/Conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ func getVideoConversionCommand(inputFilePath: String, outputFilePath: String) ->
return "-c:v libx264 -preset veryfast -crf 26"
}

// If input file is HEVC, we re-encode to H264 to ensure QuickTime support
// If input file is HEVC, we re-encode to H264 and 8-bit colour to ensure QuickTime support
// https://superuser.com/questions/1380946/how-do-i-convert-10-bit-h-265-hevc-videos-to-h-264-without-quality-loss
if inputVideoCodec == VideoCodec.hevc {
return "-c:v libx264 -preset veryfast -crf 20 -vf format=yuv420p"
}

let inputVideoCodecTag = getVideoCodecTag(inputFilePath: inputFilePath)
// MOV does not support xvid, so we need to re-encode
if inputVideoCodecTag == "xvid" && outputFileType == VideoFormat.mov.rawValue {
return "-c:v libx264 -preset veryfast -crf 26"
}

Expand Down Expand Up @@ -225,6 +232,14 @@ func getAudioCodec(inputFilePath: String) -> AudioCodec {
return convertToAudioCodec(inputCodec: codec)
}

func getVideoCodecTag(inputFilePath: String) -> String {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this adds another async ffprobe command, but we will be removing all these extra sync ffprobe commands once #54 is merged

let session = FFprobeKit.execute("-loglevel error -select_streams v:0 -show_entries stream=codec_tag_string -of default=noprint_wrappers=1:nokey=1 \"\(inputFilePath)\"")
let logs = session?.getAllLogsAsString()

let codecTagString = logs!.trimmingCharacters(in: .whitespacesAndNewlines)
return codecTagString
}

func getChannelLayout(inputFilePath: String) -> ChannelLayout {
let session = FFprobeKit.execute("-loglevel error -select_streams a:0 -show_entries stream=channel_layout -of default=noprint_wrappers=1:nokey=1 \"\(inputFilePath)\"")
let logs = session?.getAllLogsAsString()
Expand Down