Я пытаюсь прочитать два кадра, каждый из которых отдельно хранится в двоичных файлах с именамиframe1.bin иframe2.bin, и создать видеофайл MP4 с именем sample.mp4. Полный исходный код доступен здесь: https://github.com/eswar-2001/MFWriter/ ... Writer.cpp
Вот что я делаю. :
Я считываю кадр, связываю его с соответствующей временной меткой и записываю в видеофайл.
CComPtr mediaBuffer(createMediaBuffer(input));
// Create a media sample and add the buffer to the sample.
CComPtr sample;
MFWRITER_RETURN_ON_ERROR(throwIf(MFCreateSample(&sample)));
MFWRITER_RETURN_ON_ERROR(throwIf(sample->AddBuffer(mediaBuffer)));
// Set the time stamp and the duration.
MFWRITER_RETURN_ON_ERROR(throwIf(sample->SetSampleTime(_frameStart)));
MFWRITER_RETURN_ON_ERROR(throwIf(sample->SetSampleDuration(_frameDuration)));
// Send the sample to the Sink Writer.
MFWRITER_RETURN_ON_ERROR(throwIf(_sinkWriter->WriteSample(_videoStreamIndex, sample)));
// Advance the starting position for the next frame
_frameStart += _frameDuration;
Я создаю и устанавливаю свойства мойкиWriter, как показано ниже:
std::wstring wideFile = L"sample.mp4";
CComPtr pMediaTypeOut, pMediaTypeIn;
MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateSinkWriterFromURL(wideFile.c_str(), NULL, NULL, &_sinkWriter));
// Set the output media type.
MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateMediaType(&pMediaTypeOut));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH264VProfile_Main));
// Set the Bit rate. NOTE this assumes the input data is natively 24 bits per pixel (8 per band, 3 bands)
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, computeH264BitRate(_quality, width, height, _frameRate, 24)));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, width, height));
_frameDuration = static_cast(std::round((1.0 / _frameRate) * HUNDRED_NANOSECONDS));
// Derive the frame rate from
UINT32 rateNumerator = 0, rateDenominator = 0;
MFWRITER_RETURN_HRESULT_ON_ERROR(MFAverageTimePerFrameToFrameRate(_frameDuration, &rateNumerator, &rateDenominator));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, rateNumerator, rateDenominator));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
MFWRITER_RETURN_HRESULT_ON_ERROR(_sinkWriter->AddStream(pMediaTypeOut, &_videoStreamIndex));
// Set the input media type.
MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateMediaType(&pMediaTypeIn));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_YUY2));
MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, width, height));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, rateNumerator, rateDenominator));
MFWRITER_RETURN_HRESULT_ON_ERROR(MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1));
MFWRITER_RETURN_HRESULT_ON_ERROR(_sinkWriter->SetInputMediaType(_videoStreamIndex, pMediaTypeIn, NULL));
_frameStart = 0;
// Tell the sink writer to start accepting data.
MFWRITER_RETURN_HRESULT_ON_ERROR(_sinkWriter->BeginWriting());
return true;
Проблема:
Отметка времени начинается с 0,0333 вместо 0, что, похоже, соответствует значению длительности кадра. Я напечатал значение _frameStart до и после связывания его с образцом с помощью SetSampleTime, и в обоих случаях оно напечатало 0, как и ожидалось. Однако в созданном файле MP4 временная метка первого кадра равна 0,0333 вместо 0. Я не могу определить причину этой проблемы.
Я пытаюсь прочитать два кадра, каждый из которых отдельно хранится в двоичных файлах с именамиframe1.bin иframe2.bin, и создать видеофайл MP4 с именем sample.mp4. Полный исходный код доступен здесь: https://github.com/eswar-2001/MFWriter/blob/main/MFWriter.cpp Вот что я делаю. : Я считываю кадр, связываю его с соответствующей временной меткой и записываю в видеофайл. [code]CComPtr mediaBuffer(createMediaBuffer(input));
// Create a media sample and add the buffer to the sample. CComPtr sample; MFWRITER_RETURN_ON_ERROR(throwIf(MFCreateSample(&sample))); MFWRITER_RETURN_ON_ERROR(throwIf(sample->AddBuffer(mediaBuffer)));
// Set the time stamp and the duration. MFWRITER_RETURN_ON_ERROR(throwIf(sample->SetSampleTime(_frameStart))); MFWRITER_RETURN_ON_ERROR(throwIf(sample->SetSampleDuration(_frameDuration)));
// Send the sample to the Sink Writer. MFWRITER_RETURN_ON_ERROR(throwIf(_sinkWriter->WriteSample(_videoStreamIndex, sample)));
// Advance the starting position for the next frame _frameStart += _frameDuration; [/code] Я создаю и устанавливаю свойства мойкиWriter, как показано ниже: [code]std::wstring wideFile = L"sample.mp4"; CComPtr pMediaTypeOut, pMediaTypeIn; MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateSinkWriterFromURL(wideFile.c_str(), NULL, NULL, &_sinkWriter));
// Set the output media type. MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateMediaType(&pMediaTypeOut)); MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video)); MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264));
// Set the Bit rate. NOTE this assumes the input data is natively 24 bits per pixel (8 per band, 3 bands) MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, computeH264BitRate(_quality, width, height, _frameRate, 24)));
// Set the input media type. MFWRITER_RETURN_HRESULT_ON_ERROR(MFCreateMediaType(&pMediaTypeIn)); MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video)); MFWRITER_RETURN_HRESULT_ON_ERROR(pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_YUY2));
// Tell the sink writer to start accepting data. MFWRITER_RETURN_HRESULT_ON_ERROR(_sinkWriter->BeginWriting());
return true; [/code] [b]Проблема[/b]:
Отметка времени начинается с 0,0333 вместо 0, что, похоже, соответствует значению длительности кадра. Я напечатал значение _frameStart до и после связывания его с образцом с помощью SetSampleTime, и в обоих случаях оно напечатало 0, как и ожидалось. Однако в созданном файле MP4 временная метка первого кадра равна 0,0333 вместо 0. Я не могу определить причину этой проблемы.
Я пытаюсь прочитать два кадра (по отдельности хранящиеся в двоичных файлахframe1.bin иframe2.bin) и создать видеофайл mp4 с именем sample.mp4 .
Проблема:
Временная метка вместо того, чтобы начинаться с 0, начинается с 0,333 (очевидно это значение...
Я пытаюсь прочитать два кадра, каждый из которых отдельно хранится в двоичных файлах с именамиframe1.bin иframe2.bin, и создать видеофайл MP4 с именем sample.mp4. Полный исходный код доступен здесь:
Вот что я делаю. :
Я считываю кадр, связываю его...
Я пытаюсь прочитать два кадра (по отдельности хранящиеся в двоичных файлахframe1.bin иframe2.bin) и создать видеофайл mp4 с именем «sample.mp4». Временная метка начинается с 0,0333 (по-видимому, это значение длительности кадра), а не с 0. Я не могу...
Я не уверен, как это исправить, так как все параметры выполняются, и импорт принимается во внимание, и были установлены приличия, может кто -нибудь предоставить некоторое понимание и или решение. для контекста. Я строю проект из A, который был...