Skip to content

Commit 266f9f5

Browse files
author
Daniel Flores
committed
move torchaudio comment, remove streamIndex_
1 parent d7bb786 commit 266f9f5

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ void VideoEncoder::initializeEncoder(
666666
status == AVSUCCESS,
667667
"avcodec_parameters_from_context failed: ",
668668
getFFMPEGErrorStringFromErrorCode(status));
669-
streamIndex_ = avStream_->index;
670669
}
671670

672671
void VideoEncoder::encode() {
@@ -791,15 +790,16 @@ void VideoEncoder::encodeFrame(
791790
"Error receiving packet: ",
792791
getFFMPEGErrorStringFromErrorCode(status));
793792

793+
// The code below is borrowed from torchaudio:
794+
// https://github.com/pytorch/audio/blob/b6a3368a45aaafe05f1a6a9f10c68adc5e944d9e/src/libtorio/ffmpeg/stream_writer/encoder.cpp#L46
795+
// Setting packet->duration to 1 allows the last frame to be properly
796+
// encoded, and needs to be set before calling av_packet_rescale_ts.
794797
if (packet->duration == 0) {
795798
packet->duration = 1;
796799
}
797-
// av_packet_rescale_ts ensures encoded frames have correct timestamps.
798-
// This prevents "no more frames" errors when decoding encoded frames,
799-
// https://github.com/pytorch/audio/blob/b6a3368a45aaafe05f1a6a9f10c68adc5e944d9e/src/libtorio/ffmpeg/stream_writer/encoder.cpp#L46
800800
av_packet_rescale_ts(
801801
packet.get(), avCodecContext_->time_base, avStream_->time_base);
802-
packet->stream_index = streamIndex_;
802+
packet->stream_index = avStream_->index;
803803

804804
status = av_interleaved_write_frame(avFormatContext_.get(), packet.get());
805805
TORCH_CHECK(

src/torchcodec/_core/Encoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ class VideoEncoder {
153153

154154
UniqueEncodingAVFormatContext avFormatContext_;
155155
UniqueAVCodecContext avCodecContext_;
156-
int streamIndex_ = -1;
157156
AVStream* avStream_;
158157
UniqueSwsContext swsContext_;
159158

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const int* getSupportedSampleRates(const AVCodec& avCodec) {
9292

9393
const AVPixelFormat* getSupportedPixelFormats(const AVCodec& avCodec) {
9494
const AVPixelFormat* supportedPixelFormats = nullptr;
95-
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
95+
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7.1
9696
int numPixelFormats = 0;
9797
int ret = avcodec_get_supported_config(
9898
nullptr,

0 commit comments

Comments
 (0)