#716 video: fail fast instead of corrupting file when editing fragmented mp4
This commit is contained in:
parent
7b30c7235b
commit
0fc2710e62
6 changed files with 19 additions and 12 deletions
|
@ -52,6 +52,9 @@ object Mp4ParserHelper {
|
|||
}
|
||||
// creating `IsoFile` with a `File` or a `File.inputStream()` yields `No such device`
|
||||
IsoFile(channel, boxParser).use { isoFile ->
|
||||
val fragmented = isoFile.boxes.any { box -> box is MovieFragmentBox || box is SegmentIndexBox }
|
||||
if (fragmented) throw Exception("editing fragmented movies is not supported")
|
||||
|
||||
val lastContentBox = isoFile.boxes.reversed().firstOrNull { box ->
|
||||
when {
|
||||
box == isoFile.movieBox -> false
|
||||
|
@ -60,7 +63,7 @@ object Mp4ParserHelper {
|
|||
else -> true
|
||||
}
|
||||
}
|
||||
lastContentBox ?: throw Exception("failed to find last context box")
|
||||
lastContentBox ?: throw Exception("failed to find last content box")
|
||||
val oldFileSize = isoFile.size
|
||||
var appendOffset = (isoFile.getBoxOffset { box -> box == lastContentBox })!! + lastContentBox.size
|
||||
|
||||
|
@ -97,7 +100,6 @@ object Mp4ParserHelper {
|
|||
if (trailing > 0) {
|
||||
addFreeBoxEdit(appendOffset, trailing)
|
||||
}
|
||||
|
||||
return edits
|
||||
}
|
||||
}
|
||||
|
@ -277,11 +279,13 @@ object Mp4ParserHelper {
|
|||
// creating `IsoFile` with a `File` or a `File.inputStream()` yields `No such device`
|
||||
IsoFile(channel, metadataBoxParser()).use { isoFile ->
|
||||
val userDataBox = Path.getPath<UserDataBox>(isoFile.movieBox, UserDataBox.TYPE)
|
||||
if (userDataBox != null) {
|
||||
fields.putAll(extractBoxFields(userDataBox))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
Log.w(LOG_TAG, "failed to parse MP4 for mimeType=$mimeType uri=$uri", e)
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -356,6 +356,8 @@ class VideoMetadataFormatter {
|
|||
final sarDen = info[Keys.sarDen];
|
||||
// skip common square pixels (1:1)
|
||||
if (sarNum != sarDen) save('SAR', '$sarNum:$sarDen');
|
||||
case Keys.segmentCount:
|
||||
save('Segment Count', value);
|
||||
case Keys.sourceOshash:
|
||||
save('Source OSHash', value);
|
||||
case Keys.startMicros:
|
||||
|
|
|
@ -149,7 +149,7 @@ class _MetadataTabState extends State<MetadataTab> {
|
|||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Text(data),
|
||||
child: SelectableText(data),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
|
|
@ -82,6 +82,7 @@ class Keys {
|
|||
static const streams = 'streams';
|
||||
static const tbrDen = 'tbr_den';
|
||||
static const tbrNum = 'tbr_num';
|
||||
static const segmentCount = 'segment_count';
|
||||
static const streamType = 'type';
|
||||
static const title = 'title';
|
||||
static const timeBase = 'time_base';
|
||||
|
|
|
@ -172,10 +172,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: media_kit
|
||||
sha256: "0a89e7037002a62701ec319c375586849f9ef8e681820e1dd4a4ff7b843f7542"
|
||||
sha256: d7a827080fb28f0ba4e8a7ab3f3e3f868fa817f0a94499640466ade84a1c31c9
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.4+1"
|
||||
version: "1.1.5"
|
||||
media_kit_libs_android_video:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -196,10 +196,10 @@ packages:
|
|||
dependency: "direct main"
|
||||
description:
|
||||
name: media_kit_video
|
||||
sha256: e7fcbe426d42a78ad6696f8f557adb9cbdc012177829026d04992cc106a1c815
|
||||
sha256: d4143a96d97965d025bbb8b88db0ebf301e3c4cfa10c7e2ad7fd47c86a7febae
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.5"
|
||||
version: "1.1.6"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -835,10 +835,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: media_kit
|
||||
sha256: "0a89e7037002a62701ec319c375586849f9ef8e681820e1dd4a4ff7b843f7542"
|
||||
sha256: d7a827080fb28f0ba4e8a7ab3f3e3f868fa817f0a94499640466ade84a1c31c9
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.4+1"
|
||||
version: "1.1.5"
|
||||
media_kit_libs_android_video:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -859,10 +859,10 @@ packages:
|
|||
dependency: transitive
|
||||
description:
|
||||
name: media_kit_video
|
||||
sha256: e7fcbe426d42a78ad6696f8f557adb9cbdc012177829026d04992cc106a1c815
|
||||
sha256: d4143a96d97965d025bbb8b88db0ebf301e3c4cfa10c7e2ad7fd47c86a7febae
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.5"
|
||||
version: "1.1.6"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
Loading…
Reference in a new issue