Skip to content

When I used MediaConvert to convert my MP4 to M3U8, I found that the original 43-second video was only 40 seconds after conversion, and part of the AAC audio was cut off

0

"Original video information":

Invalid return value 0 for stream protocol Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'java.io.ByteArrayInputStream@27429ed8': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.37.101 Duration: 00:00:43.44, start: 0.000000, bitrate: N/A Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 960x576, 1261 kb/s, 10 fps, 10 tbr, 10240 tbn, 20 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 70 kb/s (default) Metadata: handler_name : SoundHandler

code:

private OutputGroup createOutput( String fileOutput, int qvbrMaxBitrate, int qvbrQualityLevel, int originWidth, int originHeight, int targetWidth ) {

    int targetHeight = Math.round(originHeight * targetWidth / originWidth)
            - (Math.round(originHeight * targetWidth / originWidth) % 4);

    if (targetWidth == 480 && targetHeight != 854 && targetHeight > 800 && targetHeight < 880) {
        targetHeight = 854;
    }
    OutputGroup appleHLS = null;
    try {
        Output output = Output.builder().nameModifier("ain").outputSettings(OutputSettings.builder()
                        .hlsSettings(HlsSettings.builder()

// .segmentModifier(segmentModifier) .audioGroupId("program_audio") .iFrameOnlyManifest(HlsIFrameOnlyManifest.EXCLUDE).build()) .build()) .containerSettings(ContainerSettings.builder().container(ContainerType.M3_U8) .m3u8Settings(M3u8Settings.builder().audioFramesPerPes(4) .pcrControl(M3u8PcrControl.PCR_EVERY_PES_PACKET) .pmtPid(480).privateMetadataPid(503) .programNumber(1).patInterval(0).pmtInterval(0) .scte35Source(M3u8Scte35Source.NONE) .scte35Pid(500).nielsenId3(M3u8NielsenId3.NONE) .timedMetadata(TimedMetadata.NONE) .timedMetadataPid(502).videoPid(481) .audioPids(482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492) .build()) .build()) .videoDescription( VideoDescription.builder().width(targetWidth) .height(targetHeight) .scalingBehavior(ScalingBehavior.DEFAULT) .sharpness(50).antiAlias(AntiAlias.ENABLED) .timecodeInsertion( VideoTimecodeInsertion.DISABLED) .colorMetadata(ColorMetadata.INSERT) .respondToAfd(RespondToAfd.NONE) .afdSignaling(AfdSignaling.NONE) .dropFrameTimecode(DropFrameTimecode.ENABLED) .codecSettings(VideoCodecSettings.builder() .codec(VideoCodec.H_264) .h264Settings(H264Settings .builder() .rateControlMode( H264RateControlMode.QVBR) .parControl(H264ParControl.INITIALIZE_FROM_SOURCE) .qualityTuningLevel( H264QualityTuningLevel.SINGLE_PASS) .qvbrSettings(H264QvbrSettings .builder() .qvbrQualityLevel( qvbrQualityLevel) .build()) .codecLevel(H264CodecLevel.AUTO) .codecProfile((targetHeight > 720 && targetWidth > 1280) ? H264CodecProfile.HIGH : H264CodecProfile.MAIN) .maxBitrate(qvbrMaxBitrate) .framerateControl( H264FramerateControl.INITIALIZE_FROM_SOURCE) .gopSize(2.0) .gopSizeUnits(H264GopSizeUnits.SECONDS) .numberBFramesBetweenReferenceFrames( 2) .gopClosedCadence( 1) .gopBReference(H264GopBReference.DISABLED) .slowPal(H264SlowPal.DISABLED) .syntax(H264Syntax.DEFAULT) .numberReferenceFrames( 3) .dynamicSubGop(H264DynamicSubGop.STATIC) .fieldEncoding(H264FieldEncoding.PAFF) .sceneChangeDetect( H264SceneChangeDetect.ENABLED) .minIInterval(0) .telecine(H264Telecine.NONE) .framerateConversionAlgorithm( H264FramerateConversionAlgorithm.DUPLICATE_DROP) .entropyEncoding( H264EntropyEncoding.CABAC) .slices(1) .unregisteredSeiTimecode( H264UnregisteredSeiTimecode.DISABLED) .repeatPps(H264RepeatPps.DISABLED) .adaptiveQuantization( H264AdaptiveQuantization.HIGH) .spatialAdaptiveQuantization( H264SpatialAdaptiveQuantization.ENABLED) .temporalAdaptiveQuantization( H264TemporalAdaptiveQuantization.ENABLED) .flickerAdaptiveQuantization( H264FlickerAdaptiveQuantization.DISABLED) .softness(0) .interlaceMode(H264InterlaceMode.PROGRESSIVE) .build()) .build()) .build()) .audioDescriptions(AudioDescription.builder() .audioTypeControl(AudioTypeControl.FOLLOW_INPUT) .languageCodeControl(AudioLanguageCodeControl.FOLLOW_INPUT) .codecSettings(AudioCodecSettings.builder() .codec(AudioCodec.AAC).aacSettings(AacSettings .builder() .codecProfile(AacCodecProfile.LC) .rateControlMode( AacRateControlMode.CBR) .codingMode(AacCodingMode.CODING_MODE_2_0) .sampleRate(44100) .bitrate(96000) .rawFormat(AacRawFormat.NONE) .specification(AacSpecification.MPEG4) .audioDescriptionBroadcasterMix( AacAudioDescriptionBroadcasterMix.NORMAL) .build()) .build()) .build()) .build();

        appleHLS = OutputGroup.builder().name("Apple HLS").customName("VIDEO")
                .outputGroupSettings(OutputGroupSettings.builder()
                        .type(OutputGroupType.HLS_GROUP_SETTINGS)
                        .hlsGroupSettings(HlsGroupSettings.builder()
                                .directoryStructure(
                                        HlsDirectoryStructure.SINGLE_DIRECTORY)
                                .manifestDurationFormat(
                                        HlsManifestDurationFormat.INTEGER)
                                .streamInfResolution(
                                        HlsStreamInfResolution.INCLUDE)
                                .clientCache(HlsClientCache.ENABLED)
                                .captionLanguageSetting(
                                        HlsCaptionLanguageSetting.OMIT)
                                .manifestCompression(
                                        HlsManifestCompression.NONE)
                                .codecSpecification(
                                        HlsCodecSpecification.RFC_4281)
                                .outputSelection(
                                        HlsOutputSelection.MANIFESTS_AND_SEGMENTS)
                                .programDateTime(HlsProgramDateTime.EXCLUDE)
                                .programDateTimePeriod(600)
                                .timedMetadataId3Frame(
                                        HlsTimedMetadataId3Frame.PRIV)
                                .timedMetadataId3Period(10)
                                .destination(fileOutput)
                                .segmentControl(HlsSegmentControl.SEGMENTED_FILES)
                                .minFinalSegmentLength((double) 0)
                                .segmentLength(4).minSegmentLength(0).build())
                        .build())
                .outputs(output).build();

    } catch (MediaConvertException e) {
    }
    return appleHLS;
}
asked 2 years ago214 views
1 Answer
0

Check padding video with black video frames functionality: https://docs.aws.amazon.com/mediaconvert/latest/ug/video-padding.html. It might help.

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.