#pragma once
#include <string>
#include <cstdint>

namespace UsdLayerManager {

/// Streams RGBA frames directly into an H.264/MP4 file using libavcodec.
/// Usage:
///   MovieEncoder enc;
///   enc.Open("out.mp4", 1920, 1080, 24.0);
///   for each frame: enc.WriteFrame(rgbaPixels);   // top-to-bottom, 4 bytes/px
///   enc.Close();
class MovieEncoder {
public:
    MovieEncoder();
    ~MovieEncoder();

    // Non-copyable
    MovieEncoder(const MovieEncoder&) = delete;
    MovieEncoder& operator=(const MovieEncoder&) = delete;

    bool Open(const char* outputPath, int width, int height, double fps);
    bool WriteFrame(const uint8_t* rgba);
    bool Close();   // flush + write trailer; resets state for reuse

    bool IsOpen() const { return m_open; }
    const std::string& GetLastError() const { return m_error; }

private:
    bool DrainPackets();
    void Reset();

    struct Impl;
    Impl* m_impl = nullptr;

    bool        m_open  = false;
    std::string m_error;
};

} // namespace UsdLayerManager
