Loading media/libmediatranscoding/tests/assets/desk_hevc_1920x1080_aac_48KHz_rot90.mp4 0 → 100644 +903 KiB File added.No diff preview for this file type. View file media/libmediatranscoding/tests/assets/push_assets.sh +1 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,5 @@ fi #TODO(hkuang): Check if the destination folder already exists. If so, skip the copying. echo "Copying files to device" adb push $ANDROID_BUILD_TOP/frameworks/av/media/libmediatranscoding/tests/assets /data/local/tmp/TranscodingTestAssets adb push $ANDROID_BUILD_TOP/frameworks/av/media/libmediatranscoding/tests/assets/* /data/local/tmp/TranscodingTestAssets echo "Copy done" media/libmediatranscoding/transcoder/MediaSampleWriter.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,19 @@ namespace android { class DefaultMuxer : public MediaSampleWriterMuxerInterface { public: // MediaSampleWriterMuxerInterface ssize_t addTrack(const AMediaFormat* trackFormat) override { ssize_t addTrack(AMediaFormat* trackFormat) override { // If the track format has rotation, need to call AMediaMuxer_setOrientationHint // to set the rotation. Muxer doesn't take rotation specified on the track. const char* mime; if (AMediaFormat_getString(trackFormat, AMEDIAFORMAT_KEY_MIME, &mime) && strncmp(mime, "video/", 6) == 0) { int32_t rotation; if (AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_ROTATION, &rotation) && (rotation != 0)) { AMediaMuxer_setOrientationHint(mMuxer, rotation); } } return AMediaMuxer_addTrack(mMuxer, trackFormat); } media_status_t start() override { return AMediaMuxer_start(mMuxer); } Loading media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp +19 −5 Original line number Diff line number Diff line Loading @@ -139,6 +139,10 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat( } AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT, kColorFormatSurface); // Always encode without rotation. The rotation degree will be transferred directly to // MediaSampleWriter track format, and MediaSampleWriter will call AMediaMuxer_setOrientationHint. AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_ROTATION, 0); mDestinationFormat = std::shared_ptr<AMediaFormat>(encoderFormat, &AMediaFormat_delete); // Create and configure the encoder. Loading Loading @@ -339,25 +343,35 @@ void VideoTrackTranscoder::updateTrackFormat(AMediaFormat* outputFormat) { // at container level. This is supposed to override any SAR settings in the bitstream, // thus should always be transferred to the container of the transcoded file. int32_t sarWidth, sarHeight; if (AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_SAR_WIDTH, &sarWidth) && if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_SAR_WIDTH, &sarWidth) && (sarWidth > 0) && AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_SAR_HEIGHT, &sarHeight) && AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_SAR_HEIGHT, &sarHeight) && (sarHeight > 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_SAR_WIDTH, sarWidth); AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_SAR_HEIGHT, sarHeight); } // Transfer DAR settings. int32_t displayWidth, displayHeight; if (AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_WIDTH, &displayWidth) && if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_WIDTH, &displayWidth) && (displayWidth > 0) && AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, &displayHeight) && (displayHeight > 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_DISPLAY_WIDTH, displayWidth); AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, displayHeight); } // Transfer rotation settings. // Note that muxer itself doesn't take rotation from the track format. It requires // AMediaMuxer_setOrientationHint to set the rotation. Here we pass the rotation to // MediaSampleWriter using the track format. MediaSampleWriter will then call // AMediaMuxer_setOrientationHint as needed. int32_t rotation; if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_ROTATION, &rotation) && (rotation != 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_ROTATION, rotation); } // TODO: transfer other fields as required. mActualOutputFormat = std::shared_ptr<AMediaFormat>(formatCopy, &AMediaFormat_delete); Loading media/libmediatranscoding/transcoder/include/media/MediaSampleWriter.h +1 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ public: * @param trackFormat Format of the new track. * @return A non-negative track index on success, or a negative number on failure. */ virtual ssize_t addTrack(const AMediaFormat* trackFormat) = 0; virtual ssize_t addTrack(AMediaFormat* trackFormat) = 0; /** Starts the muxer. */ virtual media_status_t start() = 0; Loading Loading
media/libmediatranscoding/tests/assets/desk_hevc_1920x1080_aac_48KHz_rot90.mp4 0 → 100644 +903 KiB File added.No diff preview for this file type. View file
media/libmediatranscoding/tests/assets/push_assets.sh +1 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,5 @@ fi #TODO(hkuang): Check if the destination folder already exists. If so, skip the copying. echo "Copying files to device" adb push $ANDROID_BUILD_TOP/frameworks/av/media/libmediatranscoding/tests/assets /data/local/tmp/TranscodingTestAssets adb push $ANDROID_BUILD_TOP/frameworks/av/media/libmediatranscoding/tests/assets/* /data/local/tmp/TranscodingTestAssets echo "Copy done"
media/libmediatranscoding/transcoder/MediaSampleWriter.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,19 @@ namespace android { class DefaultMuxer : public MediaSampleWriterMuxerInterface { public: // MediaSampleWriterMuxerInterface ssize_t addTrack(const AMediaFormat* trackFormat) override { ssize_t addTrack(AMediaFormat* trackFormat) override { // If the track format has rotation, need to call AMediaMuxer_setOrientationHint // to set the rotation. Muxer doesn't take rotation specified on the track. const char* mime; if (AMediaFormat_getString(trackFormat, AMEDIAFORMAT_KEY_MIME, &mime) && strncmp(mime, "video/", 6) == 0) { int32_t rotation; if (AMediaFormat_getInt32(trackFormat, AMEDIAFORMAT_KEY_ROTATION, &rotation) && (rotation != 0)) { AMediaMuxer_setOrientationHint(mMuxer, rotation); } } return AMediaMuxer_addTrack(mMuxer, trackFormat); } media_status_t start() override { return AMediaMuxer_start(mMuxer); } Loading
media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp +19 −5 Original line number Diff line number Diff line Loading @@ -139,6 +139,10 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat( } AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT, kColorFormatSurface); // Always encode without rotation. The rotation degree will be transferred directly to // MediaSampleWriter track format, and MediaSampleWriter will call AMediaMuxer_setOrientationHint. AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_ROTATION, 0); mDestinationFormat = std::shared_ptr<AMediaFormat>(encoderFormat, &AMediaFormat_delete); // Create and configure the encoder. Loading Loading @@ -339,25 +343,35 @@ void VideoTrackTranscoder::updateTrackFormat(AMediaFormat* outputFormat) { // at container level. This is supposed to override any SAR settings in the bitstream, // thus should always be transferred to the container of the transcoded file. int32_t sarWidth, sarHeight; if (AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_SAR_WIDTH, &sarWidth) && if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_SAR_WIDTH, &sarWidth) && (sarWidth > 0) && AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_SAR_HEIGHT, &sarHeight) && AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_SAR_HEIGHT, &sarHeight) && (sarHeight > 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_SAR_WIDTH, sarWidth); AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_SAR_HEIGHT, sarHeight); } // Transfer DAR settings. int32_t displayWidth, displayHeight; if (AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_WIDTH, &displayWidth) && if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_WIDTH, &displayWidth) && (displayWidth > 0) && AMediaFormat_getInt32(mDestinationFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, &displayHeight) && (displayHeight > 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_DISPLAY_WIDTH, displayWidth); AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, displayHeight); } // Transfer rotation settings. // Note that muxer itself doesn't take rotation from the track format. It requires // AMediaMuxer_setOrientationHint to set the rotation. Here we pass the rotation to // MediaSampleWriter using the track format. MediaSampleWriter will then call // AMediaMuxer_setOrientationHint as needed. int32_t rotation; if (AMediaFormat_getInt32(mSourceFormat.get(), AMEDIAFORMAT_KEY_ROTATION, &rotation) && (rotation != 0)) { AMediaFormat_setInt32(formatCopy, AMEDIAFORMAT_KEY_ROTATION, rotation); } // TODO: transfer other fields as required. mActualOutputFormat = std::shared_ptr<AMediaFormat>(formatCopy, &AMediaFormat_delete); Loading
media/libmediatranscoding/transcoder/include/media/MediaSampleWriter.h +1 −1 Original line number Diff line number Diff line Loading @@ -41,7 +41,7 @@ public: * @param trackFormat Format of the new track. * @return A non-negative track index on success, or a negative number on failure. */ virtual ssize_t addTrack(const AMediaFormat* trackFormat) = 0; virtual ssize_t addTrack(AMediaFormat* trackFormat) = 0; /** Starts the muxer. */ virtual media_status_t start() = 0; Loading